From 44ada20e2fe3fc8af1b7da12158e4c58028ff1e7 Mon Sep 17 00:00:00 2001 From: stnolting <22944758+stnolting@users.noreply.github.com> Date: Fri, 5 May 2023 11:28:26 +0200 Subject: [PATCH] [FPU test program] clean-up (and fix) --- sw/example/floating_point_test/main.c | 5 +- .../neorv32_zfinx_extension_intrinsics.h | 50 ------------------- 2 files changed, 2 insertions(+), 53 deletions(-) diff --git a/sw/example/floating_point_test/main.c b/sw/example/floating_point_test/main.c index a2d1e3089..222573708 100644 --- a/sw/example/floating_point_test/main.c +++ b/sw/example/floating_point_test/main.c @@ -147,9 +147,8 @@ int main() { neorv32_uart0_printf("Test cases per instruction: %u\n", (uint32_t)NUM_TEST_CASES); neorv32_uart0_printf("NOTE: The NEORV32 FPU does not support subnormal numbers yet. Subnormal numbers are flushed to zero.\n\n"); - // clear exception status word - neorv32_cpu_csr_write(CSR_FFLAGS, 0); // real hardware - feclearexcept(FE_ALL_EXCEPT); // software runtime (GCC floating-point emulation) + // clear FPU status/control word + neorv32_cpu_csr_write(CSR_FCSR, 0); // ---------------------------------------------------------------------------- diff --git a/sw/example/floating_point_test/neorv32_zfinx_extension_intrinsics.h b/sw/example/floating_point_test/neorv32_zfinx_extension_intrinsics.h index 2519cc7d6..9180d7a0e 100644 --- a/sw/example/floating_point_test/neorv32_zfinx_extension_intrinsics.h +++ b/sw/example/floating_point_test/neorv32_zfinx_extension_intrinsics.h @@ -106,56 +106,6 @@ float subnormal_flush(float tmp) { } -// ################################################################################################ -// Exception access -// ################################################################################################ - -/**********************************************************************//** - * Get exception flags from fflags CSR (floating-point hardware). - * - * @return Floating point exception status word. - **************************************************************************/ -uint32_t get_hw_exceptions(void) { - - uint32_t res = neorv32_cpu_csr_read(CSR_FFLAGS); - - neorv32_cpu_csr_write(CSR_FFLAGS, 0); // clear status word - - return res; -} - - -/**********************************************************************//** - * Get exception flags from C runtime (floating-point emulation). - * - * @warning WORK-IN-PROGRESS! - * - * @return Floating point exception status word. - **************************************************************************/ -uint32_t get_sw_exceptions(void) { - - const uint32_t FP_EXC_NV_C = 1 << 0; // invalid operation - const uint32_t FP_EXC_DZ_C = 1 << 1; // divide by zero - const uint32_t FP_EXC_OF_C = 1 << 2; // overflow - const uint32_t FP_EXC_UF_C = 1 << 3; // underflow - const uint32_t FP_EXC_NX_C = 1 << 4; // inexact - - int fpeRaised = fetestexcept(FE_ALL_EXCEPT); - - uint32_t res = 0; - - if (fpeRaised & FE_INVALID) { res |= FP_EXC_NV_C; } - if (fpeRaised & FE_DIVBYZERO) { res |= FP_EXC_DZ_C; } - if (fpeRaised & FE_OVERFLOW) { res |= FP_EXC_OF_C; } - if (fpeRaised & FE_UNDERFLOW) { res |= FP_EXC_UF_C; } - if (fpeRaised & FE_INEXACT) { res |= FP_EXC_NX_C; } - - feclearexcept(FE_ALL_EXCEPT); - - return res; -} - - // ################################################################################################ // "Intrinsics" // ################################################################################################