[Mesa-dev] [PATCH v5 10/34] nvir/nir: add nir type helper functions
Karol Herbst
kherbst at redhat.com
Tue Feb 20 21:02:28 UTC 2018
v4: treat imul as unsigned
v5: remove pointless !!
Signed-off-by: Karol Herbst <kherbst at redhat.com>
---
.../drivers/nouveau/codegen/nv50_ir_from_nir.cpp | 117 +++++++++++++++++++++
1 file changed, 117 insertions(+)
diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
index 60036a0fc3..9dd484cabb 100644
--- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
+++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
@@ -47,6 +47,7 @@ class Converter : public ConverterCommon
public:
typedef std::vector<LValue*> LValues;
typedef decltype(nir_ssa_def().index) NirSSADefIdx;
+ typedef decltype(nir_ssa_def().bit_size) NirSSADefBitSize;
typedef std::unordered_map<NirSSADefIdx, LValues> NirDefMap;
Converter(Program *, nir_shader *, nv50_ir_prog_info *);
@@ -65,6 +66,17 @@ public:
uint32_t getIndirect(nir_intrinsic_instr *, uint8_t s, uint8_t c, Value**);
bool run();
+
+ bool isFloatType(nir_alu_type);
+ bool isSignedType(nir_alu_type);
+ bool isResultFloat(nir_op);
+ bool isResultSigned(nir_op);
+ DataType getDType(nir_alu_instr*);
+ DataType getDType(nir_intrinsic_instr*);
+ DataType getDType(nir_op, NirSSADefBitSize);
+ std::vector<DataType> getSTypes(nir_alu_instr*);
+ DataType getSType(nir_src&, bool isFloat, bool isSigned);
+
private:
nir_shader *nir;
@@ -76,6 +88,111 @@ Converter::Converter(Program *prog, nir_shader *nir, nv50_ir_prog_info *info)
: ConverterCommon(prog, info),
nir(nir) {}
+bool
+Converter::isFloatType(nir_alu_type type)
+{
+ return nir_alu_type_get_base_type(type) == nir_type_float;
+}
+
+bool
+Converter::isSignedType(nir_alu_type type)
+{
+ return nir_alu_type_get_base_type(type) == nir_type_int;
+}
+
+bool
+Converter::isResultFloat(nir_op op)
+{
+ const nir_op_info &info = nir_op_infos[op];
+ if (info.output_type != nir_type_invalid)
+ return isFloatType(info.output_type);
+
+ switch (op) {
+ default:
+ ERROR("isResultFloat not implemented for %s\n", nir_op_infos[op].name);
+ assert(false);
+ return true;
+ }
+}
+
+bool
+Converter::isResultSigned(nir_op op)
+{
+ switch (op) {
+ case nir_op_imul:
+ return false;
+ default:
+ const nir_op_info &info = nir_op_infos[op];
+ if (info.output_type != nir_type_invalid)
+ return isSignedType(info.output_type);
+ ERROR("isResultSigned not implemented for %s\n", nir_op_infos[op].name);
+ assert(false);
+ return true;
+ }
+}
+
+DataType
+Converter::getDType(nir_alu_instr *insn)
+{
+ if (insn->dest.dest.is_ssa)
+ return getDType(insn->op, insn->dest.dest.ssa.bit_size);
+ else
+ return getDType(insn->op, insn->dest.dest.reg.reg->bit_size);
+}
+
+DataType
+Converter::getDType(nir_intrinsic_instr *insn)
+{
+ if (insn->dest.is_ssa)
+ return typeOfSize(insn->dest.ssa.bit_size / 8, false, false);
+ else
+ return typeOfSize(insn->dest.reg.reg->bit_size / 8, false, false);
+}
+
+DataType
+Converter::getDType(nir_op op, Converter::NirSSADefBitSize bitSize)
+{
+ DataType ty = typeOfSize(bitSize / 8, isResultFloat(op), isResultSigned(op));
+ if (ty == TYPE_NONE) {
+ ERROR("couldn't get Type for op %s with bitSize %u\n", nir_op_infos[op].name, bitSize);
+ assert(false);
+ }
+ return ty;
+}
+
+std::vector<DataType>
+Converter::getSTypes(nir_alu_instr *insn)
+{
+ const nir_op_info &info = nir_op_infos[insn->op];
+ std::vector<DataType> res(info.num_inputs);
+
+ for (auto i = 0u; i < info.num_inputs; ++i) {
+ if (info.input_types[i] != nir_type_invalid)
+ res[i] = getSType(insn->src[i].src, isFloatType(info.input_types[i]), isSignedType(info.input_types[i]));
+ else switch (insn->op) {
+ default:
+ ERROR("getSType not implemented for %s idx %u\n", info.name, i);
+ assert(false);
+ res[i] = TYPE_NONE;
+ break;
+ }
+ }
+
+ return res;
+}
+
+DataType
+Converter::getSType(nir_src &src, bool isFloat, bool isSigned)
+{
+ NirSSADefBitSize bitSize;
+ if (src.is_ssa)
+ bitSize = src.ssa->bit_size;
+ else
+ bitSize = src.reg.reg->bit_size;
+
+ return typeOfSize(bitSize / 8, isFloat, isSigned);
+}
+
Converter::LValues&
Converter::convert(nir_dest *dest)
{
--
2.14.3
More information about the mesa-dev
mailing list