From 5bd417228020a670e73fc8bf43e9595d1118d085 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 1 May 2020 20:58:45 -0400 Subject: [PATCH] pan/bi: Pack ADD ICMP 32 Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bi_pack.c | 67 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/src/panfrost/bifrost/bi_pack.c b/src/panfrost/bifrost/bi_pack.c index c92bd4e..28ba283 100644 --- a/src/panfrost/bifrost/bi_pack.c +++ b/src/panfrost/bifrost/bi_pack.c @@ -1526,6 +1526,70 @@ bi_pack_add_discard(bi_instruction *ins, struct bi_registers *regs) RETURN_PACKED(pack); } +static enum bifrost_icmp_cond +bi_cond_to_icmp(enum bi_cond cond, bool *flip, bool is_unsigned) +{ + switch (cond){ + case BI_COND_LT: + *flip = true; + /* fallthrough */ + case BI_COND_GT: + return is_unsigned ? BIFROST_ICMP_UGT : BIFROST_ICMP_IGT; + case BI_COND_LE: + *flip = true; + /* fallthrough */ + case BI_COND_GE: + return is_unsigned ? BIFROST_ICMP_UGE : BIFROST_ICMP_IGE; + case BI_COND_NE: + return BIFROST_ICMP_NEQ; + case BI_COND_EQ: + return BIFROST_ICMP_EQ; + default: + unreachable("Invalid op for icmp"); + } +} + +static unsigned +bi_pack_add_icmp32(bi_instruction *ins, struct bi_registers *regs, bool flip, + enum bifrost_icmp_cond cond) +{ + struct bifrost_add_icmp pack = { + .src0 = bi_get_src(ins, regs, flip ? 1 : 0, true), + .src1 = bi_get_src(ins, regs, flip ? 0 : 1, true), + .cond = cond, + .sz = 1, + .d3d = false, + .op = BIFROST_ADD_OP_ICMP_32 + }; + + RETURN_PACKED(pack); +} + +static unsigned +bi_pack_add_cmp(bi_instruction *ins, struct bi_registers *regs) +{ + nir_alu_type Tl = ins->src_types[0]; + nir_alu_type Tr = ins->src_types[1]; + nir_alu_type Bl = nir_alu_type_get_base_type(Tl); + + if (Bl == nir_type_uint || Bl == nir_type_int) { + assert(Tl == Tr); + unsigned sz = nir_alu_type_get_type_size(Tl); + + bool flip = false; + + enum bifrost_icmp_cond cond = + bi_cond_to_icmp(ins->cond, &flip, Bl == nir_type_uint); + + if (sz == 32) + return bi_pack_add_icmp32(ins, regs, flip, cond); + else + unreachable("TODO"); + } else { + unreachable("TODO"); + } +} + static unsigned bi_pack_add(bi_clause *clause, bi_bundle bundle, struct bi_registers *regs) { @@ -1538,8 +1602,9 @@ bi_pack_add(bi_clause *clause, bi_bundle bundle, struct bi_registers *regs) case BI_ATEST: return bi_pack_add_atest(clause, bundle.add, regs); case BI_BRANCH: - case BI_CMP: unreachable("Packing todo"); + case BI_CMP: + return bi_pack_add_cmp(bundle.add, regs); case BI_BLEND: return bi_pack_add_blend(clause, bundle.add, regs); case BI_BITWISE: -- 2.7.4