stnolting/neorv32

FPU Float to signed integer

Opened this issue ยท 1 comments

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!

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).