C 유형 struct를 인수로 사용하는 ARM Neon 함수가 있습니다. 구조체에 고정 크기 배열 float*
및 float[]
배열이 있습니다. 내 어셈블리 기능에서 float*
요소에 액세스 할 수 있습니다. 그러나 배열 요소에 액세스하려고하면 프로그램이 중단됩니다.ARM 어셈블리 : C 유형 struct에있는 배열 요소 액세스
.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 ...
이 문제가 원인 일 수 있습니다
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 파일입니다
typedef struct{
float* f1;
float* f2;
float f3[4];
}P_STRUCT;
을 main.c 파일 : 여기
내 C 측 응용 프로그램입니다r10
은
f3
배열의 주소를 가리 키지 않습니다. (아마)
이제 제 질문은 포인터 요소에 액세스하는 동안 고정 크기 배열에 액세스하면 문제가 발생하는 이유입니다. 그리고 그것을위한 해결책은 무엇입니까.
예. 당신 말이 맞아요. 이제 해결되었습니다. –