Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function calls not working riscv-llvm #46

Open
nitish2112 opened this issue Sep 14, 2017 · 1 comment
Open

function calls not working riscv-llvm #46

nitish2112 opened this issue Sep 14, 2017 · 1 comment

Comments

@nitish2112
Copy link

nitish2112 commented Sep 14, 2017

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:

#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;                                                                   
                                                                              
}

When I compile it like this:

% clang -g -O3  -MMD -MP -I. -target riscv64 -mriscv=RV64IAMFD -S  vvadd.c
% riscv64-unknown-elf-gcc vvadd.s -o vvadd
% spike pk vvadd

I get the following error:

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];                                                       
  }                                                                           
}

and compile them using

% clang -g -O3  -MMD -MP -I. -target riscv64 -mriscv=RV64IAMFD -S  vvadd.c
% clang -g -O3  -MMD -MP -I. -target riscv64 -mriscv=RV64IAMFD -S  main.c
% riscv64-unknown-elf-gcc vvadd.s main.s -o vvadd
% spike pk vvadd

I get the following error:

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;                                                                   
                                                                              
}
% clang -g -O3  -MMD -MP -I. -target riscv64 -mriscv=RV64IAMFD -S  vvadd.c
% riscv64-unknown-elf-gcc vvadd.s -o vvadd
% spike pk vvadd

[PASSED]
@nitish2112 nitish2112 changed the title noinline attribute in function calls not working riscv-llvm function calls not working riscv-llvm Sep 14, 2017
@federeghe
Copy link

It may be related to #32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants