简体   繁体   English

%w操作数上的ARM GCC内联汇编错误

[英]ARM GCC inline assembly error on %w operand

I have an ARMv8 inline assembly segment: 我有一个ARMv8内联汇编段:

/* get leading 0 of cache ways */
__asm__ __volatile__
(
  "CLZ %w[shift], %w[maxWay] \n"
  : [shift] "=r" (uiShift)
  : [maxWay] "r" (uiMaxWay)
);

When compile by ARM GCC compiler: 通过ARM GCC编译器进行编译时:

在此处输入图片说明

Interestingly, if I compile with Linaro compiler, then there is no problem. 有趣的是,如果我使用Linaro编译器进行编译,那么就没有问题。

在此处输入图片说明

Is there a problem in ARM GCC compiler, or in my code? ARM GCC编译器或我的代码中有问题吗?

Unlike x86 where the same compiler can produce x86-32 or x86-64 code with -m32 and -m64 , you need a separate build of gcc for ARM vs. AArch64. 与x86相同,同一编译器可以使用-m32-m64生成x86-32或x86-64代码,您需要为ARM与AArch64分别构建gcc。

ARM gcc accepts -march=armv8-a , but it's still compiling in 32-bit ARM mode, not AArch64. ARM gcc接受-march=armv8-a ,但仍在32位ARM模式下编译,而不是AArch64。

I can reproduce your problem on the Godbolt compiler explorer with AArch64 gcc and ARM gcc. 我可以使用AArch64 gcc和ARM gcc 在Godbolt编译器资源管理器上重现您的问题。 (And I included an example that uses __builtin_clz(uiShift) instead of inline asm, so it compiles to a clz instruction on either architecture.) (并且我提供了一个使用__builtin_clz(uiShift)而不是内联asm的示例,因此它可以在两种体系结构上编译为clz指令。)

BTW, you could have left out the w size override on both operands, and simply use unsigned int for the input and output. 顺便说一句,您可能在两个操作数上都忽略了w大小覆盖,而只是将unsigned int用于输入和输出。 Then the same inline asm would work with both ARM and AArch64. 然后,相同的嵌入式asm将与ARM和AArch64一起使用。 (But __builtin_clz is still better, because the compiler understands what it does. eg it knows the result is in the range 0..31, which may enable some optimizations.) (但是__builtin_clz仍然更好,因为编译器了解它的工作。例如,它知道结果在0..31的范围内,这可能会进行一些优化。)

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

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