[Mesa-dev] [PATCH v2 6/8] nir/spirv: add OpIsFinite and OpIsNormal
Karol Herbst
kherbst at redhat.com
Mon Jul 16 14:28:24 UTC 2018
From: Rob Clark <robdclark at gmail.com>
v2 (Karol Herbst <kherbst at redhat.com>):
make compatible with 64 bit floats
fix isfinite
Signed-off-by: Karol Herbst <kherbst at redhat.com>
---
src/compiler/spirv/vtn_alu.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c
index 5a0347989e9..5db6c7f0a87 100644
--- a/src/compiler/spirv/vtn_alu.c
+++ b/src/compiler/spirv/vtn_alu.c
@@ -583,6 +583,38 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
break;
}
+ case SpvOpIsFinite: {
+ nir_ssa_def *inf = nir_imm_floatN_t(&b->nb, INFINITY, src[0]->bit_size);
+ nir_ssa_def *isNumber = nir_feq(&b->nb, src[0], src[0]);
+ nir_ssa_def *isNotInf = nir_ine(&b->nb, nir_fabs(&b->nb, src[0]), inf);
+ val->ssa->def = nir_iand(&b->nb, isNumber, isNotInf);
+ break;
+ }
+
+ case SpvOpIsNormal: {
+ unsigned bit_size = src[0]->bit_size;
+
+ uint32_t m;
+ if (bit_size == 64)
+ m = 11;
+ else if (bit_size == 32)
+ m = 8;
+ else if (bit_size == 16)
+ m = 5;
+ else
+ assert(!"unknown float type");
+
+ nir_ssa_def *shift = nir_imm_int(&b->nb, bit_size - m - 1);
+ nir_ssa_def *abs = nir_fabs(&b->nb, src[0]);
+ nir_ssa_def *exp = nir_iadd(&b->nb,
+ nir_ushr(&b->nb, abs, shift),
+ nir_imm_intN_t(&b->nb, -1, bit_size));
+ val->ssa->def = nir_ult(&b->nb,
+ exp,
+ nir_imm_intN_t(&b->nb, (1 << m) - 2, bit_size));
+ break;
+ }
+
case SpvOpFUnordEqual:
case SpvOpFUnordNotEqual:
case SpvOpFUnordLessThan:
--
2.17.1
More information about the mesa-dev
mailing list