summaryrefslogtreecommitdiff
path: root/tb/verilator.hpp
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2023-11-22 01:24:41 -0600
committerAlejandro Soto <alejandro@34project.org>2023-11-22 02:31:51 -0600
commit1e064f29139a45061a8082914e9ee75c15e803a4 (patch)
tree2fac1bd24026807bd8e6fee1f278dc4b155afde3 /tb/verilator.hpp
parent3f5ec7003075eb78e7e2a7b179cbcd3a6c9e294d (diff)
rtl/gfx: implement fp->fixed conversion
Diffstat (limited to '')
-rw-r--r--tb/verilator.hpp10
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