From 67ca56d7add2ad3daf5d576452cb21434f865ce5 Mon Sep 17 00:00:00 2001 From: Romaric Jodin Date: Thu, 22 May 2025 13:17:42 +0200 Subject: [PATCH] panfrost: bi_builder.h.py: stop generating unneeded parentheses Generate typecheck condition later to be able to know whether extra parentheses are needed. Reviewed-by: Boris Brezillon Part-of: --- src/panfrost/compiler/bi_builder.h.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/panfrost/compiler/bi_builder.h.py b/src/panfrost/compiler/bi_builder.h.py index 87cf657c5f8..08e382d9a82 100644 --- a/src/panfrost/compiler/bi_builder.h.py +++ b/src/panfrost/compiler/bi_builder.h.py @@ -62,16 +62,9 @@ def nirtypes(opcode): def condition(opcode, typecheck, sizecheck): cond = '' - if typecheck == True: - cond += '(' - types = nirtypes(opcode) - assert types != None - for T in types: - cond += "{}type == {}".format(' || ' if cond[-1] != '(' else '', T) - cond += ')' if sizecheck == True: - cond += "{}bitsize == {}".format(' && ' if cond != '' else '', typesize(opcode)) + cond += "bitsize == {}".format(typesize(opcode)) cmpf_mods = ops[opcode]["modifiers"]["cmpf"] if "cmpf" in ops[opcode]["modifiers"] else None if "cmpf" in ops[opcode]["modifiers"]: @@ -81,6 +74,14 @@ def condition(opcode, typecheck, sizecheck): cond += "{}cmpf == BI_CMPF_{}".format(' || ' if cond[-1] != '(' else '', cmpf.upper()) cond += ')' + if typecheck == True: + types = nirtypes(opcode) + assert types != None + typecheck_cond = ' || '.join(map(lambda T: "type == {}".format(T), types)) + if cond != '': + typecheck_cond = '(' + typecheck_cond + ') && ' + cond = typecheck_cond + cond + return 'true' if cond == '' else cond def to_suffix(op):