summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/base/types.hh54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/base/types.hh b/src/base/types.hh
index a53f4db9d..c02a606cf 100644
--- a/src/base/types.hh
+++ b/src/base/types.hh
@@ -168,6 +168,60 @@ const Addr MaxAddr = (Addr)-1;
typedef uint64_t RegVal;
typedef double FloatRegVal;
+static inline uint32_t
+floatToBits32(float val)
+{
+ union
+ {
+ float f;
+ uint32_t i;
+ } u;
+ u.f = val;
+ return u.i;
+}
+
+static inline uint64_t
+floatToBits64(double val)
+{
+ union
+ {
+ double f;
+ uint64_t i;
+ } u;
+ u.f = val;
+ return u.i;
+}
+
+static inline uint64_t floatToBits(double val) { return floatToBits64(val); }
+static inline uint32_t floatToBits(float val) { return floatToBits32(val); }
+
+static inline float
+bitsToFloat32(uint32_t val)
+{
+ union
+ {
+ float f;
+ uint32_t i;
+ } u;
+ u.i = val;
+ return u.f;
+}
+
+static inline double
+bitsToFloat64(uint64_t val)
+{
+ union
+ {
+ double f;
+ uint64_t i;
+ } u;
+ u.i = val;
+ return u.f;
+}
+
+static inline double bitsToFloat(uint64_t val) { return bitsToFloat64(val); }
+static inline float bitsToFloat(uint32_t val) { return bitsToFloat32(val); }
+
/**
* Thread index/ID type
*/