手臂霓虹灯 vst1.32 段错误
arm neon vst1.32 segfault
下面的代码简单地尝试将数据从 '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"
);
[out0]"=r"(out0)
表示out0中的值会被asm覆盖。由于该值在被覆盖之前从未使用过,因此为其分配一些内容有什么意义?
换句话说,尽管看起来有悖常理,out0 是一个输入。
那么你如何告诉 gcc 你正在修改 out0 的 contents?在这种情况下,内存破坏就足够了。
下面的代码简单地尝试将数据从 '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"
);
[out0]"=r"(out0)
表示out0中的值会被asm覆盖。由于该值在被覆盖之前从未使用过,因此为其分配一些内容有什么意义?
换句话说,尽管看起来有悖常理,out0 是一个输入。
那么你如何告诉 gcc 你正在修改 out0 的 contents?在这种情况下,内存破坏就足够了。