[Mesa-dev] [PATCH 09/21] i965: Extract is_dword test

Ben Widawsky benjamin.widawsky at intel.com
Mon Dec 22 19:29:19 PST 2014


As it turns out, I have other uses for this tiny convenience function. Simple
extraction for use by others. Matt was right for not liking the macro in the
initial patch.

While doing this, add it to a few easy to spot users of this functionality.

Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
---
 src/mesa/drivers/dri/i965/brw_eu_emit.c             | 21 ++++++---------------
 src/mesa/drivers/dri/i965/brw_fs_generator.cpp      |  3 +--
 src/mesa/drivers/dri/i965/brw_reg.h                 |  6 ++++++
 src/mesa/drivers/dri/i965/brw_vec4.cpp              |  9 ++-------
 .../drivers/dri/i965/brw_vec4_copy_propagation.cpp  |  3 +--
 5 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_eu_emit.c b/src/mesa/drivers/dri/i965/brw_eu_emit.c
index 8f15db9..046e293 100644
--- a/src/mesa/drivers/dri/i965/brw_eu_emit.c
+++ b/src/mesa/drivers/dri/i965/brw_eu_emit.c
@@ -879,9 +879,7 @@ brw_alu3(struct brw_compile *p, unsigned opcode, struct brw_reg dest,
 	  dest.file == BRW_MESSAGE_REGISTER_FILE);
    assert(dest.nr < 128);
    assert(dest.address_mode == BRW_ADDRESS_DIRECT);
-   assert(dest.type == BRW_REGISTER_TYPE_F ||
-          dest.type == BRW_REGISTER_TYPE_D ||
-          dest.type == BRW_REGISTER_TYPE_UD);
+   assert(dest.type == BRW_REGISTER_TYPE_F || type_is_dword(dest.type));
    if (brw->gen == 6) {
       brw_inst_set_3src_dst_reg_file(brw, inst,
                                      dest.file == BRW_MESSAGE_REGISTER_FILE);
@@ -1065,15 +1063,13 @@ brw_ADD(struct brw_compile *p, struct brw_reg dest,
    if (src0.type == BRW_REGISTER_TYPE_F ||
        (src0.file == BRW_IMMEDIATE_VALUE &&
 	src0.type == BRW_REGISTER_TYPE_VF)) {
-      assert(src1.type != BRW_REGISTER_TYPE_UD);
-      assert(src1.type != BRW_REGISTER_TYPE_D);
+      assert(!type_is_dword(src1.type));
    }
 
    if (src1.type == BRW_REGISTER_TYPE_F ||
        (src1.file == BRW_IMMEDIATE_VALUE &&
 	src1.type == BRW_REGISTER_TYPE_VF)) {
-      assert(src0.type != BRW_REGISTER_TYPE_UD);
-      assert(src0.type != BRW_REGISTER_TYPE_D);
+      assert(!type_is_dword(src0.type));
    }
 
    return brw_alu2(p, BRW_OPCODE_ADD, dest, src0, src1);
@@ -1105,25 +1101,20 @@ brw_MUL(struct brw_compile *p, struct brw_reg dest,
         struct brw_reg src0, struct brw_reg src1)
 {
    /* 6.32.38: mul */
-   if (src0.type == BRW_REGISTER_TYPE_D ||
-       src0.type == BRW_REGISTER_TYPE_UD ||
-       src1.type == BRW_REGISTER_TYPE_D ||
-       src1.type == BRW_REGISTER_TYPE_UD) {
+   if (type_is_dword(src0.type) || type_is_dword(src1.type)) {
       assert(dest.type != BRW_REGISTER_TYPE_F);
    }
 
    if (src0.type == BRW_REGISTER_TYPE_F ||
        (src0.file == BRW_IMMEDIATE_VALUE &&
 	src0.type == BRW_REGISTER_TYPE_VF)) {
-      assert(src1.type != BRW_REGISTER_TYPE_UD);
-      assert(src1.type != BRW_REGISTER_TYPE_D);
+      assert(!type_is_dword(src1.type));
    }
 
    if (src1.type == BRW_REGISTER_TYPE_F ||
        (src1.file == BRW_IMMEDIATE_VALUE &&
 	src1.type == BRW_REGISTER_TYPE_VF)) {
-      assert(src0.type != BRW_REGISTER_TYPE_UD);
-      assert(src0.type != BRW_REGISTER_TYPE_D);
+      assert(!type_is_dword(src0.type));
    }
 
    assert(src0.file != BRW_ARCHITECTURE_REGISTER_FILE ||
diff --git a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
index 15854b0..d45a548 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
@@ -1606,8 +1606,7 @@ fs_generator::generate_code(const cfg_t *cfg, int dispatch_width)
          src[0].subnr = 4;
          src[0].type = dst.type;
          src[0] = stride(src[0], 8, 4, 2);
-         assert(dst.type == BRW_REGISTER_TYPE_UD ||
-                dst.type == BRW_REGISTER_TYPE_D);
+         assert(type_is_dword(dst.type));
          brw_MOV(p, dst, src[0]);
          break;
       case BRW_OPCODE_AVG:
diff --git a/src/mesa/drivers/dri/i965/brw_reg.h b/src/mesa/drivers/dri/i965/brw_reg.h
index 76d3248..a76932c 100644
--- a/src/mesa/drivers/dri/i965/brw_reg.h
+++ b/src/mesa/drivers/dri/i965/brw_reg.h
@@ -216,6 +216,12 @@ type_is_signed(unsigned type)
    }
 }
 
+static inline bool
+type_is_dword(unsigned type)
+{
+   return type == BRW_REGISTER_TYPE_UD || type == BRW_REGISTER_TYPE_D;
+}
+
 /**
  * Construct a brw_reg.
  * \param file      one of the BRW_x_REGISTER_FILE values
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp
index 082bb1e..21ab23c 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp
@@ -715,21 +715,16 @@ vec4_visitor::move_push_constants_to_pull_constants()
 bool
 vec4_visitor::is_dep_ctrl_unsafe(const vec4_instruction *inst)
 {
-#define IS_DWORD(reg) \
-   (reg.type == BRW_REGISTER_TYPE_UD || \
-    reg.type == BRW_REGISTER_TYPE_D)
-
    /* "When source or destination datatype is 64b or operation is integer DWord
     * multiply, DepCtrl must not be used."
     * May apply to future SoCs as well.
     */
    if (brw->is_cherryview) {
       if (inst->opcode == BRW_OPCODE_MUL &&
-         IS_DWORD(inst->src[0]) &&
-         IS_DWORD(inst->src[1]))
+         type_is_dword(inst->src[0].type) &&
+         type_is_dword(inst->src[1].type))
          return true;
    }
-#undef IS_DWORD
 
    /*
     * mlen:
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_copy_propagation.cpp b/src/mesa/drivers/dri/i965/brw_vec4_copy_propagation.cpp
index 65564c9..ab4aeb2 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_copy_propagation.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_copy_propagation.cpp
@@ -153,8 +153,7 @@ try_constant_propagate(struct brw_context *brw, vec4_instruction *inst,
 	  */
 	 if ((inst->opcode == BRW_OPCODE_MUL ||
               inst->opcode == BRW_OPCODE_MACH) &&
-	     (inst->src[1].type == BRW_REGISTER_TYPE_D ||
-	      inst->src[1].type == BRW_REGISTER_TYPE_UD))
+              type_is_dword(inst->src[1].type))
 	    break;
 	 inst->src[0] = inst->src[1];
 	 inst->src[1] = value;
-- 
2.2.1



More information about the mesa-dev mailing list