Memory offsets in inline assembly

橙三吉。 提交于 2019-12-12 21:15:13

问题


In A64 assembler, there are different ways to specify addresses.

/*
[base{,#0}]                 Simple register (exclusive) - Immediate Offset
[base{,#imm}]               Offset - Immediate Offset
[base,Xm{,LSL #imm}]        Offset - Register Offset
[base,Wm,(S|U)XTW {#imm}]   Offset - Extended Register Offset
[base,#imm]!                Pre-indexed - Immediate Offset
[base],#imm                 Post-indexed - Immediate Offset
label                       PC-relative (literal) load - Immediate Offset
*/

I would like to use "Offset - Immediate Offset" in inline assembler.

__asm__("ldp x8, x9, %0, 16 \n\t"
        :
        : "m" (*somePointer)
        : "x8", "x9");

This gets translated to

ldp x8, x9, [x0], 16

My goal is to reach

ldp x8, x9, [x0, 16]

How can I write such instructions with inline assembler?


回答1:


I don't have an ARM 64-bit toolchain to test this with, but you should be able to do something like this:

asm("ldp x8, x9, %0\n\t"
    :
    : "Ump" (*((__int128 *) somePointer + 1))
    : "x8", "x9");

The Ump constraint limits the memory operand to those permitted by the integer LDP instruction, otherwise it works like the m constraint. If somePointer is already a pointer to a 128-bit type you can just use somePointer[1] as the operand.

If the above doesn't work then David Wohlferd's suggestion should:

asm("ldp x8, x9, [%0, %1]" 
    : 
    : "r" (somePointer), "i"(16), "m" (*somePointer) 
    : "x8", "x9"); 


来源:https://stackoverflow.com/questions/29826422/memory-offsets-in-inline-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!