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

Floating-point printf output incorrect #409

Open
haresh-seenivasagan opened this issue Mar 17, 2024 · 0 comments
Open

Floating-point printf output incorrect #409

haresh-seenivasagan opened this issue Mar 17, 2024 · 0 comments

Comments

@haresh-seenivasagan
Copy link

haresh-seenivasagan commented Mar 17, 2024

I am attempting to run a simple C program on a PULPino RISC-V platform, but I am encountering issues with floating-point printf output. The program performs some basic floating-point operations (addition and subtraction) and then attempts to print the results using printf. However, the output is incorrect, with the floating-point values not being printed as expected.

Here is the C code:

c

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

}

I am using the following toolchain and settings:

RISC-V GCC compiler : https://github.com/pulp-platform/ri5cy_gnu_toolchain
TARGET_C_FLAGS="  -m32 -g -fsingle-precision-constant -mfpdouble=float "

GCC_MARCH="IMFDXpulpv2 -mhard-float"
GNU version 5.2.0

When I examine the generated assembly code (before it's converted to the s19 format), I notice that the floating-point values are being loaded into integer registers (e.g., a4) instead of floating-point registers (e.g., fa0) before the printf calls. This seems to be causing the incorrect output.

Furthermore, when I try to compile the code with optimization disabled (-O0), I get the following error:

error: insn does not satisfy its constraints:

}


(insn 54 30 31 2 (set (reg:DF 14 a4)
    (reg:DF 47 fa5 [orig:80 D.2652 ] [80])) /home/har/Documents/pulpino/sw/apps/helloworld/helloworld.c:21 342 {*movdf_hardfloat_rv32}
 (nil))

This error suggests that the compiler is trying to generate a movdf (double-precision move) instruction that doesn't satisfy the constraints of the target machine.

However, none of these attempts have resolved the issue.

I suspect that there might be a problem with how the compiler is handling floating-point values and register allocation for the PULPino platform, possibly related to the f extension for single-precision floating-point support.

I would appreciate any insights or suggestions on how to resolve this issue. Please let me know if you need any additional information.

Thank you for your help!

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

1 participant