Mesa (master): gallium/util: add bitcast helpers for double and uint

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Dec 15 15:28:46 UTC 2020


Module: Mesa
Branch: master
Commit: c314893988d4b7408383d5c0357319082c347fc6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c314893988d4b7408383d5c0357319082c347fc6

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Thu Dec 10 13:20:53 2020 +0100

gallium/util: add bitcast helpers for double and uint

This complements u_bitcast_f2u and u_bitcast_u2f with similar helpers
to cast between double and unsigned integers as well.

Reviewed-by: Hoe Hao Cheng <haochengho12907 at gmail.com>
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8034>

---

 src/gallium/auxiliary/util/u_bitcast.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_bitcast.h b/src/gallium/auxiliary/util/u_bitcast.h
index 703ea64e4dd..f5b33471ad1 100644
--- a/src/gallium/auxiliary/util/u_bitcast.h
+++ b/src/gallium/auxiliary/util/u_bitcast.h
@@ -45,6 +45,14 @@ u_bitcast_f2u(float f)
    return u;
 }
 
+static inline uint64_t
+u_bitcast_d2u(double d)
+{
+   uint64_t u;
+   memcpy(&u, &d, sizeof(u));
+   return u;
+}
+
 static inline float
 u_bitcast_u2f(uint32_t u)
 {
@@ -53,6 +61,14 @@ u_bitcast_u2f(uint32_t u)
    return f;
 }
 
+static inline double
+u_bitcast_u2d(uint64_t u)
+{
+   double d;
+   memcpy(&d, &u, sizeof(d));
+   return d;
+}
+
 #ifdef __cplusplus
 }
 #endif



More information about the mesa-commit mailing list