<div dir="ltr"><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+#define FLT_NAN 0.0f/0.0f</span><div><font color="#000000" face="arial, sans-serif"><br></font><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">+#define DBL_NAN 0.0/0.0</span><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br>
</span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">These should be parenthesized.</span></div>
</div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:13px">-- Sean Silva</span></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Oct 10, 2013 at 3:08 PM, Tom Stellard <span dir="ltr"><<a href="mailto:thomas.stellard@amd.com" target="_blank">thomas.stellard@amd.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: tstellar<br>
Date: Thu Oct 10 14:08:51 2013<br>
New Revision: 192383<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=192383&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=192383&view=rev</a><br>
Log:<br>
Implement nextafter() builtin<br>
<br>
There are two implementations of nextafter():<br>
1. Using clang's __builtin_nextafter. Clang replaces this builtin with<br>
a call to nextafter which is part of libm. Therefore, this<br>
implementation will only work for targets with an implementation of<br>
libm (e.g. most CPU targets).<br>
<br>
2. The other implementation is written in OpenCL C. This function is<br>
known internally as __clc_nextafter and can be used by targets that<br>
don't have access to libm.<br>
<br>
Added:<br>
libclc/trunk/generic/include/clc/math/clc_nextafter.h<br>
libclc/trunk/generic/include/clc/math/nextafter.h<br>
libclc/trunk/generic/include/math/<br>
libclc/trunk/generic/include/math/clc_nextafter.h<br>
libclc/trunk/generic/lib/math/<a href="http://clc_nextafter.cl" target="_blank">clc_nextafter.cl</a><br>
libclc/trunk/generic/lib/math/<a href="http://nextafter.cl" target="_blank">nextafter.cl</a><br>
libclc/trunk/r600/lib/math/<br>
libclc/trunk/r600/lib/math/<a href="http://nextafter.cl" target="_blank">nextafter.cl</a><br>
Modified:<br>
libclc/trunk/configure.py<br>
libclc/trunk/generic/include/clc/clc.h<br>
libclc/trunk/generic/include/clc/clcmacro.h<br>
libclc/trunk/generic/lib/SOURCES<br>
libclc/trunk/r600/lib/SOURCES<br>
<br>
Modified: libclc/trunk/configure.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libclc/trunk/configure.py?rev=192383&r1=192382&r2=192383&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/libclc/trunk/configure.py?rev=192383&r1=192382&r2=192383&view=diff</a><br>
==============================================================================<br>
--- libclc/trunk/configure.py (original)<br>
+++ libclc/trunk/configure.py Thu Oct 10 14:08:51 2013<br>
@@ -145,6 +145,7 @@ for target in targets:<br>
clang_bc_flags = "-target %s -I`dirname $in` %s " \<br>
"-Dcl_clang_storage_class_specifiers " \<br>
"-Dcl_khr_fp64 " \<br>
+ "-D__CLC_INTERNAL " \<br>
"-emit-llvm" % (target, clang_cl_includes)<br>
if device['gpu'] != '':<br>
clang_bc_flags += ' -mcpu=' + device['gpu']<br>
<br>
Modified: libclc/trunk/generic/include/clc/clc.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=192383&r1=192382&r2=192383&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=192383&r1=192382&r2=192383&view=diff</a><br>
==============================================================================<br>
--- libclc/trunk/generic/include/clc/clc.h (original)<br>
+++ libclc/trunk/generic/include/clc/clc.h Thu Oct 10 14:08:51 2013<br>
@@ -45,6 +45,7 @@<br>
#include <clc/math/log.h><br>
#include <clc/math/log2.h><br>
#include <clc/math/mad.h><br>
+#include <clc/math/nextafter.h><br>
#include <clc/math/pow.h><br>
#include <clc/math/rint.h><br>
#include <clc/math/sin.h><br>
@@ -107,4 +108,9 @@<br>
#include <clc/atomic/atomic_inc.h><br>
#include <clc/atomic/atomic_sub.h><br>
<br>
+/* libclc internal defintions */<br>
+#ifdef __CLC_INTERNAL<br>
+#include <math/clc_nextafter.h><br>
+#endif<br>
+<br>
#pragma OPENCL EXTENSION all : disable<br>
<br>
Modified: libclc/trunk/generic/include/clc/clcmacro.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clcmacro.h?rev=192383&r1=192382&r2=192383&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clcmacro.h?rev=192383&r1=192382&r2=192383&view=diff</a><br>
==============================================================================<br>
--- libclc/trunk/generic/include/clc/clcmacro.h (original)<br>
+++ libclc/trunk/generic/include/clc/clcmacro.h Thu Oct 10 14:08:51 2013<br>
@@ -41,6 +41,12 @@<br>
return (RET_TYPE##16)(FUNCTION(x.lo, y.lo), FUNCTION(x.hi, y.hi)); \<br>
}<br>
<br>
+#define _CLC_DEFINE_BINARY_BUILTIN(RET_TYPE, FUNCTION, BUILTIN, ARG1_TYPE, ARG2_TYPE) \<br>
+_CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG1_TYPE x, ARG2_TYPE y) { \<br>
+ return BUILTIN(x, y); \<br>
+} \<br>
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, RET_TYPE, FUNCTION, ARG1_TYPE, ARG2_TYPE)<br>
+<br>
#define _CLC_DEFINE_UNARY_BUILTIN(RET_TYPE, FUNCTION, BUILTIN, ARG1_TYPE) \<br>
_CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG1_TYPE x) { \<br>
return BUILTIN(x); \<br>
<br>
Added: libclc/trunk/generic/include/clc/math/clc_nextafter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/clc_nextafter.h?rev=192383&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/clc_nextafter.h?rev=192383&view=auto</a><br>
==============================================================================<br>
--- libclc/trunk/generic/include/clc/math/clc_nextafter.h (added)<br>
+++ libclc/trunk/generic/include/clc/math/clc_nextafter.h Thu Oct 10 14:08:51 2013<br>
@@ -0,0 +1,11 @@<br>
+#define __CLC_BODY <clc/math/binary_decl.inc><br>
+<br>
+#define __CLC_FUNCTION nextafter<br>
+#include <clc/math/gentype.inc><br>
+#undef __CLC_FUNCTION<br>
+<br>
+#define __CLC_FUNCTION __clc_nextafter<br>
+#include <clc/math/gentype.inc><br>
+#undef __CLC_FUNCTION<br>
+<br>
+#undef __CLC_BODY<br>
<br>
Added: libclc/trunk/generic/include/clc/math/nextafter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/nextafter.h?rev=192383&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/nextafter.h?rev=192383&view=auto</a><br>
==============================================================================<br>
--- libclc/trunk/generic/include/clc/math/nextafter.h (added)<br>
+++ libclc/trunk/generic/include/clc/math/nextafter.h Thu Oct 10 14:08:51 2013<br>
@@ -0,0 +1,5 @@<br>
+#define __CLC_BODY <clc/math/binary_decl.inc><br>
+#define __CLC_FUNCTION nextafter<br>
+#include <clc/math/gentype.inc><br>
+#undef __CLC_FUNCTION<br>
+#undef __CLC_BODY<br>
<br>
Added: libclc/trunk/generic/include/math/clc_nextafter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/math/clc_nextafter.h?rev=192383&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/math/clc_nextafter.h?rev=192383&view=auto</a><br>
==============================================================================<br>
--- libclc/trunk/generic/include/math/clc_nextafter.h (added)<br>
+++ libclc/trunk/generic/include/math/clc_nextafter.h Thu Oct 10 14:08:51 2013<br>
@@ -0,0 +1,7 @@<br>
+#define __CLC_BODY <clc/math/binary_decl.inc><br>
+#define __CLC_FUNCTION __clc_nextafter<br>
+<br>
+#include <clc/math/gentype.inc><br>
+<br>
+#undef __CLC_BODY<br>
+#undef __CLC_FUNCTION<br>
<br>
Modified: libclc/trunk/generic/lib/SOURCES<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=192383&r1=192382&r2=192383&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=192383&r1=192382&r2=192383&view=diff</a><br>
==============================================================================<br>
--- libclc/trunk/generic/lib/SOURCES (original)<br>
+++ libclc/trunk/generic/lib/SOURCES Thu Oct 10 14:08:51 2013<br>
@@ -26,6 +26,8 @@ math/<a href="http://fmax.cl" target="_blank">fmax.cl</a><br>
math/<a href="http://fmin.cl" target="_blank">fmin.cl</a><br>
math/<a href="http://hypot.cl" target="_blank">hypot.cl</a><br>
math/<a href="http://mad.cl" target="_blank">mad.cl</a><br>
+math/<a href="http://clc_nextafter.cl" target="_blank">clc_nextafter.cl</a><br>
+math/<a href="http://nextafter.cl" target="_blank">nextafter.cl</a><br>
relational/<a href="http://any.cl" target="_blank">any.cl</a><br>
relational/<a href="http://isnan.cl" target="_blank">isnan.cl</a><br>
shared/<a href="http://clamp.cl" target="_blank">clamp.cl</a><br>
<br>
Added: libclc/trunk/generic/lib/math/<a href="http://clc_nextafter.cl" target="_blank">clc_nextafter.cl</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_nextafter.cl?rev=192383&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_nextafter.cl?rev=192383&view=auto</a><br>
==============================================================================<br>
--- libclc/trunk/generic/lib/math/<a href="http://clc_nextafter.cl" target="_blank">clc_nextafter.cl</a> (added)<br>
+++ libclc/trunk/generic/lib/math/<a href="http://clc_nextafter.cl" target="_blank">clc_nextafter.cl</a> Thu Oct 10 14:08:51 2013<br>
@@ -0,0 +1,42 @@<br>
+#include <clc/clc.h><br>
+<br>
+// This file provides OpenCL C implementations of nextafter for targets that<br>
+// don't support the clang builtin.<br>
+<br>
+#define FLT_NAN 0.0f/0.0f<br>
+<br>
+#define NEXTAFTER(FLOAT_TYPE, UINT_TYPE, NAN, ZERO, NEXTAFTER_ZERO) \<br>
+_CLC_OVERLOAD _CLC_DEF FLOAT_TYPE __clc_nextafter(FLOAT_TYPE x, FLOAT_TYPE y) { \<br>
+ union { \<br>
+ FLOAT_TYPE f; \<br>
+ UINT_TYPE i; \<br>
+ } next; \<br>
+ if (isnan(x) || isnan(y)) { \<br>
+ return NAN; \<br>
+ } \<br>
+ if (x == y) { \<br>
+ return y; \<br>
+ } \<br>
+ next.f = x; \<br>
+ if (x < y) { \<br>
+ next.i++; \<br>
+ } else { \<br>
+ if (next.f == ZERO) { \<br>
+ next.i = NEXTAFTER_ZERO; \<br>
+ } else { \<br>
+ next.i--; \<br>
+ } \<br>
+ } \<br>
+ return next.f; \<br>
+}<br>
+<br>
+NEXTAFTER(float, uint, FLT_NAN, 0.0f, 0x80000001)<br>
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, __clc_nextafter, float, float)<br>
+<br>
+#ifdef cl_khr_fp64<br>
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable<br>
+#define DBL_NAN 0.0/0.0<br>
+<br>
+NEXTAFTER(double, ulong, DBL_NAN, 0.0, 0x8000000000000001)<br>
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, __clc_nextafter, double, double)<br>
+#endif<br>
<br>
Added: libclc/trunk/generic/lib/math/<a href="http://nextafter.cl" target="_blank">nextafter.cl</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/nextafter.cl?rev=192383&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/nextafter.cl?rev=192383&view=auto</a><br>
==============================================================================<br>
--- libclc/trunk/generic/lib/math/<a href="http://nextafter.cl" target="_blank">nextafter.cl</a> (added)<br>
+++ libclc/trunk/generic/lib/math/<a href="http://nextafter.cl" target="_blank">nextafter.cl</a> Thu Oct 10 14:08:51 2013<br>
@@ -0,0 +1,11 @@<br>
+#include <clc/clc.h><br>
+<br>
+_CLC_DEFINE_BINARY_BUILTIN(float, nextafter, __builtin_nextafterf, float, float)<br>
+<br>
+#ifdef cl_khr_fp64<br>
+<br>
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable<br>
+<br>
+_CLC_DEFINE_BINARY_BUILTIN(double, nextafter, __builtin_nextafter, double, double)<br>
+<br>
+#endif<br>
<br>
Modified: libclc/trunk/r600/lib/SOURCES<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/SOURCES?rev=192383&r1=192382&r2=192383&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/SOURCES?rev=192383&r1=192382&r2=192383&view=diff</a><br>
==============================================================================<br>
--- libclc/trunk/r600/lib/SOURCES (original)<br>
+++ libclc/trunk/r600/lib/SOURCES Thu Oct 10 14:08:51 2013<br>
@@ -1,4 +1,5 @@<br>
atomic/<a href="http://atomic.cl" target="_blank">atomic.cl</a><br>
+math/<a href="http://nextafter.cl" target="_blank">nextafter.cl</a><br>
workitem/get_num_groups.ll<br>
workitem/get_group_id.ll<br>
workitem/get_local_size.ll<br>
<br>
Added: libclc/trunk/r600/lib/math/<a href="http://nextafter.cl" target="_blank">nextafter.cl</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/math/nextafter.cl?rev=192383&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/math/nextafter.cl?rev=192383&view=auto</a><br>
==============================================================================<br>
--- libclc/trunk/r600/lib/math/<a href="http://nextafter.cl" target="_blank">nextafter.cl</a> (added)<br>
+++ libclc/trunk/r600/lib/math/<a href="http://nextafter.cl" target="_blank">nextafter.cl</a> Thu Oct 10 14:08:51 2013<br>
@@ -0,0 +1,3 @@<br>
+#include <clc/clc.h><br>
+<br>
+_CLC_DEFINE_BINARY_BUILTIN(float, nextafter, __clc_nextafter, float, float)<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>