From 7d230dae70e8caa67cc6bd7501f892d44c40a5d4 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 4 Mar 2010 08:36:26 -0700 Subject: gallivm: added lp_build_negate() --- src/gallium/auxiliary/gallivm/lp_bld_arit.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/gallium/auxiliary/gallivm/lp_bld_arit.h') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.h b/src/gallium/auxiliary/gallivm/lp_bld_arit.h index da84b7ca02..2d19ec06b4 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.h @@ -116,6 +116,10 @@ LLVMValueRef lp_build_abs(struct lp_build_context *bld, LLVMValueRef a); +LLVMValueRef +lp_build_negate(struct lp_build_context *bld, + LLVMValueRef a); + LLVMValueRef lp_build_sgn(struct lp_build_context *bld, LLVMValueRef a); -- cgit v1.2.3 From 6464d81e779e8c05ef96c9e5dab4422ff1f25464 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 4 Mar 2010 09:45:34 -0700 Subject: gallivm: added lp_build_set_sign() --- src/gallium/auxiliary/gallivm/lp_bld_arit.c | 35 +++++++++++++++++++++++++++++ src/gallium/auxiliary/gallivm/lp_bld_arit.h | 4 ++++ 2 files changed, 39 insertions(+) (limited to 'src/gallium/auxiliary/gallivm/lp_bld_arit.h') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c index f60a7a213a..42ae9f6a22 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c @@ -717,6 +717,41 @@ lp_build_sgn(struct lp_build_context *bld, } +/** + * Set the sign of float vector 'a' according to 'sign'. + * If sign==0, return abs(a). + * If sign==1, return -abs(a); + * Other values for sign produce undefined results. + */ +LLVMValueRef +lp_build_set_sign(struct lp_build_context *bld, + LLVMValueRef a, LLVMValueRef sign) +{ + const struct lp_type type = bld->type; + LLVMTypeRef int_vec_type = lp_build_int_vec_type(type); + LLVMTypeRef vec_type = lp_build_vec_type(type); + LLVMValueRef shift = lp_build_int_const_scalar(type, type.width - 1); + LLVMValueRef mask = lp_build_int_const_scalar(type, + ~((unsigned long long) 1 << (type.width - 1))); + LLVMValueRef val, res; + + assert(type.floating); + + /* val = reinterpret_cast(a) */ + val = LLVMBuildBitCast(bld->builder, a, int_vec_type, ""); + /* val = val & mask */ + val = LLVMBuildAnd(bld->builder, val, mask, ""); + /* sign = sign << shift */ + sign = LLVMBuildShl(bld->builder, sign, shift, ""); + /* res = val | sign */ + res = LLVMBuildOr(bld->builder, val, sign, ""); + /* res = reinterpret_cast(res) */ + res = LLVMBuildBitCast(bld->builder, res, vec_type, ""); + + return res; +} + + /** * Convert vector of int to vector of float. */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.h b/src/gallium/auxiliary/gallivm/lp_bld_arit.h index 2d19ec06b4..866349d8cb 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.h @@ -124,6 +124,10 @@ LLVMValueRef lp_build_sgn(struct lp_build_context *bld, LLVMValueRef a); +LLVMValueRef +lp_build_set_sign(struct lp_build_context *bld, + LLVMValueRef a, LLVMValueRef sign); + LLVMValueRef lp_build_int_to_float(struct lp_build_context *bld, LLVMValueRef a); -- cgit v1.2.3 From 516bad2272aa9bb3c85516e0023ddd2ed236dcef Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 4 Mar 2010 10:50:26 -0700 Subject: gallivm: added lp_build_fract() --- src/gallium/auxiliary/gallivm/lp_bld_arit.c | 13 +++++++++++++ src/gallium/auxiliary/gallivm/lp_bld_arit.h | 4 ++++ 2 files changed, 17 insertions(+) (limited to 'src/gallium/auxiliary/gallivm/lp_bld_arit.h') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c index 42ae9f6a22..32f9e5201c 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c @@ -899,6 +899,19 @@ lp_build_ceil(struct lp_build_context *bld, } +/** + * Return fractional part of 'a' computed as a - floor(f) + * Typically used in texture coord arithmetic. + */ +LLVMValueRef +lp_build_fract(struct lp_build_context *bld, + LLVMValueRef a) +{ + assert(bld->type.floating); + return lp_build_sub(bld, a, lp_build_floor(bld, a)); +} + + /** * Convert to integer, through whichever rounding method that's fastest, * typically truncating toward zero. diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.h b/src/gallium/auxiliary/gallivm/lp_bld_arit.h index 866349d8cb..55385e3a66 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.h @@ -148,6 +148,10 @@ LLVMValueRef lp_build_trunc(struct lp_build_context *bld, LLVMValueRef a); +LLVMValueRef +lp_build_fract(struct lp_build_context *bld, + LLVMValueRef a); + LLVMValueRef lp_build_ifloor(struct lp_build_context *bld, LLVMValueRef a); -- cgit v1.2.3