From 1e064f29139a45061a8082914e9ee75c15e803a4 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 22 Nov 2023 01:24:41 -0600 Subject: rtl/gfx: implement fp->fixed conversion --- tb/verilator.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tb') 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 #include 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(fp_bits.fp16), 16); + return static_cast(static_cast(as_double)); + } } #endif -- cgit v1.2.3