[Mesa-dev] Fixup: Use C++ style constant member functions for is_one and is_zero.
Kenneth Graunke
kenneth at whitecape.org
Fri Sep 9 14:41:45 PDT 2011
static bool src_reg_is_zero(src_reg *reg) is very C.
A first improvement would be:
static bool src_reg_is_zero(const src_reg ®)
as this (1) still avoids copying the struct in, (2) actually guarantees
the register won't be modified, and (3) doesn't require you to explicitly
use the & operator to get a pointer.
A second improvement is just moving to a const member function:
bool src_reg::is_zero()
This allows use in other files (which could come in handy) and takes
less typing (no "src_reg") to call.
---
src/mesa/drivers/dri/i965/brw_vec4.cpp | 30 +++++++++++++++---------------
src/mesa/drivers/dri/i965/brw_vec4.h | 2 ++
2 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp
index 5fd4756..699a3c3 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp
@@ -306,29 +306,29 @@ vec4_visitor::pack_uniform_registers()
}
}
-static bool
-src_reg_is_zero(src_reg *reg)
+bool
+src_reg::is_zero() const
{
- if (reg->file != IMM)
+ if (file != IMM)
return false;
- if (reg->type == BRW_REGISTER_TYPE_F) {
- return reg->imm.f == 0.0;
+ if (type == BRW_REGISTER_TYPE_F) {
+ return imm.f == 0.0;
} else {
- return reg->imm.i == 0;
+ return imm.i == 0;
}
}
-static bool
-src_reg_is_one(src_reg *reg)
+bool
+src_reg::is_one() const
{
- if (reg->file != IMM)
+ if (file != IMM)
return false;
- if (reg->type == BRW_REGISTER_TYPE_F) {
- return reg->imm.f == 1.0;
+ if (type == BRW_REGISTER_TYPE_F) {
+ return imm.f == 1.0;
} else {
- return reg->imm.i == 1;
+ return imm.i == 1;
}
}
@@ -354,7 +354,7 @@ vec4_visitor::opt_algebraic()
switch (inst->opcode) {
case BRW_OPCODE_ADD:
- if (src_reg_is_zero(&inst->src[1])) {
+ if (inst->src[1].is_zero()) {
inst->opcode = BRW_OPCODE_MOV;
inst->src[1] = src_reg();
progress = true;
@@ -362,7 +362,7 @@ vec4_visitor::opt_algebraic()
break;
case BRW_OPCODE_MUL:
- if (src_reg_is_zero(&inst->src[1])) {
+ if (inst->src[1].is_zero()) {
inst->opcode = BRW_OPCODE_MOV;
switch (inst->src[0].type) {
case BRW_REGISTER_TYPE_F:
@@ -381,7 +381,7 @@ vec4_visitor::opt_algebraic()
}
inst->src[1] = src_reg();
progress = true;
- } else if (src_reg_is_one(&inst->src[1])) {
+ } else if (inst->src[1].is_one()) {
inst->opcode = BRW_OPCODE_MOV;
inst->src[1] = src_reg();
}
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h
index 3f116ee..058615f 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -163,6 +163,8 @@ public:
}
bool equals(src_reg *r);
+ bool is_zero() const;
+ bool is_one() const;
src_reg(class vec4_visitor *v, const struct glsl_type *type);
--
1.7.6.1
More information about the mesa-dev
mailing list