[Libclc-dev] [PATCH] Implementations for exp(float) and exp(double) v2
Jeroen Ketema
j.ketema at imperial.ac.uk
Fri Jun 13 04:03:24 PDT 2014
Thanks,
Committed.
I’m not in favour of depending on the behaviour of casting as suggested by Aaron, so I committed this version.
I’m not sure if this version gives enough precision to satisfy the specification, but at least this is better than what we had.
Jeroen
On 12 Jun 2014, at 22:14, Tom Stellard <tom at stellard.net> wrote:
> On Sun, May 11, 2014 at 11:36:00AM +0200, Jeroen Ketema wrote:
>> 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
>
> LGTM.
>
>> ---
>> generic/include/clc/math/exp.h | 9 +++++++--
>> generic/include/clc/math/gentype.inc | 4 ++++
>> generic/lib/SOURCES | 1 +
>> generic/lib/math/exp.cl | 8 ++++++++
>> generic/lib/math/exp.inc | 10 ++++++++++
>> 5 files changed, 30 insertions(+), 2 deletions(-)
>> create mode 100644 generic/lib/math/exp.cl
>> create mode 100644 generic/lib/math/exp.inc
>>
>> diff --git a/generic/include/clc/math/exp.h b/generic/include/clc/math/exp.h
>> index dbc4b84..9866524 100644
>> --- a/generic/include/clc/math/exp.h
>> +++ b/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 <clc/math/unary_decl.inc>
>> +#define __CLC_FUNCTION exp
>> +
>> +#include <clc/math/gentype.inc>
>> +
>> +#undef __CLC_BODY
>> +#undef __CLC_FUNCTION
>> diff --git a/generic/include/clc/math/gentype.inc b/generic/include/clc/math/gentype.inc
>> index bff4f56..9f79f6e 100644
>> --- a/generic/include/clc/math/gentype.inc
>> +++ b/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/generic/lib/SOURCES b/generic/lib/SOURCES
>> index 6ccdf48..a35542c 100644
>> --- a/generic/lib/SOURCES
>> +++ b/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
>> diff --git a/generic/lib/math/exp.cl b/generic/lib/math/exp.cl
>> new file mode 100644
>> index 0000000..dbf4a93
>> --- /dev/null
>> +++ b/generic/lib/math/exp.cl
>> @@ -0,0 +1,8 @@
>> +#include <clc/clc.h>
>> +
>> +#ifdef cl_khr_fp64
>> +#pragma OPENCL EXTENSION cl_khr_fp64 : enable
>> +#endif
>> +
>> +#define __CLC_BODY <exp.inc>
>> +#include <clc/math/gentype.inc>
>> diff --git a/generic/lib/math/exp.inc b/generic/lib/math/exp.inc
>> new file mode 100644
>> index 0000000..525fb59
>> --- /dev/null
>> +++ b/generic/lib/math/exp.inc
>> @@ -0,0 +1,10 @@
>> +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE exp(__CLC_GENTYPE val) {
>> + // exp(x) = exp2(x * log2(e))
>> +#if __CLC_FPSIZE == 32
>> + return exp2(val * M_LOG2E_F);
>> +#elif __CLC_FPSIZE == 64
>> + return exp2(val * M_LOG2E);
>> +#else
>> +#error unknown _CLC_FPSIZE
>> +#endif
>> +}
>> --
>> 1.8.5.2 (Apple Git-48)
>>
>>
>> _______________________________________________
>> Libclc-dev mailing list
>> Libclc-dev at pcc.me.uk
>> http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev
More information about the Libclc-dev
mailing list