Mesa (master): ra: Use a bitset for storing which registers belong to a class.

Kenneth Graunke kwg at kemper.freedesktop.org
Tue Mar 18 17:36:10 UTC 2014


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

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Fri Feb 21 19:50:15 2014 -0800

ra: Use a bitset for storing which registers belong to a class.

This should use 1/8 the memory.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Matt Turner <mattst88 at gmail.com>
Reviewed-by: Brian Paul <brianp at vmware.com>
Reviewed-by: Christoph Brill <egore911 at gmail.com>

---

 src/mesa/program/register_allocate.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/mesa/program/register_allocate.c b/src/mesa/program/register_allocate.c
index c763b96..d5b4423 100644
--- a/src/mesa/program/register_allocate.c
+++ b/src/mesa/program/register_allocate.c
@@ -99,7 +99,12 @@ struct ra_regs {
 };
 
 struct ra_class {
-   bool *regs;
+   /**
+    * Bitset indicating which registers belong to this class.
+    *
+    * (If bit N is set, then register N belongs to this class.)
+    */
+   BITSET_WORD *regs;
 
    /**
     * p(B) in Runeson/Nyström paper.
@@ -269,7 +274,7 @@ ra_alloc_reg_class(struct ra_regs *regs)
    class = rzalloc(regs, struct ra_class);
    regs->classes[regs->class_count] = class;
 
-   class->regs = rzalloc_array(class, bool, regs->count);
+   class->regs = rzalloc_array(class, BITSET_WORD, BITSET_WORDS(regs->count));
 
    return regs->class_count++;
 }
@@ -279,7 +284,7 @@ ra_class_add_reg(struct ra_regs *regs, unsigned int c, unsigned int r)
 {
    struct ra_class *class = regs->classes[c];
 
-   class->regs[r] = true;
+   BITSET_SET(class->regs, r);
    class->p++;
 }
 
@@ -289,7 +294,7 @@ ra_class_add_reg(struct ra_regs *regs, unsigned int c, unsigned int r)
 static bool
 reg_belongs_to_class(unsigned int r, struct ra_class *c)
 {
-   return c->regs[r];
+   return BITSET_TEST(c->regs, r);
 }
 
 /**
@@ -333,7 +338,7 @@ ra_set_finalize(struct ra_regs *regs, unsigned int **q_values)
 
 	    for (i = 0; i < regs->regs[rc].num_conflicts; i++) {
 	       unsigned int rb = regs->regs[rc].conflict_list[i];
-	       if (regs->classes[b]->regs[rb])
+	       if (BITSET_TEST(regs->classes[b]->regs, rb))
 		  conflicts++;
 	    }
 	    max_conflicts = MAX2(max_conflicts, conflicts);




More information about the mesa-commit mailing list