I am trying to compile a simple vector-vector add program using riscv-llvm compiler and run it on spike and I get the following error:
#include <stdio.h>
void __attribute__ ((noinline)) vvadd( int C[], int A[], int B[], int size )
{
for ( int i = 0; i < size; i++ ) {
C[i] = A[i] + B[i];
}
}
int main() {
int A[10] = { 1,2,3,4,5,6,7,8,9,10 };
int B[10] = { 1,2,3,4,5,6,7,8,9,10 };
int C[10];
vvadd(C, A, B, 10);
for ( int i = 0; i < 10; i++ ) {
if ( C[i] != 2*(i+1) ) {
printf("\n[FAILED]\n");
return 0;
}
}
printf("\n[PASSED]\n");
return 0;
}
z 0000000000000000 ra 00000000000102e8 sp 000000007f7e9ac0 gp 0000000000015bf8
tp 0000000000000000 t0 0000000000000014 t1 0000000000000009 t2 0000000000000002
s0 000000007f7e9ac0 s1 0000000000000000 a0 0000000000000001 a1 0000000000000018
a2 000000007f7e9b18 a3 0000000000000000 a4 0000000000000010 a5 0000000000000002
a6 000000000000001f a7 0000000000000000 s2 0000000000000000 s3 0000000000000000
s4 0000000000000000 s5 0000000000000000 s6 0000000000000000 s7 0000000000000000
s8 0000000000000000 s9 0000000000000000 sA 0000000000000000 sB 0000000000000000
t3 0000000000000000 t4 0000000000000000 t5 0000000000000000 t6 0000000000000000
pc 0000000000010304 va 0000000000000014 insn ffffffff sr 8000000200046020
User load segfault @ 0x0000000000000014
When instead I try to break the code in two files:
main.c
#include <stdio.h>
void vvadd( int C[], int A[], int B[], int size );
int main() {
int A[10] = { 1,2,3,4,5,6,7,8,9,10 };
int B[10] = { 1,2,3,4,5,6,7,8,9,10 };
int C[10];
vvadd(C, A, B, 10);
for ( int i = 0; i < 10; i++ ) {
if ( C[i] != 2*(i+1) ) {
printf("\n[FAILED]\n");
return 0;
}
}
printf("\n[PASSED]\n");
return 0;
}
vvadd.c
void vvadd( int C[], int A[], int B[], int size )
{
for ( int i = 0; i < size; i++ ) {
C[i] = A[i] + B[i];
}
}
z 0000000000000000 ra 00000000000102f8 sp 000000007f7e9ac0 gp 0000000000015c00
tp 0000000000000000 t0 000000000000000a t1 0000000000000009 t2 0000000000000000
s0 000000007f7e9ac0 s1 0000000000000000 a0 000000000000000a a1 000000007f7e9b18
a2 000000007f7e9af0 a3 000000000000000a a4 000000000000000a a5 0000000000000002
a6 000000000000001f a7 0000000000000000 s2 0000000000000000 s3 0000000000000000
s4 0000000000000000 s5 0000000000000000 s6 0000000000000000 s7 0000000000000000
s8 0000000000000000 s9 0000000000000000 sA 0000000000000000 sB 0000000000000000
t3 0000000000000000 t4 0000000000000000 t5 0000000000000000 t6 0000000000000000
pc 000000000001030c va 000000000000000a insn ffffffff sr 8000000200046020
User load segfault @ 0x000000000000000a
I am using commit point e617c9c for riscv-llvm and 52e04ed for riscv-clang, commit 65cb174 for riscv-gnu-toolchain, 3a4e893 for riscv-isa-sim and 2dcae92 for riscv-pk ( basically riscv-trunk branch for both gnu tool chain and llvm ).
The program however works perfectly fine when there are no function call:
vvadd.c
int A[100];
int B[100];
int C[100];
#include <stdio.h>
int main() {
for ( int i = 0; i < 100; i++ ) {
A[i] = i+1;
B[i] = i+1;
}
for ( int i = 0; i < 100; i++ ) {
C[i] = A[i] + B[i];
}
for ( int i = 0; i < 100; i++ ) {
if ( C[i] != 2*(i+1) ) {
printf("\n[FAILED]\n");
return 0;
}
}
printf("\n[PASSED]\n");
return 0;
}
Hi everyone,
I am trying to compile a simple vector-vector add program using riscv-llvm compiler and run it on spike and I get the following error:
When I compile it like this:
I get the following error:
When instead I try to break the code in two files:
main.c
vvadd.c
and compile them using
I get the following error:
I am using commit point e617c9c for riscv-llvm and 52e04ed for riscv-clang, commit 65cb174 for riscv-gnu-toolchain, 3a4e893 for riscv-isa-sim and 2dcae92 for riscv-pk ( basically riscv-trunk branch for both gnu tool chain and llvm ).
The program however works perfectly fine when there are no function call:
vvadd.c