pulp-platform / pulpino

An open-source microcontroller system based on RISC-V
http://www.pulp-platform.org
Other
878 stars 296 forks source link

Not able to make floating point code work #408

Open haresh-seenivasagan opened 6 months ago

haresh-seenivasagan commented 6 months ago

I am trying to run a simple floating point c code on pulpino but i am facing an issue where floats are not being printed. here is the code that i am trying to run :

#include <stdio.h>
int main() {
    float a =4.2;
    float b = 3.1;
    float c;
    float d;
    c = a+b ;
    d = a-b ;

    printf("Toplam=%f",c);
    printf("Fark=%f",d ); 
return 0;
}

and here is my cmake configuration

TARGET_C_FLAGS="-O3 -m32 -g -fsingle-precision-constant -mfpdouble=float -Werror=double-promotion"
GCC_MARCH="IMFDXpulpv2 -mhard-float"

I am using the https://github.com/pulp-platform/ri5cy_gnu_toolchain compiler with the FPU. since i am adding the -Werror=double-promotion flag i am getting an error

`error: implicit conversion from 'float' to 'double' when passing argument to function [-Werror=double-promotion]`
I understand  that the error is originating because printf implicitly converts float to double when we use %f

 after removing that flag even though the make is successful ,The floats are not visible . Previously  only Toplam= was printed without the floats now i only see garbage characters no matter what i print `†Æ÷.`

 If i remove all other flags and only keep the mfpdouble=float flag then i am getting `error: insn does not satisfy its constraints:

}

^

(insn 43 20 21 2 (set (reg:DF 14 a4)

(reg:DF 47 fa5 [orig:79 D.2575 ] [79])) /home/har/Downloads/pulpino/sw/apps/helloworld/helloworld.c:14 342 {*movdf_hardfloat_rv32}

(`

I have no clue where i am going wrong here would appreciate any help and advice on what direction i should take to solve this issue