Skip to content

Commit

Permalink
Refactor softfp library into a single header C++ library
Browse files Browse the repository at this point in the history
- Remove gotos
- Use braces in all blocks
- Always initialize variables
- Replace int bools with bool
- Remove float128 support
- Remove unused code
- Use templates instead of macros
- Rename and document functions
- Use C++ style static casts
- Simplify some portions of the code
  • Loading branch information
edubart committed Nov 24, 2022
1 parent 1c24573 commit 0f489d9
Show file tree
Hide file tree
Showing 14 changed files with 1,065 additions and 2,009 deletions.
2 changes: 0 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ CARTESI_OBJS:= \
machine.o \
machine-config.o \
interpret.o \
soft-float.o \
virtual-machine.o \
protobuf-util.o \
machine-c-api.o \
Expand Down Expand Up @@ -521,7 +520,6 @@ REMOTE_CARTESI_MACHINE_OBJS:= \
machine.o \
machine-config.o \
interpret.o \
soft-float.o \
uarch-machine.o \
uarch-interpret.o

Expand Down
118 changes: 60 additions & 58 deletions src/interpret.cpp

Large diffs are not rendered by default.

30 changes: 19 additions & 11 deletions src/riscv-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ enum SENVCFG_RW_masks : uint64_t {

/// \brief fcsr fflags shifts
enum FFLAGS_shifts {
FFLAGS_NX_SHIFT = 0,
FFLAGS_UF_SHIFT = 1,
FFLAGS_OF_SHIFT = 2,
FFLAGS_DZ_SHIFT = 3,
FFLAGS_NV_SHIFT = 4,
FFLAGS_NX_SHIFT = 0, // Inexact
FFLAGS_UF_SHIFT = 1, // Underflow
FFLAGS_OF_SHIFT = 2, // Overflow
FFLAGS_DZ_SHIFT = 3, // Divide by zero
FFLAGS_NV_SHIFT = 4, // Invalid op
};

/// \brief fcsr fflags masks
Expand All @@ -351,6 +351,20 @@ enum FRM_modes : uint32_t {
FRM_DYN = UINT32_C(0b111)
};

/// \brief float classes
enum FCLASS_classes : uint32_t {
FCLASS_NINF = 1 << 0,
FCLASS_NNORMAL = 1 << 1,
FCLASS_NSUBNORMAL = 1 << 2,
FCLASS_NZERO = 1 << 3,
FCLASS_PZERO = 1 << 4,
FCLASS_PSUBNORMAL = 1 << 5,
FCLASS_PNORMAL = 1 << 6,
FCLASS_PINF = 1 << 7,
FCLASS_SNAN = 1 << 8,
FCLASS_QNAN = 1 << 9
};

/// \brief frm masks
enum FCSR_FRM_masks : uint64_t { FRM_RW_MASK = 0b111 };

Expand All @@ -367,12 +381,6 @@ enum FCSR_rw_masks : uint64_t {
FCSR_RW_MASK = FCSR_FFLAGS_RW_MASK | FCSR_FRM_RW_MASK
};

/// \brief float32 constants
enum F32_constants : uint32_t { F32_CANONICAL_NAN = UINT32_C(0x7FC00000), F32_SIGN_MASK = UINT32_C(1) << 31 };

/// \brief float64 constants
enum F64_constants : uint64_t { F64_CANONICAL_NAN = UINT64_C(0x7FF8000000000000), F64_SIGN_MASK = UINT64_C(1) << 63 };

/// \brief Paging shifts
enum PAGE_shifts {
PAGE_NUMBER_SHIFT = 12,
Expand Down
28 changes: 0 additions & 28 deletions src/soft-float.cpp

This file was deleted.

Loading

0 comments on commit 0f489d9

Please sign in to comment.