summaryrefslogtreecommitdiff
path: root/src/util/half_float.h
diff options
context:
space:
mode:
authorKristian H. Kristensen <hoegsberg@google.com>2020-01-16 14:56:53 -0800
committerMarge Bot <eric+marge@anholt.net>2020-03-09 16:31:08 +0000
commit4068d6baff78b203477abbd3c3453a0058ecee56 (patch)
treedaed64b52d35c24211cef344f97604d409c02ccc /src/util/half_float.h
parentb75a166e6866c4ab3f2c525763a25c9b7ab9fb56 (diff)
downloadmesa-4068d6baff78b203477abbd3c3453a0058ecee56.tar.gz
mesa-4068d6baff78b203477abbd3c3453a0058ecee56.tar.bz2
mesa-4068d6baff78b203477abbd3c3453a0058ecee56.zip
glsl: Add ir_constant constructor for fp16
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3929>
Diffstat (limited to 'src/util/half_float.h')
-rw-r--r--src/util/half_float.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/util/half_float.h b/src/util/half_float.h
index 84112e57bd4..c9fad9a9400 100644
--- a/src/util/half_float.h
+++ b/src/util/half_float.h
@@ -33,8 +33,8 @@
extern "C" {
#endif
-#define FP16_ONE 0x3C00
-#define FP16_ZERO 0
+#define FP16_ONE ((uint16_t) 0x3c00)
+#define FP16_ZERO ((uint16_t) 0)
uint16_t _mesa_float_to_half(float val);
float _mesa_half_to_float(uint16_t val);
@@ -63,6 +63,22 @@ _mesa_half_is_negative(uint16_t h)
#ifdef __cplusplus
+
+/* Helper class for disambiguating fp16 from uint16_t in C++ overloads */
+
+struct float16_t {
+ uint16_t bits;
+ float16_t(float f) : bits(_mesa_float_to_half(f)) {}
+ float16_t(double d) : bits(_mesa_float_to_half(d)) {}
+ float16_t(uint16_t bits) : bits(bits) {}
+ static float16_t one() { return float16_t(FP16_ONE); }
+ static float16_t zero() { return float16_t(FP16_ZERO); }
+};
+
+#endif
+
+
+#ifdef __cplusplus
} /* extern C */
#endif