【发布时间】:2014-11-22 22:48:32
【问题描述】:
我有一个使用 C 类型结构作为参数的 ARM Neon 函数。
我在该结构中有一个固定大小的float* 和float[] 数组。我可以在我的汇编函数中访问float* 元素。但是当我尝试访问数组的元素时,我的程序崩溃了。
这是我的 C 端应用程序:
typedef struct{
float* f1;
float* f2;
float f3[4];
}P_STRUCT;
main.c 文件:
extern void myNeonFunc(P_STRUCT* p, float* res);
P_STRUCT p;
// memory allocation for f1,f2 and fill array f3 here.
// memory allocation for res
myNeonFunc(&p, res);
这是我的 .S 文件:
.text
.set P_STRUCT_F1, 0 @ float* f1
.set P_STRUCT_F2, 4 @ float* f2
.set P_STRUCT_F3, 8 @ float f3[4]
.globl myNeonFunc
@ void myNeonFunc (P_STRUCT* p ----> r0, r1 )
.balign 64 @ align the function to 64
myNeonFunc:
@save callee-save registers here
ldr r8, [r0,P_STRUCT_F1] @ r8 <- f1
add r8, r8, #8 @ r8 points to the f1[2] (2*4 = 8 )
ldr r9, [r0,P_STRUCT_F2] @ r9 <- f2
add r9, r9, #4 @ r9 points to the f2[1] (1*4 = 8)
ldr r10, [r0,P_STRUCT_F3] @ r10 <- f3
add r10, r10, #4 @ r10 points to the f3[1] (1*4 = 8)
vld1.f32 {d4}, [r8]! @ d4 now contains the corresponding r8 value
vld1.f32 {d6}, [r9]! @ d6 now contains the corresponding r9 value
vst1.32 {d4}, [r1]! @ store f1[2] value in result register
vst1.32 {d6}, [r1]! @ store f1[1] value in result register
// every thing is ok up to here
// this line probably causes seg fault !!!
vld1.f32 {d8}, [r10]! @ d8 now contains the corresponding r10 value
//
vst1.32 {d8}, [r1]! @ store f3[1] value in result register
// epilog part here ...
这个问题可能是因为r10没有指向f3数组的地址。(可能)
现在我的问题是,为什么在访问指针元素时访问固定大小的数组会导致问题。解决方案是什么。
【问题讨论】:
标签: c arrays assembly arm neon