0

This is simplified from a larger example.

In the C source, I have:

uint32_t xx = oxdeadbeef ;

I compiled with gcc -O or clang -O

Looking at 'objdump -d a.out' on the RPi 4, I see

9ac:    5297dde8    mov w8, #0xbeef // #48879
9b0:    72bbd5a8    movk w8, #0xdead, lsl #16

This produces the correct result, but, these are 16-bit values. How do I force gcc or clang to use 32-bits in this case?

mov w8, #0xdeadbeef

Or, do I want to?

4
  • Are you sure such an instruction (and not a pseudo instruction) actually exists on that architecture?
    – Dan Mašek
    Commented Apr 13 at 11:28
  • uint32_t xx = oxdeadbeef ; I am 100 % sure you do not have it.
    – gulpr
    Commented Apr 13 at 11:33
  • ARM64 instructions are all 32 bits wide, unlike x86 where they are of variable length. Since you need some bits for the opcode and register specifier, it follows that you can't encode every possible mov wn, #imm32 in a single instruction. So instead the architecture designers limited it to 16 bits and provided movk to make it reasonably convenient to construct a larger value with multiple instructions. We've definitely had other questions about this issue, but I can't find one that's really "canonical" to link as a dupe. Maybe I'll write one at some point. Commented Apr 13 at 15:56
  • mov is not a real instruction.
    – Siguza
    Commented Apr 13 at 18:58

1 Answer 1

2

This micro does not have the move immediate 32-bit value into the register, only 16 bits. 2 instructions are faster and shorter than storing the value in memory and loading it into the register from memory.

That's the reason why you have 2 instructions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.