X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fauxiliary%2Fgallivm%2Flp_bld_const.c;h=6d8b7c26fc8344f37e588dc9d3133e4bce26fb9e;hb=1dbcb83881f508280ed78dae6834d341936712f2;hp=57843e9a60ce909e230aac77bf284710801c853b;hpb=75b8c4a8f869f63991c774caa7e1cec7e988c5ec;p=mesa.git diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.c b/src/gallium/auxiliary/gallivm/lp_bld_const.c index 57843e9a60c..6d8b7c26fc8 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_const.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.c @@ -39,6 +39,7 @@ #include "lp_bld_type.h" #include "lp_bld_const.h" +#include "lp_bld_init.h" unsigned @@ -211,31 +212,31 @@ lp_const_eps(struct lp_type type) LLVMValueRef -lp_build_undef(struct lp_type type) +lp_build_undef(struct gallivm_state *gallivm, struct lp_type type) { - LLVMTypeRef vec_type = lp_build_vec_type(type); + LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type); return LLVMGetUndef(vec_type); } LLVMValueRef -lp_build_zero(struct lp_type type) +lp_build_zero(struct gallivm_state *gallivm, struct lp_type type) { if (type.length == 1) { if (type.floating) - return LLVMConstReal(LLVMFloatType(), 0.0); + return lp_build_const_float(gallivm, 0.0); else - return LLVMConstInt(LLVMIntType(type.width), 0, 0); + return LLVMConstInt(LLVMIntTypeInContext(gallivm->context, type.width), 0, 0); } else { - LLVMTypeRef vec_type = lp_build_vec_type(type); + LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type); return LLVMConstNull(vec_type); } } LLVMValueRef -lp_build_one(struct lp_type type) +lp_build_one(struct gallivm_state *gallivm, struct lp_type type) { LLVMTypeRef elem_type; LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; @@ -243,7 +244,7 @@ lp_build_one(struct lp_type type) assert(type.length <= LP_MAX_VECTOR_LENGTH); - elem_type = lp_build_elem_type(type); + elem_type = lp_build_elem_type(gallivm, type); if(type.floating) elems[0] = LLVMConstReal(elem_type, 1.0); @@ -280,39 +281,54 @@ lp_build_one(struct lp_type type) /** - * Build constant-valued vector from a scalar value. + * Build constant-valued element from a scalar value. */ LLVMValueRef -lp_build_const_vec(struct lp_type type, - double val) +lp_build_const_elem(struct gallivm_state *gallivm, + 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); + LLVMTypeRef elem_type = lp_build_elem_type(gallivm, type); + LLVMValueRef elem; if(type.floating) { - elems[0] = LLVMConstReal(elem_type, val); + elem = LLVMConstReal(elem_type, val); } else { double dscale = lp_const_scale(type); - elems[0] = LLVMConstInt(elem_type, val*dscale + 0.5, 0); + elem = LLVMConstInt(elem_type, val*dscale + 0.5, 0); } - for(i = 1; i < type.length; ++i) - elems[i] = elems[0]; + return elem; +} - return LLVMConstVector(elems, type.length); + +/** + * Build constant-valued vector from a scalar value. + */ +LLVMValueRef +lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type, + double val) +{ + if (type.length == 1) { + return lp_build_const_elem(gallivm, type, val); + } else { + LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; + unsigned i; + elems[0] = lp_build_const_elem(gallivm, type, val); + for(i = 1; i < type.length; ++i) + elems[i] = elems[0]; + return LLVMConstVector(elems, type.length); + } } LLVMValueRef -lp_build_const_int_vec(struct lp_type type, - long long val) +lp_build_const_int_vec(struct gallivm_state *gallivm, struct lp_type type, + long long val) { - LLVMTypeRef elem_type = lp_build_int_elem_type(type); + LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type); LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; unsigned i; @@ -321,12 +337,16 @@ lp_build_const_int_vec(struct lp_type type, for(i = 0; i < type.length; ++i) elems[i] = LLVMConstInt(elem_type, val, type.sign ? 1 : 0); + if (type.length == 1) + return elems[0]; + return LLVMConstVector(elems, type.length); } LLVMValueRef -lp_build_const_aos(struct lp_type type, +lp_build_const_aos(struct gallivm_state *gallivm, + struct lp_type type, double r, double g, double b, double a, const unsigned char *swizzle) { @@ -338,7 +358,7 @@ lp_build_const_aos(struct lp_type type, assert(type.length % 4 == 0); assert(type.length <= LP_MAX_VECTOR_LENGTH); - elem_type = lp_build_elem_type(type); + elem_type = lp_build_elem_type(gallivm, type); if(swizzle == NULL) swizzle = default_swizzle; @@ -365,19 +385,27 @@ lp_build_const_aos(struct lp_type type, } +/** + * @param mask TGSI_WRITEMASK_xxx + */ LLVMValueRef -lp_build_const_mask_aos(struct lp_type type, - const boolean cond[4]) +lp_build_const_mask_aos(struct gallivm_state *gallivm, + struct lp_type type, + unsigned mask) { - LLVMTypeRef elem_type = LLVMIntType(type.width); + LLVMTypeRef elem_type = LLVMIntTypeInContext(gallivm->context, type.width); LLVMValueRef masks[LP_MAX_VECTOR_LENGTH]; unsigned i, j; assert(type.length <= LP_MAX_VECTOR_LENGTH); - for(j = 0; j < type.length; j += 4) - for(i = 0; i < 4; ++i) - masks[j + i] = LLVMConstInt(elem_type, cond[i] ? ~0 : 0, 0); + for (j = 0; j < type.length; j += 4) { + for( i = 0; i < 4; ++i) { + masks[j + i] = LLVMConstInt(elem_type, + mask & (1 << i) ? ~0ULL : 0, + 1); + } + } return LLVMConstVector(masks, type.length); }