我在64位Aarch64设备上使用ARM学习GCC内联汇编程序。我看到了一条我不太了解的错误信息。来自GCC的内联汇编程序的错误消息:
$ gcc -DNDEBUG -g3 -O1 -march=armv8-a+crc+crypto test.cc -o test.exe
/tmp/ccCHOWrn.s: Assembler messages:
/tmp/ccCHOWrn.s:19: Error: invalid use of vector register at operand 1 -- `pmull v0,v0,v0'
示例程序只是尝试运用多项式乘法:
$ cat test.cc
#include <arm_neon.h>
int main(int argc, char* argv[])
{
uint64x2_t r = {0,0}, a = {2,4};
__asm__ __volatile__
(
"pmull %0, %1, %1;"
: "=w" (r)
: "w" (a), "w" (a)
: "cc"
);
return (int)r[0];
}
"w"
是Aarch64 machine constraint。在这种情况下,它被描述为&#34;浮点或SIMD向量寄存器&#34; ,这似乎是我想要的。
uint64x2_t
类型通常与ARM内在函数一起使用。但它是一个128位类型并且与SIMD协处理器对齐,所以它似乎是样本的一个很好的选择。
该设备是LeMaker HiKey,带有Linaro图像和GCC 4.9.2编译器。看起来这个错误几年前已修复,但我不确定它是否相关:fbb ftbfs on arm64。
我有两个问题:
pmull
和pmull2
我尝试添加排列说明符,但我并不感到惊讶它不起作用,因为我不知道语法:
$ gcc -DNDEBUG -g3 -O1 -march=armv8-a+crc+crypto test.cc -o test.exe
test.cc: In function ‘int main(int, char**)’:
test.cc:8:15: error: expected ‘)’ before numeric constant
: "=w" (r.1q)
^
test.cc:8:15: error: expected ‘)’ before numeric constant
test.cc:9:6: error: expected ‘;’ before ‘:’ token
: "w" (a.1d), "w" (a.1d)
^
test.cc:9:6: error: expected primary-expression before ‘:’ token
我还尝试添加双百分号(即%%0
和%%1
),因为汇编程序遇到了.att_stntax
和.intel_syntax
的问题:
$ gcc -DNDEBUG -g3 -O1 -march=armv8-a+crc+crypto test.cc -o test.exe
/tmp/ccPpnvUP.s: Assembler messages:
/tmp/ccPpnvUP.s:19: Error: operand 1 should be a SIMD vector register -- `pmull %0,%1,%1'
答案 0 :(得分:1)
错误意味着什么,我该如何解决?
我猜错误意味着发生了约束违规。看起来如下诀窍:
$ cat test.cc
#include <arm_neon.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
uint64x2_t r = {0,0}, a = {2,4};
__asm__ __volatile__
(
"pmull %0.1q, %1.1d, %1.1d;"
: "=w" (r)
: "w" (a[0]), "w" (a[1])
: "cc"
);
fprintf(stdout, "%d, %d\n", r[0], r[1]);
return 0;
}
和
$ gcc -march=armv8-a+crc+crypto test.cc -o test.exe
$ ./test.exe
4, 0
And:
$ gdb -batch -ex 'disassemble main' ./test.exe
Dump of assembler code for function main:
0x00000000004005f0 <+0>: stp x29, x30, [sp,#-64]!
0x00000000004005f4 <+4>: mov x29, sp
0x00000000004005f8 <+8>: str w0, [x29,#28]
0x00000000004005fc <+12>: str x1, [x29,#16]
0x0000000000400600 <+16>: movi v0.4s, #0x0
0x0000000000400604 <+20>: mov x0, v0.d[0]
0x0000000000400608 <+24>: mov x1, v0.d[1]
0x000000000040060c <+28>: fmov d0, x0
0x0000000000400610 <+32>: mov v0.d[1], x1
0x0000000000400614 <+36>: str q0, [x29,#48]
0x0000000000400618 <+40>: ldr q0, 0x4006a0
0x000000000040061c <+44>: mov x0, v0.d[0]
0x0000000000400620 <+48>: mov x1, v0.d[1]
0x0000000000400624 <+52>: fmov d0, x0
0x0000000000400628 <+56>: mov v0.d[1], x1
0x000000000040062c <+60>: str q0, [x29,#32]
0x0000000000400630 <+64>: ldr x0, [x29,#32]
0x0000000000400634 <+68>: ldr x1, [x29,#40]
0x0000000000400638 <+72>: fmov d0, x0
0x000000000040063c <+76>: fmov d1, x1
0x0000000000400640 <+80>: pmull v0.1q, v0.1d, v0.1d
0x0000000000400644 <+84>: mov x0, v0.d[0]
0x0000000000400648 <+88>: mov x1, v0.d[1]
0x000000000040064c <+92>: fmov d0, x0
0x0000000000400650 <+96>: mov v0.d[1], x1
0x0000000000400654 <+100>: str q0, [x29,#48]
0x0000000000400658 <+104>: adrp x0, 0x410000
0x000000000040065c <+108>: add x0, x0, #0x9f0
0x0000000000400660 <+112>: ldr x4, [x0]
0x0000000000400664 <+116>: ldr x1, [x29,#48]
0x0000000000400668 <+120>: ldr x2, [x29,#56]
0x000000000040066c <+124>: adrp x0, 0x400000
0x0000000000400670 <+128>: add x0, x0, #0x748
0x0000000000400674 <+132>: mov x3, x2
0x0000000000400678 <+136>: mov x2, x1
0x000000000040067c <+140>: mov x1, x0
0x0000000000400680 <+144>: mov x0, x4
0x0000000000400684 <+148>: bl 0x4004a0 <fprintf@plt>
0x0000000000400688 <+152>: mov w0, #0x0 // #0
0x000000000040068c <+156>: ldp x29, x30, [sp],#64
0x0000000000400690 <+160>: ret
End of assembler dump.
是否存在pmull和pmull2的内在函数?
看起来有一些内在因素:
$ gcc -march=armv8-a+crc+crypto -E test.cc | grep -B 4 pmull
__extension__ static __inline poly16x8_t __attribute__ ((__always_inline__))
vmull_high_p8 (poly8x16_t a, poly8x16_t b)
{
poly16x8_t result;
__asm__ ("pmull2 %0.8h,%1.16b,%2.16b"
--
__extension__ static __inline poly16x8_t __attribute__ ((__always_inline__))
vmull_p8 (poly8x8_t a, poly8x8_t b)
{
poly16x8_t result;
__asm__ ("pmull %0.8h, %1.8b, %2.8b"
--
static __inline poly128_t
vmull_p64 (poly64_t a, poly64_t b)
{
return
__builtin_aarch64_crypto_pmulldi_ppp (a, b);
--
static __inline poly128_t
vmull_high_p64 (poly64x2_t a, poly64x2_t b)
{
return __builtin_aarch64_crypto_pmullv2di_ppp (a, b);