[Libclc-dev] [PATCH v2 1/1] Implement log10

Jeroen Ketema j.ketema at imperial.ac.uk
Mon Jan 26 03:50:04 PST 2015


> On 22 Jan 2015, at 22:47, Jan Vesely <jan.vesely at rutgers.edu> wrote:
> 
> v2: Use constant and multiplication instead of division
> 
> Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
> ---
> 
> Hi,
> sorry it took so long. This issue has fallen low on priority. The new version
> uses multiplication (correctly rounded) and builtin constant,
> the constant is smaller than 1 so the resulting error should be smaller
> or equal to log2 function.
> This is the same approach as log() (although log does not handle DP correctly).
> 
> I have also pinged the corresponding piglit test.
> 
> jan
> 
> generic/include/clc/clc.h        |  1 +
> generic/include/clc/math/log10.h |  9 +++++++++
> generic/lib/SOURCES              |  1 +
> generic/lib/math/log10.cl        |  8 ++++++++
> generic/lib/math/log10.inc       | 13 +++++++++++++
> 5 files changed, 32 insertions(+)
> create mode 100644 generic/include/clc/math/log10.h
> create mode 100644 generic/lib/math/log10.cl
> create mode 100644 generic/lib/math/log10.inc
> 
> diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
> index bd92fdb..29c1855 100644
> --- a/generic/include/clc/clc.h
> +++ b/generic/include/clc/clc.h
> @@ -50,6 +50,7 @@
> #include <clc/math/fmod.h>
> #include <clc/math/hypot.h>
> #include <clc/math/log.h>
> +#include <clc/math/log10.h>
> #include <clc/math/log1p.h>
> #include <clc/math/log2.h>
> #include <clc/math/mad.h>
> diff --git a/generic/include/clc/math/log10.h b/generic/include/clc/math/log10.h
> new file mode 100644
> index 0000000..ec4e4ae
> --- /dev/null
> +++ b/generic/include/clc/math/log10.h
> @@ -0,0 +1,9 @@
> +#undef log10
> +
> +#define __CLC_BODY <clc/math/unary_decl.inc>
> +#define __CLC_FUNCTION log10
> +
> +#include <clc/math/gentype.inc>
> +
> +#undef __CLC_BODY
> +#undef __CLC_FUNCTION
> diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
> index b76fec9..1032606 100644
> --- a/generic/lib/SOURCES
> +++ b/generic/lib/SOURCES
> @@ -63,6 +63,7 @@ math/fmax.cl
> math/fmin.cl
> math/fmod.cl
> math/hypot.cl
> +math/log10.cl
> math/log1p.cl
> math/mad.cl
> math/mix.cl
> diff --git a/generic/lib/math/log10.cl b/generic/lib/math/log10.cl
> new file mode 100644
> index 0000000..d65764a
> --- /dev/null
> +++ b/generic/lib/math/log10.cl
> @@ -0,0 +1,8 @@
> +#include <clc/clc.h>
> +
> +#ifdef cl_khr_fp64
> +#pragma OPENCL EXTENSION cl_khr_fp64 : enable
> +#endif
> +
> +#define __CLC_BODY <log10.inc>
> +#include <clc/math/gentype.inc>
> diff --git a/generic/lib/math/log10.inc b/generic/lib/math/log10.inc
> new file mode 100644
> index 0000000..bf8fa1a
> --- /dev/null
> +++ b/generic/lib/math/log10.inc
> @@ -0,0 +1,13 @@
> +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE log10(__CLC_GENTYPE val) {
> +  // log10(x) = log2(x) / log2(10)
> +  // 1 / log2(10) = 0.30102999566 = log10(2)
> +  // SP representation is 0.30103
> +  // DP representation is 0.301029995659999993762312442414
> +#if __CLC_FPSIZE == 32
> +  return log2(val) * 0.30102999566f;
> +#elif __CLC_FPSIZE == 64
> +  return log2(val) * 0.30102999566;

In other places we’re using hexadecimal floating point representations. Shouldn’t
those be used here too?

Jeroen

> +#else
> +#error unknown _CLC_FPSIZE
> +#endif
> +}
> -- 
> 2.1.0
> 
> 
> _______________________________________________
> 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