Mesa (master): gallivm: avoid unnecessary URem in linear wrap repeat case

Roland Scheidegger sroland at kemper.freedesktop.org
Fri Oct 8 22:37:05 UTC 2010


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

Author: Roland Scheidegger <sroland at vmware.com>
Date:   Fri Oct  8 21:08:49 2010 +0200

gallivm: avoid unnecessary URem in linear wrap repeat case

Haven't looked at what code this exactly generates but URem can't be fast.
Instead of using two URem only use one and replace the second one with
select/add (this is what the corresponding aos code already does).

---

 src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
index 242e8d3..b020782 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
@@ -251,19 +251,23 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
       coord = lp_build_sub(coord_bld, coord, half);
       /* convert to int, compute lerp weight */
       lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight);
-      coord1 = lp_build_add(uint_coord_bld, coord0, uint_coord_bld->one);
       /* repeat wrap */
       if (is_pot) {
+         coord1 = lp_build_add(uint_coord_bld, coord0, uint_coord_bld->one);
          coord0 = LLVMBuildAnd(bld->builder, coord0, length_minus_one, "");
          coord1 = LLVMBuildAnd(bld->builder, coord1, length_minus_one, "");
       }
       else {
          /* Add a bias to the texcoord to handle negative coords */
          LLVMValueRef bias = lp_build_mul_imm(uint_coord_bld, length, 1024);
+         LLVMValueRef mask;
          coord0 = LLVMBuildAdd(bld->builder, coord0, bias, "");
-         coord1 = LLVMBuildAdd(bld->builder, coord1, bias, "");
          coord0 = LLVMBuildURem(bld->builder, coord0, length, "");
-         coord1 = LLVMBuildURem(bld->builder, coord1, length, "");
+         mask = lp_build_compare(bld->builder, int_coord_bld->type,
+                                 PIPE_FUNC_NOTEQUAL, coord0, length_minus_one);
+         coord1 = LLVMBuildAnd(bld->builder,
+                              lp_build_add(uint_coord_bld, coord0, uint_coord_bld->one),
+                              mask, "");
       }
       break;
 




More information about the mesa-commit mailing list