summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/gallivm/lp_bld_arit.c
diff options
context:
space:
mode:
authorZack Rusin <zackr@vmware.com>2013-07-18 03:32:02 -0400
committerZack Rusin <zackr@vmware.com>2013-07-19 16:29:18 -0400
commitf7c06785d08156320836ee94552e7f89e1542647 (patch)
tree35d718c0112585aa719445fc179fe54e52e37858 /src/gallium/auxiliary/gallivm/lp_bld_arit.c
parent018c69ac56ee0579b5d4f138340444b326c4e6dc (diff)
downloadexternal_mesa3d-f7c06785d08156320836ee94552e7f89e1542647.zip
external_mesa3d-f7c06785d08156320836ee94552e7f89e1542647.tar.gz
external_mesa3d-f7c06785d08156320836ee94552e7f89e1542647.tar.bz2
gallivm: add a log function that handles edge cases
Same as log2_safe, which means that it can handle infs, 0s and nans. Signed-off-by: Zack Rusin <zackr@vmware.com> Reviewed-by: Jose Fonseca <jfonseca@vmware.com> Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Diffstat (limited to 'src/gallium/auxiliary/gallivm/lp_bld_arit.c')
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_arit.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
index 2ce287f..98409c3 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.