Hello Francesco,
The printf() implementation in the driver of lowrisc-nexys4 git repo is
very limited.
It does not recognize %f and if you try printing out floating point
numbers by %d, there is no automatic type conversion from float to int.
Then printf() tries to interpret the floating point number as an
integer, leading to a wrong number.
The easiest way to do it perhaps is to try inside a RISC-V Linux, where
you get full support of printf.
Best regards,
Wei
On 21/06/2016 00:57, Francesco Viggiano wrote:
Hi all,
I'm trying to see if the FPU is working properly on my Rocket
implementation. I have the simplest C code possible:
*...*
*float a=6; float b=2; printf("a/b = %f",a/b);*
*...*
When I try to run it in bare metal, it simply prints out "a/b = %f"! If I
put %d instead of %f it writes 0 as a result of 6 divided by 2. That is a
very strange behavior.
I'm using this script to compile the C code:
*riscv64-unknown-elf-gcc -static -Wa,-march=RVIMAFD -std=gnu99 -g
-ffast-math -fno-common -fno-builtin-printf -I./driver -c
./driver/syscalls.c -o ./driver/syscalls.o*
*riscv64-unknown-elf-gcc -static -Wa,-march=RVIMAFD -std=gnu99 -g
-ffast-math -fno-common -fno-builtin-printf -I./driver -c ./driver/spi.c -o
./driver/spi.o*
*riscv64-unknown-elf-gcc -static -Wa,-march=RVIMAFD -std=gnu99 -g
-ffast-math -fno-common -fno-builtin-printf -I./driver -c ./driver/uart.c
-o ./driver/uart.o*
*riscv64-unknown-elf-gcc -static -Wa,-march=RVIMAFD -std=gnu99 -g
-ffast-math -fno-common -fno-builtin-printf -I./driver -c ./driver/memory.c
-o ./driver/memory.o*
*riscv64-unknown-elf-gcc -static -Wa,-march=RVIMAFD -std=gnu99 -g
-ffast-math -fno-common -fno-builtin-printf -I./driver -c ./driver/elf.c -o
./driver/elf.o*
*riscv64-unknown-elf-gcc -static -Wa,-march=RVIMAFD -std=gnu99 -g
-ffast-math -fno-common -fno-builtin-printf -I./driver -c ./driver/diskio.c
-o ./driver/diskio.o*
*riscv64-unknown-elf-gcc -static -Wa,-march=RVIMAFD -std=gnu99 -g
-ffast-math -fno-common -fno-builtin-printf -I./driver -c ./driver/ff.c -o
./driver/ff.o*
*riscv64-unknown-elf-gcc -static -Wa,-march=RVIMAFD -std=gnu99 -g
-ffast-math -fno-common -fno-builtin-printf -I./driver -c ./driver/crt.S -o
crt.o*
*riscv64-unknown-elf-gcc -T ./driver/test.ld -static -Wa,-march=RVIMAFD
-std=gnu99 -g -ffast-math -fno-common -fno-builtin-printf -I./driver -o
hello.riscv hello.c ./driver/syscalls.o ./driver/spi.o ./driver/uart.o
./driver/memory.o ./driver/elf.o ./driver/diskio.o ./dri\*
*ver/ff.o crt.o -nostdlib -nostartfiles -ffast-math -lc -lgcc*
Is this correct?
Thank you for your help,
Francesco