0
我有一个ARM Neon函数,它使用C类型struct作为参数。 我有一个float*
和float[]
该结构中的固定大小的数组。我能够在我的汇编函数中访问float*
元素。但是当我尝试访问数组的元素时,我的程序崩溃了。ARM程序集:访问C类型的数组元素struct
这里是我的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
数组的地址(可能是)
现在我的问题是,为什么在访问指针元素时访问固定大小的数组会导致问题。那是什么解决方案。
是的。你是对的。现在解决了。 – 2014-11-22 23:23:20