arm neon vst1.32 segfault

时间:2016-04-24 18:10:25

标签: assembly arm inline-assembly neon

以下代码只是尝试复制' in *'中的数据。阵列到' out *'数组,但第一个vst1.32指令的段错误,但为什么?

int* in0 = new int[4]{ 0x0, 0x1, 0x2, 0x3 };
int* in1 = new int[4]{ 0x4, 0x5, 0x6, 0x7 };
int* in2 = new int[4]{ 0x8, 0x9, 0xA, 0xB };
int* in3 = new int[4]{ 0xC, 0xD, 0xE, 0xF };

int* out0 = new int[4]{};
int* out1 = new int[4]{};
int* out2 = new int[4]{};
int* out3 = new int[4]{};

asm volatile("vld1.32 {d0, d1}, [%[in0]]      \n"
             "vld1.32 {d2, d3}, [%[in1]]      \n"
             "vld1.32 {d4, d5}, [%[in2]]      \n"
             "vld1.32 {d6, d7}, [%[in3]]      \n"
             "vst1.32 {d0, d1}, [%[out0]]     \n"
             "vst1.32 {d2, d3}, [%[out1]]     \n"
             "vst1.32 {d4, d5}, [%[out2]]     \n"
             "vst1.32 {d6, d7}, [%[out3]]     \n"
             : [out0]"=r"(out0), [out1]"=r"(out1), [out2]"=r"(out2), [out3]"=r"(out3)
             : [in0]"r"(in0), [in1]"r"(in1), [in2]"r"(in2), [in3]"r"(in3)
             : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "memory", "cc"
             );

1 个答案:

答案 0 :(得分:3)

[out0]"=r"(out0)表示outm中的值将被asm覆盖。而且,由于在被覆盖之前从未使用过该值,因此分配内容的重点是什么?

换句话说,就像看起来的反直觉一样,out0是一个输入。

那你怎么告诉gcc你正在修改out0的内容?在这种情况下,内存破坏应该足够了。