From 82aaa4128647e8a12ce88588766088c94bd0d0f2 Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Fri, 13 Jun 2014 09:40:09 +0000 Subject: [PATCH] Implementations for exp(float) and exp(double) v2 Use separate implementations instead of a macro to ensure the constant multiplied with is of higher precision. v2: Use the correct formula, spotted by Dan Liew Reviewed-by: Aaron Warty Reviewed-by: Tom Stellard llvm-svn: 210891 --- libclc/generic/include/clc/math/exp.h | 9 +++++++-- libclc/generic/include/clc/math/gentype.inc | 4 ++++ libclc/generic/lib/SOURCES | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libclc/generic/include/clc/math/exp.h b/libclc/generic/include/clc/math/exp.h index dbc4b84..9866524 100644 --- a/libclc/generic/include/clc/math/exp.h +++ b/libclc/generic/include/clc/math/exp.h @@ -1,4 +1,9 @@ #undef exp -// exp(x) = exp2(x * log2(e) -#define exp(val) (__clc_exp2((val) * 1.44269504f)) +#define __CLC_BODY +#define __CLC_FUNCTION exp + +#include + +#undef __CLC_BODY +#undef __CLC_FUNCTION diff --git a/libclc/generic/include/clc/math/gentype.inc b/libclc/generic/include/clc/math/gentype.inc index bff4f56..9f79f6e 100644 --- a/libclc/generic/include/clc/math/gentype.inc +++ b/libclc/generic/include/clc/math/gentype.inc @@ -1,4 +1,5 @@ #define __CLC_SCALAR_GENTYPE float +#define __CLC_FPSIZE 32 #define __CLC_GENTYPE float #define __CLC_SCALAR @@ -26,10 +27,12 @@ #include __CLC_BODY #undef __CLC_GENTYPE +#undef __CLC_FPSIZE #undef __CLC_SCALAR_GENTYPE #ifdef cl_khr_fp64 #define __CLC_SCALAR_GENTYPE double +#define __CLC_FPSIZE 64 #define __CLC_SCALAR #define __CLC_GENTYPE double @@ -57,6 +60,7 @@ #include __CLC_BODY #undef __CLC_GENTYPE +#undef __CLC_FPSIZE #undef __CLC_SCALAR_GENTYPE #endif diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES index 6ccdf48..a35542c 100644 --- a/libclc/generic/lib/SOURCES +++ b/libclc/generic/lib/SOURCES @@ -27,6 +27,7 @@ integer/sub_sat.cl integer/sub_sat_if.ll integer/sub_sat_impl.ll integer/upsample.cl +math/exp.cl math/fmax.cl math/fmin.cl math/hypot.cl -- 2.7.4