Skip to content. | Skip to navigation

Personal tools
Log in
Sections
You are here: Home Blog archive 2008 September 13 Smallest UTF32 to UTF8 converter

Smallest UTF32 to UTF8 converter

by Bastian Blank — last modified Sep 13, 2008 12:30 PM
Filed Under:

I found some weird opcodes in the s390 instruction set some time ago. I finally want to use it as I have access to such a machine. The result is rather slim:

.globl cu41
        .type   cu41, @function
cu41:
.L2:
        cu41    %r2,%r4
        ipm     %r1
        srl     %r1,28
        chi     %r1,3
        je      .L2
        ltr     %r1,%r1
        je      .L3
        lcr     %r1,%r1
        lgfr    %r3,%r1
.L3:
        lgr     %r2,%r3
        br      %r14

The cu41 opcode translates UTF32 to UTF8. Each "parameter" is a register pair [1], which describes address and length of the buffer. This opcode will return after a not specified number of translated characters. The rest is boiler plate code for condition code checking. The loop makes sure that anything is converted within the function unless another error occured.

[1]An even pair. gcc is not yet able to allocate such pairs on its own, so it is hardcoded.
Filed under: ,
Add comment

You can add a comment by filling out the form below. Plain text formatting. Web and email addresses are transformed into clickable links. Comments are moderated.