Mesa (master): gallivm: Use a more compact approach for lp_build_broadcast_scalar().
Jose Fonseca
jrfonseca at kemper.freedesktop.org
Wed May 12 19:50:28 UTC 2010
Module: Mesa
Branch: master
Commit: a09e46c72461183c879d8472b44fe740ecc79b9f
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=a09e46c72461183c879d8472b44fe740ecc79b9f
Author: José Fonseca <jfonseca at vmware.com>
Date: Sun May 9 22:31:18 2010 +0100
gallivm: Use a more compact approach for lp_build_broadcast_scalar().
It produces exactly the same machine code, but it cuts 5% of the
number of instructions generated for a typical shader.
Also, preserve the scalar when length is 1.
---
src/gallium/auxiliary/gallivm/lp_bld_swizzle.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c
index 6a3c8f3..f095a39 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c
@@ -68,18 +68,20 @@ lp_build_broadcast_scalar(struct lp_build_context *bld,
LLVMValueRef scalar)
{
const struct lp_type type = bld->type;
- LLVMValueRef res;
- unsigned i;
assert(lp_check_elem_type(type, LLVMTypeOf(scalar)));
- res = bld->undef;
- for(i = 0; i < type.length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
- res = LLVMBuildInsertElement(bld->builder, res, scalar, index, "");
+ if (type.length == 1) {
+ return scalar;
+ }
+ else {
+ LLVMValueRef res;
+ res = LLVMBuildInsertElement(bld->builder, bld->undef, scalar,
+ LLVMConstInt(LLVMInt32Type(), 0, 0), "");
+ res = LLVMBuildShuffleVector(bld->builder, res, bld->undef,
+ lp_build_const_int_vec(type, 0), "");
+ return res;
}
-
- return res;
}
More information about the mesa-commit
mailing list