News for hackers. Stuff that matters.
Re:Loading an x64 register, how hard could it be? by 0xcde4c3db on Saturday September 19, 2015 @11:20PM (#10246464)
It's not crazy at all. This sort of shuffling is pretty standard for RISC ISAs, where it's typical to have fixed-length instructions that are no larger than the registers.

For example, MIPS has no actual "load immediate" instruction. Instead, say you want to load the value 0x12345678 into register t0. You can go ahead and tell your MIPS assembler:

    li $t0, 0x12345678
but it will actually emit something like:

    lui $t0, 0x1234
    ori $t0, $t0, 0x5678
"lui" here is the "load upper immediate" instruction, which loads the target register with the 16-bit immediate, left-shifted by 16 bits. "ori $t0, t0, 0x5678" then performs a bitwise OR with its immediate to get the lower 16 bits into the register. This can be done in a single instruction if the immediate is 16 bits or smaller by using the dedicated zero register (a read-only register that always contains 0x00000000, which turns out to be extremely handy for minimizing an instruction set):

    ori $t0, $zero 0xabcd
Re:Loading an x64 register, how hard could it be? by JoshTriplett on Sunday September 20, 2015 @12:52AM (#10246598)
SPARC does something similar, with a special "sethi" instruction to set the high 22 bits of a register, using more space for an argument than any other instruction does.

Some architectures manage to do something more clever than that, as well. See http://alisdair.mcdiarmid.org/arm-immediate-value-encoding/ for instance.

Re:Loading an x64 register, how hard could it be? by pm215 on Sunday September 20, 2015 @05:00AM (#10246969)
The SPARC call instruction beats that with a 30 bit immediate, sacrificing a huge chunk of the encoding space for being able to reach any target in a 32 bit address space with a single instruction.