diff options
Diffstat (limited to 'tb')
| -rw-r--r-- | tb/verilator.hpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tb/verilator.hpp b/tb/verilator.hpp index ff2e9c0..282c7af 100644 --- a/tb/verilator.hpp +++ b/tb/verilator.hpp @@ -1,6 +1,7 @@ #ifndef TALLER_VERILATOR_HPP #define TALLER_VERILATOR_HPP +#include <cmath> #include <cstdint> namespace taller @@ -30,6 +31,15 @@ namespace taller q_bits.fp16 = a_bits.fp16 * b_bits.fp16; return q_bits.u16; } + + static inline std::uint32_t fp_fix(std::uint16_t fp) noexcept + { + fp16_bits fp_bits; + fp_bits.u16 = fp; + + auto as_double = std::ldexp(static_cast<double>(fp_bits.fp16), 16); + return static_cast<std::uint32_t>(static_cast<std::int32_t>(as_double)); + } } #endif |
