[Mesa-dev] [PATCH v2 6/8] nir/spirv: add OpIsFinite and OpIsNormal
Jason Ekstrand
jason at jlekstrand.net
Mon Jul 16 15:25:43 UTC 2018
On Mon, Jul 16, 2018 at 7:29 AM Karol Herbst <kherbst at redhat.com> wrote:
> 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]);
>
Please use snake_case.
> + nir_ssa_def *isNotInf = nir_ine(&b->nb, nir_fabs(&b->nb, src[0]),
> inf);
>
Same here.
> + 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
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180716/d5db31ca/attachment.html>
More information about the mesa-dev
mailing list