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

Author: José Fonseca <[email protected]>
Date:   Thu Mar 11 15:36:51 2010 +0000

gallivm: Use bitmasks for scalar masks.

We could use single 1 bit conditions for scalar masks, but a lot of code
expects masks. The compiler easily optimzes away masks
extensions/truncations so consistency is preferable.

We can revisit this when LLVM backends have more support for vector
conditions.

---

 src/gallium/auxiliary/gallivm/lp_bld_logic.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.c 
b/src/gallium/auxiliary/gallivm/lp_bld_logic.c
index fa65895..b7eb2c3 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_logic.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.c
@@ -259,11 +259,13 @@ lp_build_compare(LLVMBuilderRef builder,
       cond = LLVMBuildFCmp(builder, op, a, b, "");
       res = LLVMBuildSExt(builder, cond, int_vec_type, "");
 #else
-      res = LLVMGetUndef(int_vec_type);
       if (type.length == 1) {
-         res = LLVMBuildFCmp(builder, op, a, b, "");
+         cond = LLVMBuildFCmp(builder, op, a, b, "");
+         res = LLVMBuildSExt(builder, cond, int_vec_type, "");
       }
       else {
+         res = LLVMGetUndef(int_vec_type);
+
          debug_printf("%s: warning: using slow element-wise float"
                       " vector comparison\n", __FUNCTION__);
          for (i = 0; i < type.length; ++i) {
@@ -311,11 +313,13 @@ lp_build_compare(LLVMBuilderRef builder,
       cond = LLVMBuildICmp(builder, op, a, b, "");
       res = LLVMBuildSExt(builder, cond, int_vec_type, "");
 #else
-      res = LLVMGetUndef(int_vec_type);
       if (type.length == 1) {
-         res = LLVMBuildICmp(builder, op, a, b, "");
+         cond = LLVMBuildICmp(builder, op, a, b, "");
+         res = LLVMBuildSExt(builder, cond, int_vec_type, "");
       }
       else {
+         res = LLVMGetUndef(int_vec_type);
+
          debug_printf("%s: warning: using slow element-wise int"
                       " vector comparison\n", __FUNCTION__);
 
@@ -357,6 +361,8 @@ lp_build_cmp(struct lp_build_context *bld,
 
 /**
  * Return mask ? a : b;
+ *
+ * mask is a bitwise mask, composed of 0 or ~0 for each element.
  */
 LLVMValueRef
 lp_build_select(struct lp_build_context *bld,
@@ -371,6 +377,7 @@ lp_build_select(struct lp_build_context *bld,
       return a;
 
    if (type.length == 1) {
+      mask = LLVMBuildTrunc(bld->builder, mask, LLVMInt1Type(), "");
       res = LLVMBuildSelect(bld->builder, mask, a, b, "");
    }
    else {

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to