diff options
author | Karol Herbst <[email protected]> | 2018-07-12 15:02:27 +0200 |
---|---|---|
committer | Karol Herbst <[email protected]> | 2019-03-05 22:28:29 +0100 |
commit | 272e927d0e9fed6e791d706ff5d895b6c2036fc0 (patch) | |
tree | 2bbe3b7fbef9275137bd4669cb86b72181094379 /src/compiler/nir/nir_opcodes.py | |
parent | d0b47ec4df0eafe4f4afddc2a0594b392c27f426 (diff) |
nir/spirv: initial handling of OpenCL.std extension opcodes
Not complete, mostly just adding things as I encounter them in CTS. But
not getting far enough yet to hit most of the OpenCL.std instructions.
Anyway, this is better than nothing and covers the most common builtins.
v2: add hadd proof from Jason
move some of the lowering into opt_algebraic and create new nir opcodes
simplify nextafter lowering
fix normalize lowering for inf
rework upsample to use nir_pack_bits
add missing files to build systems
v3: split lines of iadd/sub_sat expressions
Signed-off-by: Karol Herbst <[email protected]>
Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_opcodes.py')
-rw-r--r-- | src/compiler/nir/nir_opcodes.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index 42f8662352e..5da3cafabb2 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -466,8 +466,20 @@ def binop_reduce(name, output_size, output_type, src_type, prereduce_expr, binop("fadd", tfloat, commutative + associative, "src0 + src1") binop("iadd", tint, commutative + associative, "src0 + src1") +binop("iadd_sat", tint, commutative + associative, """ + src1 > 0 ? + (src0 + src1 < src0 ? (1ull << (bit_size - 1)) - 1 : src0 + src1) : + (src0 < src0 + src1 ? (1ull << (bit_size - 1)) : src0 + src1) +""") binop("uadd_sat", tuint, commutative, "(src0 + src1) < src0 ? UINT64_MAX : (src0 + src1)") +binop("isub_sat", tint, "", """ + src1 < 0 ? + (src0 - src1 < src0 ? (1ull << (bit_size - 1)) - 1 : src0 - src1) : + (src0 < src0 - src1 ? (1ull << (bit_size - 1)) : src0 - src1) +""") +binop("usub_sat", tuint, "", "src0 < src1 ? 0 : src0 - src1") + binop("fsub", tfloat, "", "src0 - src1") binop("isub", tint, "", "src0 - src1") @@ -536,6 +548,32 @@ binop_convert("uadd_carry", tuint, tuint, commutative, "src0 + src1 < src0") binop_convert("usub_borrow", tuint, tuint, "", "src0 < src1") +# hadd: (a + b) >> 1 (without overflow) +# x + y = x - (x & ~y) + (x & ~y) + y - (~x & y) + (~x & y) +# = (x & y) + (x & ~y) + (x & y) + (~x & y) +# = 2 * (x & y) + (x & ~y) + (~x & y) +# = ((x & y) << 1) + (x ^ y) +# +# Since we know that the bottom bit of (x & y) << 1 is zero, +# +# (x + y) >> 1 = (((x & y) << 1) + (x ^ y)) >> 1 +# = (x & y) + ((x ^ y) >> 1) +binop("ihadd", tint, commutative, "(src0 & src1) + ((src0 ^ src1) >> 1)") +binop("uhadd", tuint, commutative, "(src0 & src1) + ((src0 ^ src1) >> 1)") + +# rhadd: (a + b + 1) >> 1 (without overflow) +# x + y + 1 = x + (~x & y) - (~x & y) + y + (x & ~y) - (x & ~y) + 1 +# = (x | y) - (~x & y) + (x | y) - (x & ~y) + 1 +# = 2 * (x | y) - ((~x & y) + (x & ~y)) + 1 +# = ((x | y) << 1) - (x ^ y) + 1 +# +# Since we know that the bottom bit of (x & y) << 1 is zero, +# +# (x + y + 1) >> 1 = (x | y) + (-(x ^ y) + 1) >> 1) +# = (x | y) - ((x ^ y) >> 1) +binop("irhadd", tint, commutative, "(src0 | src1) + ((src0 ^ src1) >> 1)") +binop("urhadd", tuint, commutative, "(src0 | src1) + ((src0 ^ src1) >> 1)") + binop("umod", tuint, "", "src1 == 0 ? 0 : src0 % src1") # For signed integers, there are several different possible definitions of |