diff --git a/src/asahi/compiler/agx_builder.h.py b/src/asahi/compiler/agx_builder.h.py index 24e0dd34186..6638d408c4e 100644 --- a/src/asahi/compiler/agx_builder.h.py +++ b/src/asahi/compiler/agx_builder.h.py @@ -129,6 +129,34 @@ enum agx_bitop_table { AGX_BITOP_OR = 0xE }; +#define BINOP_BITOP(name, table) \ + static inline agx_instr * \ + agx_## name ##_to(agx_builder *b, agx_index dst0, agx_index src0, agx_index src1) \ + { \ + return agx_bitop_to(b, dst0, src0, src1, AGX_BITOP_ ## table); \ + } \ + \ + static inline agx_index \ + agx_## name (agx_builder *b, agx_index src0, agx_index src1) \ + { \ + agx_index tmp = agx_temp(b->shader, src0.size); \ + agx_##name##_to(b, tmp, src0, src1); \ + return tmp; \ + } + +BINOP_BITOP(nor, NOR) +BINOP_BITOP(andn2, ANDN2) +BINOP_BITOP(andn1, ANDN1) +BINOP_BITOP(xor, XOR) +BINOP_BITOP(nand, NAND) +BINOP_BITOP(and, AND) +BINOP_BITOP(xnor, XNOR) +BINOP_BITOP(orn2, ORN2) +BINOP_BITOP(orn1, ORN1) +BINOP_BITOP(or, OR) + +#undef BINOP_BITOP + static inline agx_instr * agx_fmov_to(agx_builder *b, agx_index dst0, agx_index src0) { diff --git a/src/asahi/compiler/agx_lower_pseudo.c b/src/asahi/compiler/agx_lower_pseudo.c index 415457520cb..14004983ff3 100644 --- a/src/asahi/compiler/agx_lower_pseudo.c +++ b/src/asahi/compiler/agx_lower_pseudo.c @@ -56,15 +56,6 @@ lower(agx_builder *b, agx_instr *I) case AGX_OPCODE_NOT: return agx_bitop_to(b, I->dest[0], I->src[0], agx_zero(), AGX_BITOP_NOT); - case AGX_OPCODE_AND: - return agx_bitop_to(b, I->dest[0], I->src[0], I->src[1], AGX_BITOP_AND); - - case AGX_OPCODE_XOR: - return agx_bitop_to(b, I->dest[0], I->src[0], I->src[1], AGX_BITOP_XOR); - - case AGX_OPCODE_OR: - return agx_bitop_to(b, I->dest[0], I->src[0], I->src[1], AGX_BITOP_OR); - /* Unfused comparisons are fused with a 0/1 select */ case AGX_OPCODE_ICMP: return agx_icmpsel_to(b, I->dest[0], I->src[0], I->src[1], diff --git a/src/asahi/compiler/agx_opcodes.py b/src/asahi/compiler/agx_opcodes.py index 0eca8284935..dba1015070a 100644 --- a/src/asahi/compiler/agx_opcodes.py +++ b/src/asahi/compiler/agx_opcodes.py @@ -463,9 +463,6 @@ op("stack_store", # Convenient aliases. op("mov", _, srcs = 1) op("not", _, srcs = 1) -op("xor", _, srcs = 2) -op("and", _, srcs = 2) -op("or", _, srcs = 2) op("collect", _, srcs = VARIABLE) op("split", _, srcs = 1, dests = VARIABLE) diff --git a/src/asahi/compiler/agx_print.c b/src/asahi/compiler/agx_print.c index deac13cea7f..a6690da3525 100644 --- a/src/asahi/compiler/agx_print.c +++ b/src/asahi/compiler/agx_print.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: MIT */ +#include "agx_builder.h" #include "agx_compiler.h" static void @@ -88,11 +89,34 @@ agx_print_index(agx_index index, bool is_float, FILE *fp) fprintf(fp, ".neg"); } +static struct agx_opcode_info +agx_get_opcode_info_for_print(const agx_instr *I) +{ + struct agx_opcode_info info = agx_opcodes_info[I->op]; + + if (I->op == AGX_OPCODE_BITOP) { + const char *bitops[16] = { + [AGX_BITOP_NOR] = "nor", [AGX_BITOP_ANDN2] = "andn2", + [AGX_BITOP_ANDN1] = "andn1", [AGX_BITOP_XOR] = "xor", + [AGX_BITOP_NAND] = "nand", [AGX_BITOP_AND] = "and", + [AGX_BITOP_XNOR] = "xnor", [AGX_BITOP_ORN2] = "orn2", + [AGX_BITOP_ORN1] = "orn1", [AGX_BITOP_OR] = "or", + }; + + if (bitops[I->truth_table] != NULL) { + info.name = bitops[I->truth_table]; + info.immediates &= ~AGX_IMMEDIATE_TRUTH_TABLE; + } + } + + return info; +} + void agx_print_instr(const agx_instr *I, FILE *fp) { assert(I->op < AGX_NUM_OPCODES); - struct agx_opcode_info info = agx_opcodes_info[I->op]; + struct agx_opcode_info info = agx_get_opcode_info_for_print(I); bool print_comma = false; fprintf(fp, " "); diff --git a/src/asahi/compiler/test/test-lower-pseudo.cpp b/src/asahi/compiler/test/test-lower-pseudo.cpp index 5db5443fc09..e55b675a836 100644 --- a/src/asahi/compiler/test/test-lower-pseudo.cpp +++ b/src/asahi/compiler/test/test-lower-pseudo.cpp @@ -40,10 +40,3 @@ TEST_F(LowerPseudo, Not) { CASE(agx_not_to(b, wx, wy), agx_bitop_to(b, wx, wy, agx_zero(), 0x5)); } - -TEST_F(LowerPseudo, BinaryBitwise) -{ - CASE(agx_and_to(b, wx, wy, wz), agx_bitop_to(b, wx, wy, wz, 0x8)); - CASE(agx_xor_to(b, wx, wy, wz), agx_bitop_to(b, wx, wy, wz, 0x6)); - CASE(agx_or_to(b, wx, wy, wz), agx_bitop_to(b, wx, wy, wz, 0xE)); -}