From 952d188c3c8ab90bd2919b88457c81b491fcc3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 2 Jun 2010 16:00:40 +0100 Subject: [PATCH] gallivm: Add a lp_build_const_elem(). --- src/gallium/auxiliary/gallivm/lp_bld_const.c | 53 ++++++++++++-------- src/gallium/auxiliary/gallivm/lp_bld_const.h | 4 ++ 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.c b/src/gallium/auxiliary/gallivm/lp_bld_const.c index 031ce9d1a37..e42ff31ac7a 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_const.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.c @@ -279,6 +279,29 @@ lp_build_one(struct lp_type type) } +/** + * Build constant-valued element from a scalar value. + */ +LLVMValueRef +lp_build_const_elem(struct lp_type type, + double val) +{ + LLVMTypeRef elem_type = lp_build_elem_type(type); + LLVMValueRef elem; + + if(type.floating) { + elem = LLVMConstReal(elem_type, val); + } + else { + double dscale = lp_const_scale(type); + + elem = LLVMConstInt(elem_type, val*dscale + 0.5, 0); + } + + return elem; +} + + /** * Build constant-valued vector from a scalar value. */ @@ -286,28 +309,16 @@ LLVMValueRef lp_build_const_vec(struct lp_type type, double val) { - LLVMTypeRef elem_type = lp_build_elem_type(type); - LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; - unsigned i; - - assert(type.length <= LP_MAX_VECTOR_LENGTH); - - if(type.floating) { - elems[0] = LLVMConstReal(elem_type, val); + if (type.length == 1) { + return lp_build_const_elem(type, val); + } else { + LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; + unsigned i; + elems[0] = lp_build_const_elem(type, val); + for(i = 1; i < type.length; ++i) + elems[i] = elems[0]; + return LLVMConstVector(elems, type.length); } - else { - double dscale = lp_const_scale(type); - - elems[0] = LLVMConstInt(elem_type, val*dscale + 0.5, 0); - } - - if (type.length == 1) - return elems[0]; - - for(i = 1; i < type.length; ++i) - elems[i] = elems[0]; - - return LLVMConstVector(elems, type.length); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h index 9ca2f0664eb..d46b9f882b0 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_const.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h @@ -84,6 +84,10 @@ LLVMValueRef lp_build_one(struct lp_type type); +LLVMValueRef +lp_build_const_elem(struct lp_type type, + double val); + LLVMValueRef lp_build_const_vec(struct lp_type type, double val);