diff options
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_arit.c | 17 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_arit.h | 4 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c index 2ce287f938a..98409c3be86 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c @@ -3080,6 +3080,7 @@ lp_build_exp(struct lp_build_context *bld, /** * Generate log(x) + * Behavior is undefined with infs, 0s and nans */ LLVMValueRef lp_build_log(struct lp_build_context *bld, @@ -3094,6 +3095,22 @@ lp_build_log(struct lp_build_context *bld, return lp_build_mul(bld, log2, lp_build_log2(bld, x)); } +/** + * Generate log(x) that handles edge cases (infs, 0s and nans) + */ +LLVMValueRef +lp_build_log_safe(struct lp_build_context *bld, + LLVMValueRef x) +{ + /* log(2) */ + LLVMValueRef log2 = lp_build_const_vec(bld->gallivm, bld->type, + 0.69314718055994529); + + assert(lp_check_value(bld->type, x)); + + return lp_build_mul(bld, log2, lp_build_log2_safe(bld, x)); +} + /** * Generate polynomial. diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.h b/src/gallium/auxiliary/gallivm/lp_bld_arit.h index 6b9e0d1caf6..35119d18f7b 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.h @@ -292,6 +292,10 @@ lp_build_log(struct lp_build_context *bld, LLVMValueRef a); LLVMValueRef +lp_build_log_safe(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef lp_build_exp2(struct lp_build_context *bld, LLVMValueRef a); |