diff options
Diffstat (limited to 'src/gallium/auxiliary/gallivm/lp_bld_swizzle.c')
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_swizzle.c | 92 |
1 files changed, 49 insertions, 43 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c index 4685a90e41..71693603c1 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c @@ -37,12 +37,13 @@ #include "lp_bld_type.h" #include "lp_bld_const.h" +#include "lp_bld_init.h" #include "lp_bld_logic.h" #include "lp_bld_swizzle.h" LLVMValueRef -lp_build_broadcast(LLVMBuilderRef builder, +lp_build_broadcast(struct gallivm_state *gallivm, LLVMTypeRef vec_type, LLVMValueRef scalar) { @@ -52,8 +53,8 @@ lp_build_broadcast(LLVMBuilderRef builder, res = LLVMGetUndef(vec_type); for(i = 0; i < n; ++i) { - LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0); - res = LLVMBuildInsertElement(builder, res, scalar, index, ""); + LLVMValueRef index = lp_build_const_int32(gallivm, i); + res = LLVMBuildInsertElement(gallivm->builder, res, scalar, index, ""); } return res; @@ -67,6 +68,7 @@ LLVMValueRef lp_build_broadcast_scalar(struct lp_build_context *bld, LLVMValueRef scalar) { + LLVMBuilderRef builder = bld->gallivm->builder; const struct lp_type type = bld->type; assert(lp_check_elem_type(type, LLVMTypeOf(scalar))); @@ -82,17 +84,17 @@ lp_build_broadcast_scalar(struct lp_build_context *bld, struct lp_type i32_vec_type = lp_type_int_vec(32); i32_vec_type.length = type.length; - res = LLVMBuildInsertElement(bld->builder, bld->undef, scalar, - LLVMConstInt(LLVMInt32Type(), 0, 0), ""); - res = LLVMBuildShuffleVector(bld->builder, res, bld->undef, - lp_build_const_int_vec(i32_vec_type, 0), ""); + res = LLVMBuildInsertElement(builder, bld->undef, scalar, + lp_build_const_int32(bld->gallivm, 0), ""); + res = LLVMBuildShuffleVector(builder, res, bld->undef, + lp_build_const_int_vec(bld->gallivm, i32_vec_type, 0), ""); #else /* XXX: The above path provokes a bug in LLVM 2.6 */ unsigned i; res = bld->undef; for(i = 0; i < type.length; ++i) { - LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0); - res = LLVMBuildInsertElement(bld->builder, res, scalar, index, ""); + LLVMValueRef index = lp_build_const_int32(bld->gallivm, i); + res = LLVMBuildInsertElement(builder, res, scalar, index, ""); } #endif return res; @@ -104,13 +106,13 @@ lp_build_broadcast_scalar(struct lp_build_context *bld, * Combined extract and broadcast (or a mere shuffle when the two types match) */ LLVMValueRef -lp_build_extract_broadcast(LLVMBuilderRef builder, +lp_build_extract_broadcast(struct gallivm_state *gallivm, struct lp_type src_type, struct lp_type dst_type, LLVMValueRef vector, LLVMValueRef index) { - LLVMTypeRef i32t = LLVMInt32Type(); + LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context); LLVMValueRef res; assert(src_type.floating == dst_type.floating); @@ -132,8 +134,8 @@ lp_build_extract_broadcast(LLVMBuilderRef builder, * Broadcast scalar -> vector. */ - res = lp_build_broadcast(builder, - lp_build_vec_type(dst_type), + res = lp_build_broadcast(gallivm, + lp_build_vec_type(gallivm, dst_type), vector); } } @@ -144,16 +146,16 @@ lp_build_extract_broadcast(LLVMBuilderRef builder, */ LLVMValueRef shuffle; - shuffle = lp_build_broadcast(builder, + shuffle = lp_build_broadcast(gallivm, LLVMVectorType(i32t, dst_type.length), index); - res = LLVMBuildShuffleVector(builder, vector, - LLVMGetUndef(lp_build_vec_type(dst_type)), + res = LLVMBuildShuffleVector(gallivm->builder, vector, + LLVMGetUndef(lp_build_vec_type(gallivm, dst_type)), shuffle, ""); } else { LLVMValueRef scalar; - scalar = LLVMBuildExtractElement(builder, vector, index, ""); + scalar = LLVMBuildExtractElement(gallivm->builder, vector, index, ""); if (dst_type.length == 1) { /* * Trivial extract scalar from vector. @@ -166,8 +168,8 @@ lp_build_extract_broadcast(LLVMBuilderRef builder, * General case of different sized vectors. */ - res = lp_build_broadcast(builder, - lp_build_vec_type(dst_type), + res = lp_build_broadcast(gallivm, + lp_build_vec_type(gallivm, dst_type), vector); } } @@ -185,6 +187,7 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld, LLVMValueRef a, unsigned channel) { + LLVMBuilderRef builder = bld->gallivm->builder; const struct lp_type type = bld->type; const unsigned n = type.length; unsigned i, j; @@ -199,14 +202,14 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld, /* * Shuffle. */ - LLVMTypeRef elem_type = LLVMInt32Type(); + LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context); LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH]; for(j = 0; j < n; j += 4) for(i = 0; i < 4; ++i) shuffles[j + i] = LLVMConstInt(elem_type, j + channel, 0); - return LLVMBuildShuffleVector(bld->builder, a, bld->undef, LLVMConstVector(shuffles, n), ""); + return LLVMBuildShuffleVector(builder, a, bld->undef, LLVMConstVector(shuffles, n), ""); } else { /* @@ -226,8 +229,9 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld, }; unsigned i; - a = LLVMBuildAnd(bld->builder, a, - lp_build_const_mask_aos(type, 1 << channel), ""); + a = LLVMBuildAnd(builder, a, + lp_build_const_mask_aos(bld->gallivm, + type, 1 << channel), ""); /* * Build a type where each element is an integer that cover the four @@ -239,7 +243,7 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld, type4.width *= 4; type4.length /= 4; - a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type4), ""); + a = LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type4), ""); for(i = 0; i < 2; ++i) { LLVMValueRef tmp = NULL; @@ -250,16 +254,16 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld, #endif if(shift > 0) - tmp = LLVMBuildLShr(bld->builder, a, lp_build_const_int_vec(type4, shift*type.width), ""); + tmp = LLVMBuildLShr(builder, a, lp_build_const_int_vec(bld->gallivm, type4, shift*type.width), ""); if(shift < 0) - tmp = LLVMBuildShl(bld->builder, a, lp_build_const_int_vec(type4, -shift*type.width), ""); + tmp = LLVMBuildShl(builder, a, lp_build_const_int_vec(bld->gallivm, type4, -shift*type.width), ""); assert(tmp); if(tmp) - a = LLVMBuildOr(bld->builder, a, tmp, ""); + a = LLVMBuildOr(builder, a, tmp, ""); } - return LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type), ""); + return LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type), ""); } } @@ -269,6 +273,7 @@ lp_build_swizzle_aos(struct lp_build_context *bld, LLVMValueRef a, const unsigned char swizzles[4]) { + LLVMBuilderRef builder = bld->gallivm->builder; const struct lp_type type = bld->type; const unsigned n = type.length; unsigned i, j; @@ -303,8 +308,8 @@ lp_build_swizzle_aos(struct lp_build_context *bld, /* * Shuffle. */ - LLVMValueRef undef = LLVMGetUndef(lp_build_elem_type(type)); - LLVMTypeRef i32t = LLVMInt32Type(); + LLVMValueRef undef = LLVMGetUndef(lp_build_elem_type(bld->gallivm, type)); + LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context); LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH]; LLVMValueRef aux[LP_MAX_VECTOR_LENGTH]; @@ -326,13 +331,13 @@ lp_build_swizzle_aos(struct lp_build_context *bld, case PIPE_SWIZZLE_ZERO: shuffle = type.length + 0; if (!aux[0]) { - aux[0] = lp_build_const_elem(type, 0.0); + aux[0] = lp_build_const_elem(bld->gallivm, type, 0.0); } break; case PIPE_SWIZZLE_ONE: shuffle = type.length + 1; if (!aux[1]) { - aux[1] = lp_build_const_elem(type, 1.0); + aux[1] = lp_build_const_elem(bld->gallivm, type, 1.0); } break; } @@ -346,7 +351,7 @@ lp_build_swizzle_aos(struct lp_build_context *bld, } } - return LLVMBuildShuffleVector(bld->builder, a, + return LLVMBuildShuffleVector(builder, a, LLVMConstVector(aux, n), LLVMConstVector(shuffles, n), ""); } else { @@ -387,8 +392,8 @@ lp_build_swizzle_aos(struct lp_build_context *bld, type4.width *= 4; type4.length /= 4; - a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type4), ""); - res = LLVMBuildBitCast(bld->builder, res, lp_build_vec_type(type4), ""); + a = LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type4), ""); + res = LLVMBuildBitCast(builder, res, lp_build_vec_type(bld->gallivm, type4), ""); /* * Mask and shift the channels, trying to group as many channels in the @@ -414,23 +419,24 @@ lp_build_swizzle_aos(struct lp_build_context *bld, if (0) debug_printf("shift = %i, mask = 0x%08llx\n", shift, mask); - masked = LLVMBuildAnd(bld->builder, a, - lp_build_const_int_vec(type4, mask), ""); + masked = LLVMBuildAnd(builder, a, + lp_build_const_int_vec(bld->gallivm, type4, mask), ""); if (shift > 0) { - shifted = LLVMBuildShl(bld->builder, masked, - lp_build_const_int_vec(type4, shift*type.width), ""); + shifted = LLVMBuildShl(builder, masked, + lp_build_const_int_vec(bld->gallivm, type4, shift*type.width), ""); } else if (shift < 0) { - shifted = LLVMBuildLShr(bld->builder, masked, - lp_build_const_int_vec(type4, -shift*type.width), ""); + shifted = LLVMBuildLShr(builder, masked, + lp_build_const_int_vec(bld->gallivm, type4, -shift*type.width), ""); } else { shifted = masked; } - res = LLVMBuildOr(bld->builder, res, shifted, ""); + res = LLVMBuildOr(builder, res, shifted, ""); } } - return LLVMBuildBitCast(bld->builder, res, lp_build_vec_type(type), ""); + return LLVMBuildBitCast(builder, res, + lp_build_vec_type(bld->gallivm, type), ""); } } |