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

float type printf error using spike #1143

Closed
dshm opened this issue Nov 7, 2022 · 6 comments
Closed

float type printf error using spike #1143

dshm opened this issue Nov 7, 2022 · 6 comments

Comments

@dshm
Copy link

dshm commented Nov 7, 2022

float type and double type can't printed corrcctly using spike pk, the code is simple as below:

#include<stdio.h>
int main()
{
double b=7.7;
float a=5.6;
printf("float test %f\n", a);
printf("double test %f\n", b);
printf("end of float test\n");
return 0;
}

I write above code in floattest.c and run "riscv64-unknown-elf-gcc -o floattest ./floattest.c ; spike pk floattest" then I get the output as below, the float and double type variables are printed as f. Is it an error in spike?

bbl loader
float test f
double test f
end of float test

spike version: master branch, commit id ab3225a
pk version: master branch, commit id 7e9b671c0415dfd7b562ac934feb9380075d4aa2

for spike:

mkdir build;cd build
../configure --prefix=$RISCV
make
make install

for pk
mkdir build; cd build
../configure --prefix=$RISCV --host=riscv64-unknown-elf --with-arch=rv64gc_zifencei
make
make install

Does it wrong to use --with-arch=rv64gc_zifencei to build pk? I referenced riscv-software-src/riscv-pk#260 for help. without --with-arch=rv64gc_zifencei pk can't build successful and report Error: unrecognized opcode `fence.i'

@scottj97
Copy link
Contributor

scottj97 commented Nov 7, 2022

Printing of floating point numbers comes from your C library, which is likely newlib, which has lots of compile-time options for floating-point support.

Assuming support was compiled in, you might need to add to your link line: -u_printf_float

And you might want to build newlib with --enable-newlib-nano-formatted-io for a much simpler/faster floating-point printf.

I'm closing this issue as it's not a Spike problem. You can reopen if you conclude otherwise.

@scottj97 scottj97 closed this as completed Nov 7, 2022
@scottj97 scottj97 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2022
@dshm
Copy link
Author

dshm commented Nov 8, 2022

Printing of floating point numbers comes from your C library, which is likely newlib, which has lots of compile-time options for floating-point support.

Assuming support was compiled in, you might need to add to your link line: -u_printf_float

And you might want to build newlib with --enable-newlib-nano-formatted-io for a much simpler/faster floating-point printf.

I'm closing this issue as it's not a Spike problem. You can reopen if you conclude otherwise.

Is newlib a part of riscv-isa-sim(spike) or riscv-pk? or I need to install newlib in addition? Could you please give me a complete overflow to doing this? thus print float type collectly? this problem also lead to user load segfault for running coremark using spike pk.[https://github.com//issues/1140]
I am a new user of spike and pk, I am not very clear about the structure and use method of spike and pk to printf float, is there some keypoint step I miss? Could you please give me a complete overflow to doing this? Thank you very much. I reopen the issue as it is not completed for me.

@sifiverobert
Copy link

@dshm - This is NOT a spike problem.

You must link your code with proper 'printf' library. Some libraries do NOT include floating point support (to save space).
There are many examples of how to link (and run ...) your RISC-V programs. Sometimes you must also compile your library.

Spike should NOT be used to run Coremark as it is NOT cycle-accurate simulator. Reported values will be meaningless ...

@scottj97
Copy link
Contributor

scottj97 commented Nov 8, 2022

there some keypoint step I miss? Could you please give me a complete overflow to doing this? Thank you very much. I reopen the issue as it is not completed for me.

Spike is running the program you gave it. If that program was not compiled correctly, and apparently it was not, then you will not get the results you expect.

This is the issue tracker for the Spike simulator, not a support forum for newlib or other software compilation questions.

@dshm
Copy link
Author

dshm commented Nov 8, 2022

there some keypoint step I miss? Could you please give me a complete overflow to doing this? Thank you very much. I reopen the issue as it is not completed for me.

Spike is running the program you gave it. If that program was not compiled correctly, and apparently it was not, then you will not get the results you expect.

This is the issue tracker for the Spike simulator, not a support forum for newlib or other software compilation questions.

So where is the offical forum or link to discuss above problems? like errors of using spike or pk? Could you please give a link? It's a little hard and unfriendly for new users. Thanks

@scottj97
Copy link
Contributor

scottj97 commented Nov 8, 2022

The errors become visible when you run your program in Spike, but that's tantamount to blaming the computer for the bugs in your code.

Where did you get your C compiler riscv64-unknown-elf-gcc? That would be a good place to start looking, since that is likely also the same place you got your C library (which I am guessing is newlib).

You need to add something to your compile line that will enable floating-point printf. Have you tried Googling "floating-point printf in newlib"?

You could also ask in the sw-dev mailing list.

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

3 participants