<div dir="ltr"><div class="gmail_quote"><div>Looks the same as what we do for the others.</div><div><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div dir="ltr"><br></div><div dir="ltr">On Tue, Dec 4, 2018 at 1:18 AM Iago Toral Quiroga <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
src/compiler/spirv/vtn_glsl450.c | 48 ++++++++++++++++++++++++++++++--<br>
1 file changed, 46 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/src/compiler/spirv/vtn_glsl450.c b/src/compiler/spirv/vtn_glsl450.c<br>
index 85851755aab..bb340c87416 100644<br>
--- a/src/compiler/spirv/vtn_glsl450.c<br>
+++ b/src/compiler/spirv/vtn_glsl450.c<br>
@@ -389,6 +389,45 @@ build_atan2(nir_builder *b, nir_ssa_def *y, nir_ssa_def *x)<br>
nir_fneg(b, arc), arc);<br>
}<br>
<br>
+static nir_ssa_def *<br>
+build_frexp16(nir_builder *b, nir_ssa_def *x, nir_ssa_def **exponent)<br>
+{<br>
+ assert(x->bit_size == 16);<br>
+<br>
+ nir_ssa_def *abs_x = nir_fabs(b, x);<br>
+ nir_ssa_def *zero = nir_imm_floatN_t(b, 0, 16);<br>
+<br>
+ /* Half-precision floating-point values are stored as<br>
+ * 1 sign bit;<br>
+ * 5 exponent bits;<br>
+ * 10 mantissa bits.<br>
+ *<br>
+ * An exponent shift of 10 will shift the mantissa out, leaving only the<br>
+ * exponent and sign bit (which itself may be zero, if the absolute value<br>
+ * was taken before the bitcast and shift).<br>
+ */<br>
+ nir_ssa_def *exponent_shift = nir_imm_int(b, 10);<br>
+ nir_ssa_def *exponent_bias = nir_imm_intN_t(b, -14, 16);<br>
+<br>
+ nir_ssa_def *sign_mantissa_mask = nir_imm_intN_t(b, 0x83ffu, 16);<br>
+<br>
+ /* Exponent of floating-point values in the range [0.5, 1.0). */<br>
+ nir_ssa_def *exponent_value = nir_imm_intN_t(b, 0x3800u, 16);<br>
+<br>
+ nir_ssa_def *is_not_zero = nir_fne(b, abs_x, zero);<br>
+<br>
+ /* Significand return must be of the same type as the input, but the<br>
+ * exponent must be a 32-bit integer.<br>
+ */<br>
+ *exponent =<br>
+ nir_i2i32(b,<br>
+ nir_iadd(b, nir_ushr(b, abs_x, exponent_shift),<br>
+ nir_bcsel(b, is_not_zero, exponent_bias, zero)));<br>
+<br>
+ return nir_ior(b, nir_iand(b, x, sign_mantissa_mask),<br>
+ nir_bcsel(b, is_not_zero, exponent_value, zero));<br>
+}<br>
+<br>
static nir_ssa_def *<br>
build_frexp32(nir_builder *b, nir_ssa_def *x, nir_ssa_def **exponent)<br>
{<br>
@@ -751,8 +790,10 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,<br>
nir_ssa_def *exponent;<br>
if (src[0]->bit_size == 64)<br>
val->ssa->def = build_frexp64(nb, src[0], &exponent);<br>
- else<br>
+ else if (src[0]->bit_size == 32)<br>
val->ssa->def = build_frexp32(nb, src[0], &exponent);<br>
+ else<br>
+ val->ssa->def = build_frexp16(nb, src[0], &exponent);<br>
nir_store_deref(nb, vtn_nir_deref(b, w[6]), exponent, 0xf);<br>
return;<br>
}<br>
@@ -762,9 +803,12 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,<br>
if (src[0]->bit_size == 64)<br>
val->ssa->elems[0]->def = build_frexp64(nb, src[0],<br>
&val->ssa->elems[1]->def);<br>
- else<br>
+ else if (src[0]->bit_size == 32)<br>
val->ssa->elems[0]->def = build_frexp32(nb, src[0],<br>
&val->ssa->elems[1]->def);<br>
+ else<br>
+ val->ssa->elems[0]->def = build_frexp16(nb, src[0],<br>
+ &val->ssa->elems[1]->def);<br>
return;<br>
}<br>
<br>
-- <br>
2.17.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div></div>