summaryrefslogtreecommitdiff
path: root/src/compiler/nir/nir.c
diff options
context:
space:
mode:
authorJason Ekstrand <jason@jlekstrand.net>2019-06-20 10:36:10 -0500
committerJuan A. Suarez Romero <jasuarez@igalia.com>2019-07-15 10:09:44 +0000
commitafaec581a880a5e1c7ecaf7ba45f48d2be437792 (patch)
treee45a150d867b175cebd4d0d9a5b27a2f4d12b764 /src/compiler/nir/nir.c
parentf5e70045e1ad7ff6c2cdd9a8eff682fcdd166067 (diff)
downloadmesa-afaec581a880a5e1c7ecaf7ba45f48d2be437792.tar.gz
nir: Add more helpers for working with const values
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com> (cherry picked from commit ce5581e23e54be91e4c1ad6a6c5990eca6677ceb)
Diffstat (limited to 'src/compiler/nir/nir.c')
-rw-r--r--src/compiler/nir/nir.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 5b75585498e..5c1e0e8a3b3 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -1204,6 +1204,41 @@ nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state)
return nir_foreach_dest(instr, visit_dest_indirect, &dest_state);
}
+nir_const_value
+nir_const_value_for_float(double f, unsigned bit_size)
+{
+ nir_const_value v;
+ memset(&v, 0, sizeof(v));
+
+ switch (bit_size) {
+ case 16:
+ v.u16 = _mesa_float_to_half(f);
+ break;
+ case 32:
+ v.f32 = f;
+ break;
+ case 64:
+ v.f64 = f;
+ break;
+ default:
+ unreachable("Invalid bit size");
+ }
+
+ return v;
+}
+
+double
+nir_const_value_as_float(nir_const_value value, unsigned bit_size)
+{
+ switch (bit_size) {
+ case 16: return _mesa_half_to_float(value.u16);
+ case 32: return value.f32;
+ case 64: return value.f64;
+ default:
+ unreachable("Invalid bit size");
+ }
+}
+
int64_t
nir_src_comp_as_int(nir_src src, unsigned comp)
{