简体   繁体   English

程序集用寄存器值替换常量

[英]Assembly replacing constant with a register value

I'm not an expert with assembly so this may be simple. 我不是装配专家,所以这可能很简单。

If I have an instruction that expects a constant value as a parameter like so: 如果我有一条指令需要一个常量作为参数,例如:

VQSHRN.U32 d0,q0,#16

How can I replace #16 with a value in a register, eg r0 ? 如何用寄存器中的值(例如r0替换#16 This instruction may even allow you to do so, but I haven't found docs on that capability. 该说明甚至可能允许您这样做,但是我还没有找到关于该功能的文档。 Is there a normal method of doing this? 有正常的方法吗?

In case this matters, I'm writing ARMv7 assembly and putting it inline with c++ code. 如果这很重要,我将编写ARMv7程序集并将其与c ++代码内联。 Thanks. 谢谢。

As @Michael pointed out, VQRSHL is the appropriate shift-by-register instruction here - fortunately, right happens to be negative left. 正如@Michael指出的那样, VQRSHL是此处的适当移位寄存器指令-幸运的是,右恰好是负左。 I'd use a VDUP to turn r0 into an appropriate vector of shift values first, and a VQMOVN afterwards for the narrowing. 我将先使用VDUPr0转换为适当的移位值矢量,然后使用VQMOVN进行缩小。 All of these are available as intrinsics to help keep the nastiness of inline assembly at bay, something like this: 所有这些都可以作为内部函数来使用,以帮助避免内联汇编的复杂性,如下所示:

vshift = vdupq_n_s32(-shift);
result = vqmovn_u32(vqrshlq_u32(data, vshift));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM