[Mesa-dev] [PATCH 10/28] nir/builder: Generate the alu helpers directly in python

Jason Ekstrand jason at jlekstrand.net
Tue May 10 23:16:30 UTC 2016


There's no reason for having a macro *and* a python generator.  We can
easily just do the whole thing in python.  This has the advantage that we
are no longer definining ALU# macros which conflict with the ones in
brw_fs_builder.h.
---
 src/compiler/nir/nir_builder.h            | 30 ------------------------------
 src/compiler/nir/nir_builder_opcodes_h.py | 14 +++++++++++++-
 2 files changed, 13 insertions(+), 31 deletions(-)

diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 4fa9779..756188f 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -233,36 +233,6 @@ nir_build_alu(nir_builder *build, nir_op op, nir_ssa_def *src0,
    return &instr->dest.dest.ssa;
 }
 
-#define ALU1(op)                                                          \
-static inline nir_ssa_def *                                               \
-nir_##op(nir_builder *build, nir_ssa_def *src0)                           \
-{                                                                         \
-   return nir_build_alu(build, nir_op_##op, src0, NULL, NULL, NULL);      \
-}
-
-#define ALU2(op)                                                          \
-static inline nir_ssa_def *                                               \
-nir_##op(nir_builder *build, nir_ssa_def *src0, nir_ssa_def *src1)        \
-{                                                                         \
-   return nir_build_alu(build, nir_op_##op, src0, src1, NULL, NULL);      \
-}
-
-#define ALU3(op)                                                          \
-static inline nir_ssa_def *                                               \
-nir_##op(nir_builder *build, nir_ssa_def *src0,                           \
-         nir_ssa_def *src1, nir_ssa_def *src2)                            \
-{                                                                         \
-   return nir_build_alu(build, nir_op_##op, src0, src1, src2, NULL);      \
-}
-
-#define ALU4(op)                                                          \
-static inline nir_ssa_def *                                               \
-nir_##op(nir_builder *build, nir_ssa_def *src0,                           \
-         nir_ssa_def *src1, nir_ssa_def *src2, nir_ssa_def *src3)         \
-{                                                                         \
-   return nir_build_alu(build, nir_op_##op, src0, src1, src2, src3);      \
-}
-
 #include "nir_builder_opcodes.h"
 
 static inline nir_ssa_def *
diff --git a/src/compiler/nir/nir_builder_opcodes_h.py b/src/compiler/nir/nir_builder_opcodes_h.py
index 038e2b4..42eb6e0 100644
--- a/src/compiler/nir/nir_builder_opcodes_h.py
+++ b/src/compiler/nir/nir_builder_opcodes_h.py
@@ -26,8 +26,20 @@ template = """\
 #ifndef _NIR_BUILDER_OPCODES_
 #define _NIR_BUILDER_OPCODES_
 
+<%
+def src_decl_list(num_srcs):
+   return ', '.join('nir_ssa_def *src' + str(i) for i in range(num_srcs))
+
+def src_list(num_srcs):
+   return ', '.join('src' + str(i) if i < num_srcs else 'NULL' for i in range(4))
+%>
+
 % for name, opcode in sorted(opcodes.iteritems()):
-ALU${opcode.num_inputs}(${name})
+static inline nir_ssa_def *
+nir_${name}(nir_builder *build, ${src_decl_list(opcode.num_inputs)})
+{
+   return nir_build_alu(build, nir_op_${name}, ${src_list(opcode.num_inputs)});
+}
 % endfor
 
 #endif /* _NIR_BUILDER_OPCODES_ */"""
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list