[Mesa-dev] [PATCH 07/13] i965: Make a brw_conditional_mod enum.

Pohjolainen, Topi topi.pohjolainen at intel.com
Wed Jul 2 06:43:06 PDT 2014


On Mon, Jun 30, 2014 at 02:40:38PM -0700, Matt Turner wrote:
> ---
>  src/mesa/drivers/dri/i965/brw_blorp_blit_eu.cpp    |  2 +-
>  src/mesa/drivers/dri/i965/brw_blorp_blit_eu.h      |  7 +++---
>  src/mesa/drivers/dri/i965/brw_defines.h            | 26 ++++++++++++----------
>  src/mesa/drivers/dri/i965/brw_eu.c                 |  2 +-
>  src/mesa/drivers/dri/i965/brw_eu.h                 |  4 ++--
>  src/mesa/drivers/dri/i965/brw_eu_emit.c            |  2 +-
>  src/mesa/drivers/dri/i965/brw_fs.cpp               |  6 +++--
>  src/mesa/drivers/dri/i965/brw_fs.h                 |  9 ++++----
>  .../drivers/dri/i965/brw_fs_copy_propagation.cpp   |  2 +-
>  src/mesa/drivers/dri/i965/brw_fs_fp.cpp            |  4 ++--
>  src/mesa/drivers/dri/i965/brw_fs_visitor.cpp       |  4 ++--
>  src/mesa/drivers/dri/i965/brw_shader.cpp           |  2 +-
>  src/mesa/drivers/dri/i965/brw_shader.h             |  4 ++--
>  src/mesa/drivers/dri/i965/brw_vec4.h               | 10 +++++----
>  .../drivers/dri/i965/brw_vec4_copy_propagation.cpp |  2 +-
>  src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp     |  8 ++++---
>  src/mesa/drivers/dri/i965/brw_vec4_vp.cpp          |  2 +-
>  src/mesa/drivers/dri/i965/gen8_instruction.c       |  1 +
>  18 files changed, 54 insertions(+), 43 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_blorp_blit_eu.cpp b/src/mesa/drivers/dri/i965/brw_blorp_blit_eu.cpp
> index a2e008b..c1676a9 100644
> --- a/src/mesa/drivers/dri/i965/brw_blorp_blit_eu.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_blorp_blit_eu.cpp
> @@ -117,7 +117,7 @@ brw_blorp_eu_emitter::emit_combine(enum opcode combine_opcode,
>  }
>  
>  fs_inst *
> -brw_blorp_eu_emitter::emit_cmp(int op,
> +brw_blorp_eu_emitter::emit_cmp(enum brw_conditional_mod op,
>                                 const struct brw_reg &x,
>                                 const struct brw_reg &y)
>  {
> diff --git a/src/mesa/drivers/dri/i965/brw_blorp_blit_eu.h b/src/mesa/drivers/dri/i965/brw_blorp_blit_eu.h
> index bc927fe..0459a7e 100644
> --- a/src/mesa/drivers/dri/i965/brw_blorp_blit_eu.h
> +++ b/src/mesa/drivers/dri/i965/brw_blorp_blit_eu.h
> @@ -59,7 +59,7 @@ protected:
>  
>     inline void emit_cond_mov(const struct brw_reg &x,
>                               const struct brw_reg &y,
> -                             int op,
> +                             enum brw_conditional_mod op,
>                               const struct brw_reg &dst,
>                               const struct brw_reg &src)
>     {
> @@ -160,7 +160,7 @@ protected:
>        insts.push_tail(new (mem_ctx) fs_inst(BRW_OPCODE_RNDD, dst, src));
>     }
>  
> -   inline void emit_cmp_if(int op,
> +   inline void emit_cmp_if(enum brw_conditional_mod op,
>                             const struct brw_reg &x,
>                             const struct brw_reg &y)
>     {
> @@ -179,7 +179,8 @@ protected:
>     }
>  
>  private:
> -   fs_inst *emit_cmp(int op, const struct brw_reg &x, const struct brw_reg &y);
> +   fs_inst *emit_cmp(enum brw_conditional_mod op, const struct brw_reg &x,
> +                     const struct brw_reg &y);
>  
>     void *mem_ctx;
>     exec_list insts;
> diff --git a/src/mesa/drivers/dri/i965/brw_defines.h b/src/mesa/drivers/dri/i965/brw_defines.h
> index 88d18a3..822156d 100644
> --- a/src/mesa/drivers/dri/i965/brw_defines.h
> +++ b/src/mesa/drivers/dri/i965/brw_defines.h
> @@ -654,18 +654,20 @@ enum brw_compression {
>  #define GEN6_COMPRESSION_1H		0
>  #define GEN6_COMPRESSION_2H		2
>  
> -#define BRW_CONDITIONAL_NONE  0
> -#define BRW_CONDITIONAL_Z     1
> -#define BRW_CONDITIONAL_NZ    2
> -#define BRW_CONDITIONAL_EQ    1	/* Z */
> -#define BRW_CONDITIONAL_NEQ   2	/* NZ */
> -#define BRW_CONDITIONAL_G     3
> -#define BRW_CONDITIONAL_GE    4
> -#define BRW_CONDITIONAL_L     5
> -#define BRW_CONDITIONAL_LE    6
> -#define BRW_CONDITIONAL_R     7
> -#define BRW_CONDITIONAL_O     8
> -#define BRW_CONDITIONAL_U     9
> +enum PACKED brw_conditional_mod {
> +   BRW_CONDITIONAL_NONE = 0,
> +   BRW_CONDITIONAL_Z    = 1,
> +   BRW_CONDITIONAL_NZ   = 2,
> +   BRW_CONDITIONAL_EQ   = 1,	/* Z */
> +   BRW_CONDITIONAL_NEQ  = 2,	/* NZ */

I'm not super happy with enumeration having multiple definitions for the same
value but that is sort of what we had even before this patch. I'm thinking
possible switch-statements later on where one would need to explain that
Z is actually the same as EQ and so on. But as said this problem exists even
with the current logic so your patch is ok.

> +   BRW_CONDITIONAL_G    = 3,
> +   BRW_CONDITIONAL_GE   = 4,
> +   BRW_CONDITIONAL_L    = 5,
> +   BRW_CONDITIONAL_LE   = 6,
> +   BRW_CONDITIONAL_R    = 7,
> +   BRW_CONDITIONAL_O    = 8,
> +   BRW_CONDITIONAL_U    = 9,
> +};
>  
>  #define BRW_DEBUG_NONE        0
>  #define BRW_DEBUG_BREAKPOINT  1
> diff --git a/src/mesa/drivers/dri/i965/brw_eu.c b/src/mesa/drivers/dri/i965/brw_eu.c
> index 6a1e785..f4c7495 100644
> --- a/src/mesa/drivers/dri/i965/brw_eu.c
> +++ b/src/mesa/drivers/dri/i965/brw_eu.c
> @@ -68,7 +68,7 @@ brw_reg_type_letters(unsigned type)
>  /* Returns the corresponding conditional mod for swapping src0 and
>   * src1 in e.g. CMP.
>   */
> -uint32_t
> +enum brw_conditional_mod
>  brw_swap_cmod(uint32_t cmod)
>  {
>     switch (cmod) {
> diff --git a/src/mesa/drivers/dri/i965/brw_eu.h b/src/mesa/drivers/dri/i965/brw_eu.h
> index 59b9232..48ef298 100644
> --- a/src/mesa/drivers/dri/i965/brw_eu.h
> +++ b/src/mesa/drivers/dri/i965/brw_eu.h
> @@ -320,7 +320,7 @@ void brw_shader_time_add(struct brw_compile *p,
>   * channel.
>   */
>  brw_inst *brw_IF(struct brw_compile *p, unsigned execute_size);
> -brw_inst *gen6_IF(struct brw_compile *p, uint32_t conditional,
> +brw_inst *gen6_IF(struct brw_compile *p, enum brw_conditional_mod conditional,
>                    struct brw_reg src0, struct brw_reg src1);
>  
>  void brw_ELSE(struct brw_compile *p);
> @@ -404,7 +404,7 @@ void brw_set_src1(struct brw_compile *p, brw_inst *insn, struct brw_reg reg);
>  
>  void brw_set_uip_jip(struct brw_compile *p);
>  
> -uint32_t brw_swap_cmod(uint32_t cmod);
> +enum brw_conditional_mod brw_swap_cmod(uint32_t cmod);
>  
>  /* brw_eu_compact.c */
>  void brw_init_compaction_tables(struct brw_context *brw);
> diff --git a/src/mesa/drivers/dri/i965/brw_eu_emit.c b/src/mesa/drivers/dri/i965/brw_eu_emit.c
> index 44ae700..cd5bc9f 100644
> --- a/src/mesa/drivers/dri/i965/brw_eu_emit.c
> +++ b/src/mesa/drivers/dri/i965/brw_eu_emit.c
> @@ -1241,7 +1241,7 @@ brw_IF(struct brw_compile *p, unsigned execute_size)
>   * embedded comparison (conditional modifier).  It is not used on gen7.
>   */
>  brw_inst *
> -gen6_IF(struct brw_compile *p, uint32_t conditional,
> +gen6_IF(struct brw_compile *p, enum brw_conditional_mod conditional,
>  	struct brw_reg src0, struct brw_reg src1)
>  {
>     const struct brw_context *brw = p->brw;
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
> index 47b8d86..f56474f 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
> @@ -198,7 +198,8 @@ fs_visitor::IF(uint32_t predicate)
>  
>  /** Gen6 IF with embedded comparison. */
>  fs_inst *
> -fs_visitor::IF(const fs_reg &src0, const fs_reg &src1, uint32_t condition)
> +fs_visitor::IF(const fs_reg &src0, const fs_reg &src1,
> +               enum brw_conditional_mod condition)
>  {
>     assert(brw->gen == 6);
>     fs_inst *inst = new(mem_ctx) fs_inst(BRW_OPCODE_IF,
> @@ -213,7 +214,8 @@ fs_visitor::IF(const fs_reg &src0, const fs_reg &src1, uint32_t condition)
>   * the flag register with the packed 16 bits of the result.
>   */
>  fs_inst *
> -fs_visitor::CMP(fs_reg dst, fs_reg src0, fs_reg src1, uint32_t condition)
> +fs_visitor::CMP(fs_reg dst, fs_reg src0, fs_reg src1,
> +                enum brw_conditional_mod condition)
>  {
>     fs_inst *inst;
>  
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
> index da4d373..bffdb2c 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs.h
> +++ b/src/mesa/drivers/dri/i965/brw_fs.h
> @@ -273,9 +273,10 @@ public:
>     fs_inst *OR(const fs_reg &dst, const fs_reg &src0, const fs_reg &src1);
>     fs_inst *XOR(const fs_reg &dst, const fs_reg &src0, const fs_reg &src1);
>     fs_inst *IF(uint32_t predicate);
> -   fs_inst *IF(const fs_reg &src0, const fs_reg &src1, uint32_t condition);
> +   fs_inst *IF(const fs_reg &src0, const fs_reg &src1,
> +               enum brw_conditional_mod condition);
>     fs_inst *CMP(fs_reg dst, fs_reg src0, fs_reg src1,
> -                uint32_t condition);
> +                enum brw_conditional_mod condition);
>     fs_inst *LRP(const fs_reg &dst, const fs_reg &a, const fs_reg &y,
>                  const fs_reg &x);
>     fs_inst *DEP_RESOLVE_MOV(int grf);
> @@ -385,7 +386,7 @@ public:
>     fs_inst *emit_math(enum opcode op, fs_reg dst, fs_reg src0, fs_reg src1);
>     void emit_lrp(const fs_reg &dst, const fs_reg &x, const fs_reg &y,
>                   const fs_reg &a);
> -   void emit_minmax(uint32_t conditionalmod, const fs_reg &dst,
> +   void emit_minmax(enum brw_conditional_mod conditionalmod, const fs_reg &dst,
>                      const fs_reg &src0, const fs_reg &src1);
>     bool try_emit_saturate(ir_expression *ir);
>     bool try_emit_mad(ir_expression *ir);
> @@ -417,7 +418,7 @@ public:
>     void emit_fp_minmax(const struct prog_instruction *fpi,
>                         fs_reg dst, fs_reg src0, fs_reg src1);
>  
> -   void emit_fp_sop(uint32_t conditional_mod,
> +   void emit_fp_sop(enum brw_conditional_mod conditional_mod,
>                      const struct prog_instruction *fpi,
>                      fs_reg dst, fs_reg src0, fs_reg src1, fs_reg one);
>  
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp b/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp
> index 3452a95..28e59c6 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_copy_propagation.cpp
> @@ -442,7 +442,7 @@ try_constant_propagate(struct brw_context *brw, fs_inst *inst,
>              inst->src[i] = entry->src;
>              progress = true;
>           } else if (i == 0 && inst->src[1].file != IMM) {
> -            uint32_t new_cmod;
> +            enum brw_conditional_mod new_cmod;
>  
>              new_cmod = brw_swap_cmod(inst->conditional_mod);
>              if (new_cmod != ~0u) {
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_fp.cpp b/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
> index 5eaea77..0c5daa7 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_fp.cpp
> @@ -57,7 +57,7 @@ void
>  fs_visitor::emit_fp_minmax(const prog_instruction *fpi,
>                             fs_reg dst, fs_reg src0, fs_reg src1)
>  {
> -   uint32_t conditionalmod;
> +   enum brw_conditional_mod conditionalmod;
>     if (fpi->Opcode == OPCODE_MIN)
>        conditionalmod = BRW_CONDITIONAL_L;
>     else
> @@ -72,7 +72,7 @@ fs_visitor::emit_fp_minmax(const prog_instruction *fpi,
>  }
>  
>  void
> -fs_visitor::emit_fp_sop(uint32_t conditional_mod,
> +fs_visitor::emit_fp_sop(enum brw_conditional_mod conditional_mod,
>                          const struct prog_instruction *fpi,
>                          fs_reg dst, fs_reg src0, fs_reg src1,
>                          fs_reg one)
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> index 6d9c31f..1359f39 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> @@ -251,7 +251,7 @@ fs_visitor::emit_lrp(const fs_reg &dst, const fs_reg &x, const fs_reg &y,
>  }
>  
>  void
> -fs_visitor::emit_minmax(uint32_t conditionalmod, const fs_reg &dst,
> +fs_visitor::emit_minmax(enum brw_conditional_mod conditionalmod, const fs_reg &dst,
>                          const fs_reg &src0, const fs_reg &src1)
>  {
>     fs_inst *inst;
> @@ -2693,7 +2693,7 @@ fs_visitor::emit_color_write(int target, int index, int first_color_mrf)
>     }
>  }
>  
> -static int
> +static enum brw_conditional_mod
>  cond_for_alpha_func(GLenum func)
>  {
>     switch(func) {
> diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
> index 58ebd33..d7e127b 100644
> --- a/src/mesa/drivers/dri/i965/brw_shader.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
> @@ -311,7 +311,7 @@ brw_type_for_base_type(const struct glsl_type *type)
>     return BRW_REGISTER_TYPE_F;
>  }
>  
> -uint32_t
> +enum brw_conditional_mod
>  brw_conditional_for_comparison(unsigned int op)
>  {
>     switch (op) {
> diff --git a/src/mesa/drivers/dri/i965/brw_shader.h b/src/mesa/drivers/dri/i965/brw_shader.h
> index 7205a85..7c84ab4 100644
> --- a/src/mesa/drivers/dri/i965/brw_shader.h
> +++ b/src/mesa/drivers/dri/i965/brw_shader.h
> @@ -118,7 +118,7 @@ public:
>     uint8_t mlen; /**< SEND message length */
>     int8_t base_mrf; /**< First MRF in the SEND message, if mlen is nonzero. */
>     uint8_t target; /**< MRT target. */
> -   uint8_t conditional_mod; /**< BRW_CONDITIONAL_* */
> +   enum brw_conditional_mod conditional_mod; /**< BRW_CONDITIONAL_* */
>  
>     bool force_writemask_all:1;
>     bool no_dd_clear:1;
> @@ -180,6 +180,6 @@ void annotation_finalize(struct annotation_info *annotation, unsigned offset);
>  #endif /* __cplusplus */
>  
>  enum brw_reg_type brw_type_for_base_type(const struct glsl_type *type);
> -uint32_t brw_conditional_for_comparison(unsigned int op);
> +enum brw_conditional_mod brw_conditional_for_comparison(unsigned int op);
>  uint32_t brw_math_function(enum opcode op);
>  const char *brw_instruction_name(enum opcode op);
> diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h
> index 21df552..d61909d 100644
> --- a/src/mesa/drivers/dri/i965/brw_vec4.h
> +++ b/src/mesa/drivers/dri/i965/brw_vec4.h
> @@ -441,8 +441,9 @@ public:
>     vec4_instruction *ASR(const dst_reg &dst, const src_reg &src0,
>                           const src_reg &src1);
>     vec4_instruction *CMP(dst_reg dst, src_reg src0, src_reg src1,
> -			 uint32_t condition);
> -   vec4_instruction *IF(src_reg src0, src_reg src1, uint32_t condition);
> +			 enum brw_conditional_mod condition);
> +   vec4_instruction *IF(src_reg src0, src_reg src1,
> +                        enum brw_conditional_mod condition);
>     vec4_instruction *IF(uint32_t predicate);
>     vec4_instruction *PULL_CONSTANT_LOAD(const dst_reg &dst,
>                                          const src_reg &index);
> @@ -479,14 +480,15 @@ public:
>     /** Walks an exec_list of ir_instruction and sends it through this visitor. */
>     void visit_instructions(const exec_list *list);
>  
> -   void emit_vp_sop(uint32_t condmod, dst_reg dst,
> +   void emit_vp_sop(enum brw_conditional_mod condmod, dst_reg dst,
>                      src_reg src0, src_reg src1, src_reg one);
>  
>     void emit_bool_to_cond_code(ir_rvalue *ir, uint32_t *predicate);
>     void emit_bool_comparison(unsigned int op, dst_reg dst, src_reg src0, src_reg src1);
>     void emit_if_gen6(ir_if *ir);
>  
> -   void emit_minmax(uint32_t condmod, dst_reg dst, src_reg src0, src_reg src1);
> +   void emit_minmax(enum brw_conditional_mod conditionalmod, dst_reg dst,
> +                    src_reg src0, src_reg src1);
>  
>     void emit_lrp(const dst_reg &dst,
>                   const src_reg &x, const src_reg &y, const src_reg &a);
> 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 b6dc07f..2c41d02 100644
> --- a/src/mesa/drivers/dri/i965/brw_vec4_copy_propagation.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_vec4_copy_propagation.cpp
> @@ -162,7 +162,7 @@ try_constant_propagate(struct brw_context *brw, vec4_instruction *inst,
>  	 inst->src[arg] = value;
>  	 return true;
>        } else if (arg == 0 && inst->src[1].file != IMM) {
> -	 uint32_t new_cmod;
> +	 enum brw_conditional_mod new_cmod;
>  
>  	 new_cmod = brw_swap_cmod(inst->conditional_mod);
>  	 if (new_cmod != ~0u) {
> diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
> index 5051d9f..c5f4b5c 100644
> --- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
> @@ -195,7 +195,8 @@ vec4_visitor::IF(uint32_t predicate)
>  
>  /** Gen6 IF with embedded comparison. */
>  vec4_instruction *
> -vec4_visitor::IF(src_reg src0, src_reg src1, uint32_t condition)
> +vec4_visitor::IF(src_reg src0, src_reg src1,
> +                 enum brw_conditional_mod condition)
>  {
>     assert(brw->gen == 6);
>  
> @@ -217,7 +218,8 @@ vec4_visitor::IF(src_reg src0, src_reg src1, uint32_t condition)
>   * the flag register with the packed 16 bits of the result.
>   */
>  vec4_instruction *
> -vec4_visitor::CMP(dst_reg dst, src_reg src0, src_reg src1, uint32_t condition)
> +vec4_visitor::CMP(dst_reg dst, src_reg src0, src_reg src1,
> +                  enum brw_conditional_mod condition)
>  {
>     vec4_instruction *inst;
>  
> @@ -1185,7 +1187,7 @@ vec4_visitor::emit_bool_comparison(unsigned int op,
>  }
>  
>  void
> -vec4_visitor::emit_minmax(uint32_t conditionalmod, dst_reg dst,
> +vec4_visitor::emit_minmax(enum brw_conditional_mod conditionalmod, dst_reg dst,
>                            src_reg src0, src_reg src1)
>  {
>     vec4_instruction *inst;
> diff --git a/src/mesa/drivers/dri/i965/brw_vec4_vp.cpp b/src/mesa/drivers/dri/i965/brw_vec4_vp.cpp
> index b62f809..f9c23ca 100644
> --- a/src/mesa/drivers/dri/i965/brw_vec4_vp.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_vec4_vp.cpp
> @@ -37,7 +37,7 @@ extern "C" {
>  using namespace brw;
>  
>  void
> -vec4_visitor::emit_vp_sop(uint32_t conditional_mod,
> +vec4_visitor::emit_vp_sop(enum brw_conditional_mod conditional_mod,
>                            dst_reg dst, src_reg src0, src_reg src1,
>                            src_reg one)
>  {
> diff --git a/src/mesa/drivers/dri/i965/gen8_instruction.c b/src/mesa/drivers/dri/i965/gen8_instruction.c
> index c9cbab6..47955e1 100644
> --- a/src/mesa/drivers/dri/i965/gen8_instruction.c
> +++ b/src/mesa/drivers/dri/i965/gen8_instruction.c
> @@ -28,6 +28,7 @@
>   * and set various fields.  This is the actual hardware format.
>   */
>  
> +#include "main/compiler.h"
>  #include "brw_defines.h"
>  #include "gen8_instruction.h"
>  
> -- 
> 1.8.3.2
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list