nir/builder: Handle 16-bit floats in nir_imm_floatN_t
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 22 Oct 2018 19:08:44 +0000 (14:08 -0500)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 26 Oct 2018 16:45:29 +0000 (11:45 -0500)
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/compiler/nir/nir_builder.h

index 5ea0a5a2637d8c01b57c19e4b0bd365f43022104..3271a480520ee2d53e802b15301fafc995dfc5b4 100644 (file)
@@ -25,6 +25,7 @@
 #define NIR_BUILDER_H
 
 #include "nir_control_flow.h"
+#include "util/half_float.h"
 
 struct exec_list;
 
@@ -228,6 +229,17 @@ nir_imm_false(nir_builder *build)
    return nir_imm_bool(build, false);
 }
 
+static inline nir_ssa_def *
+nir_imm_float16(nir_builder *build, float x)
+{
+   nir_const_value v;
+
+   memset(&v, 0, sizeof(v));
+   v.u16[0] = _mesa_float_to_half(x);
+
+   return nir_build_imm(build, 1, 16, v);
+}
+
 static inline nir_ssa_def *
 nir_imm_float(nir_builder *build, float x)
 {
@@ -254,6 +266,8 @@ static inline nir_ssa_def *
 nir_imm_floatN_t(nir_builder *build, double x, unsigned bit_size)
 {
    switch (bit_size) {
+   case 16:
+      return nir_imm_float16(build, x);
    case 32:
       return nir_imm_float(build, x);
    case 64: