When I have the following code:
int value2 = 0x11223344;
The VS2022 compiler (arm64) generates:
StarFunction PROC
...
ldr w8,|value_label|
...
...
...
ret
|value_label|
DCD 0x11223344
ENDP
As you can see, the value 0x11223344 is generated as "data" at the end of the function.
Is there any way to have some control on that so it generates instead:
mov w8, 0x1122
movk w8, 0x3344, lsl 16
I cannot use compiler optimizations as I need to have control over the generated code to patch specific code sequences. With compiler optimizations, I loose that control.
I have tried different compiler optimization switches but some of them have no effect and other more aggressive optimizations even remove the declaration of "0x11223344" and directly use it in code afterwards.
Summing up, can I "force" somehow the compiler to avoid that "data" mixed with code for immediate values in arm64?
I found that declaring the local variables with "volatile" such as:
And also compiling with
/Ox, makes the compiler generate the wantedmov Wn, imm16_low; movk Wn, imm16_high, lsl 16at the expected location where it was declared.Here is a full example (compiled with
/Ox)Generates: