Mesa (master): glsl: Make is_zero and is_one virtual methods of ir_rvalue

Ian Romanick idr at kemper.freedesktop.org
Fri Nov 19 02:21:53 UTC 2010


Module: Mesa
Branch: master
Commit: ad87f2ddc7e6b95e3dd5bbe4d2b19703d305c74e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ad87f2ddc7e6b95e3dd5bbe4d2b19703d305c74e

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Nov 18 17:11:17 2010 -0800

glsl: Make is_zero and is_one virtual methods of ir_rvalue

This eliminates the need in some cames to validate that an rvalue is
an ir_constant before checking to see if it's 0 or 1.

---

 src/glsl/ir.cpp |   10 ++++++++++
 src/glsl/ir.h   |   47 ++++++++++++++++++++++++++---------------------
 2 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 8c5441d..574ef3e 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -31,6 +31,16 @@ ir_rvalue::ir_rvalue()
    this->type = glsl_type::error_type;
 }
 
+bool ir_rvalue::is_zero() const
+{
+   return false;
+}
+
+bool ir_rvalue::is_one() const
+{
+   return false;
+}
+
 /**
  * Modify the swizzle make to move one component to another
  *
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 3fc8349..3ea7301 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -171,6 +171,30 @@ public:
       return NULL;
    }
 
+   /**
+    * Determine if an r-value has the value zero
+    *
+    * The base implementation of this function always returns \c false.  The
+    * \c ir_constant class over-rides this function to return \c true \b only
+    * for vector and scalar types that have all elements set to the value
+    * zero (or \c false for booleans).
+    *
+    * \sa ir_constant::has_value, ir_rvalue::is_one
+    */
+   virtual bool is_zero() const;
+
+   /**
+    * Determine if an r-value has the value one
+    *
+    * The base implementation of this function always returns \c false.  The
+    * \c ir_constant class over-rides this function to return \c true \b only
+    * for vector and scalar types that have all elements set to the value
+    * one (or \c true for booleans).
+    *
+    * \sa ir_constant::has_value, ir_rvalue::is_zero
+    */
+   virtual bool is_one() const;
+
 protected:
    ir_rvalue();
 };
@@ -1460,27 +1484,8 @@ public:
     */
    bool has_value(const ir_constant *) const;
 
-   /**
-    * Determine if a constant has the value zero
-    *
-    * \note
-    * This function always returns \c false for constants that are not
-    * scalars or vectors.
-    *
-    * \sa ir_constant::has_value, ir_constant::is_one
-    */
-   bool is_zero() const;
-
-   /**
-    * Determine if a constant has the value one
-    *
-    * \note
-    * This function always returns \c false for constants that are not
-    * scalars or vectors.
-    *
-    * \sa ir_constant::has_value, ir_constant::is_zero
-    */
-   bool is_one() const;
+   virtual bool is_zero() const;
+   virtual bool is_one() const;
 
    /**
     * Value of the constant.




More information about the mesa-commit mailing list