agx: Implement unary math ops
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 24 Oct 2022 00:50:17 +0000 (20:50 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 10 Nov 2022 02:25:09 +0000 (02:25 +0000)
Implement nir_op_bitfield_reverse, nir_op_bit_count, and
nir_op_ufind_msb. These map to native instructions.  With appropriate
integer render target and multiple render target support, passes:

   dEQP-GLES31.functional.shaders.builtin_functions.integer.bitfieldreverse.*vertex
   dEQP-GLES31.functional.shaders.builtin_functions.integer.bitfieldreverse.*fragment
   dEQP-GLES31.functional.shaders.builtin_functions.integer.bitcount.*vertex
   dEQP-GLES31.functional.shaders.builtin_functions.integer.bitcount.*fragment
   dEQP-GLES31.functional.shaders.builtin_functions.integer.findLSB.*vertex
   dEQP-GLES31.functional.shaders.builtin_functions.integer.findLSB.*fragment
   dEQP-GLES31.functional.shaders.builtin_functions.integer.findMSB.*vertex
   dEQP-GLES31.functional.shaders.builtin_functions.integer.findMSB.*fragment

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19590>

src/asahi/compiler/agx_compile.c
src/asahi/compiler/agx_opcodes.py

index 0a0efc6..70b2294 100644 (file)
@@ -871,6 +871,9 @@ agx_emit_alu(agx_builder *b, nir_alu_instr *instr)
    UNOP(mov, mov);
    UNOP(u2u16, mov);
    UNOP(u2u32, mov);
+   UNOP(bitfield_reverse, bitrev);
+   UNOP(bit_count, popcount);
+   UNOP(ufind_msb, ffs);
    UNOP(inot, not);
    BINOP(iand, and);
    BINOP(ior, or);
index c86463f..191396d 100644 (file)
@@ -148,6 +148,13 @@ def funop(name, opcode):
       0x3F | L | (((1 << 14) - 1) << 28), 6, _),
       srcs = 1, is_float = True)
 
+def iunop(name, opcode):
+    assert(opcode < 4)
+    op(name, (0x3E | (opcode << 26),
+              0x7F | L | (((1 << 14) - 1) << 26),
+              6, _),
+       srcs = 1)
+
 # Listing of opcodes
 funop("floor",     0b000000)
 funop("srsqrt",    0b000001)
@@ -163,6 +170,10 @@ funop("ceil",      0b010000)
 funop("trunc",     0b100000)
 funop("roundeven", 0b110000)
 
+iunop("bitrev",    0b01)
+iunop("popcount",  0b10)
+iunop("ffs",       0b11)
+
 op("fadd",
       encoding_16 = (0x26 | L, 0x3F | L, 6, _),
       encoding_32 = (0x2A | L, 0x3F | L, 6, _),