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

FPU Float to signed integer #942

Open
Quma78 opened this issue Jul 5, 2024 · 1 comment · May be fixed by #943
Open

FPU Float to signed integer #942

Quma78 opened this issue Jul 5, 2024 · 1 comment · May be fixed by #943
Assignees
Labels
bug Something isn't working

Comments

@Quma78
Copy link

Quma78 commented Jul 5, 2024

Describe the bug
Hello,
When I replaying the floating_point_test, I came across an error on converting a float to a signed integer.
It seems that the rounding of values exceeding 32 bits with the mantissa at zero is not good.
To be sure, here's the code I used:

To Reproduce

int main() {

  uint32_t err_cnt = 0;
  uint32_t err_cnt_total = 0;
  uint32_t test_cnt = 0;
  uint32_t i = 0;
  float_conv_t opa;
  float_conv_t opb;
  float_conv_t res_hw;
  float_conv_t res_sw;

  // setup UART at default baud rate, no interrupts
  neorv32_uart0_setup(BAUD_RATE, 0);

  // capture all exceptions and give debug info via UART
  neorv32_rte_setup();

/////////////// test //////////////////////////
neorv32_uart0_printf("\nStart Float to signed integer\n");
for(uint32_t i=0; i < 256; i++){
  uint32_t f_value = 0;
  f_value += (i << 24);
  opa.binary_value = f_value;
  
  res_hw.binary_value = (uint32_t)riscv_intrinsic_fcvt_ws(opa.float_value);
  res_sw.binary_value = (uint32_t)riscv_emulate_fcvt_ws(opa.float_value);
  err_cnt += verify_result(i, opa.binary_value, 0, res_sw.binary_value, res_hw.binary_value);
}
neorv32_uart0_printf("Float to signed integer finished! \n");
return 0;
///////////////////////////////////////////////
}

Expected behavior
The rounding should be 0x80000000 but it is just 0.

Screenshots
Capture

Environment:

  • OS: Linux Ubuntu 20.04
  • GCC Version : Your distribution
  • Libraries used : neorv32_zfinx_extension_intrinsics.h and the NEORV32 Lib

Hardware:

  • Hardware version: 1.9.4
  • Implemented CPU extensions, peripherals: Zfinx, Zicond, Zicntr, C, B, M, UART, DSP, Barrel shifter, IMEM, DMEM
  • Hardware modifications: No

Thank you for your help!

@stnolting
Copy link
Owner

stnolting commented Jul 6, 2024

Hey @Quma78!

I just tested your code an I can confirm the bug. Thanks for finding this! I'll try to come up with a fix. 🙈

Hardware version: 1.9.4

Btw, you should really update your version of the core. 😉 There were lots of improvements (and FPU bug fixes) since this version (see changelog).

@stnolting stnolting self-assigned this Jul 6, 2024
@stnolting stnolting added bug Something isn't working HW hardware-related and removed HW hardware-related labels Jul 6, 2024
@stnolting stnolting linked a pull request Jul 6, 2024 that will close this issue
@stnolting stnolting linked a pull request Jul 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants