Skip to content

Commit

Permalink
[FPU test program] clean-up (and fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
stnolting committed May 5, 2023
1 parent 3c1700b commit 44ada20
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 53 deletions.
5 changes: 2 additions & 3 deletions sw/example/floating_point_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);


// ----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
// ################################################################################################
Expand Down

0 comments on commit 44ada20

Please sign in to comment.