[libclc] r258933 - Implement modf math builtin

Tom Stellard via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 27 06:52:10 PST 2016


Author: tstellar
Date: Wed Jan 27 08:52:10 2016
New Revision: 258933

URL: http://llvm.org/viewvc/llvm-project?rev=258933&view=rev
Log:
Implement modf math builtin

V2: use the reference implementation as suggested by Matt Arsenault

Patch By: Pavel Ondračka

Added:
    libclc/trunk/generic/include/clc/math/modf.h
    libclc/trunk/generic/include/clc/math/modf.inc
    libclc/trunk/generic/lib/math/modf.cl
    libclc/trunk/generic/lib/math/modf.inc
Modified:
    libclc/trunk/generic/include/clc/clc.h
    libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=258933&r1=258932&r2=258933&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Wed Jan 27 08:52:10 2016
@@ -67,6 +67,7 @@
 #include <clc/math/log1p.h>
 #include <clc/math/log2.h>
 #include <clc/math/mad.h>
+#include <clc/math/modf.h>
 #include <clc/math/nextafter.h>
 #include <clc/math/pow.h>
 #include <clc/math/pown.h>

Added: libclc/trunk/generic/include/clc/math/modf.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/modf.h?rev=258933&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/math/modf.h (added)
+++ libclc/trunk/generic/include/clc/math/modf.h Wed Jan 27 08:52:10 2016
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#define __CLC_BODY <clc/math/modf.inc>
+#include <clc/math/gentype.inc>

Added: libclc/trunk/generic/include/clc/math/modf.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/modf.inc?rev=258933&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/math/modf.inc (added)
+++ libclc/trunk/generic/include/clc/math/modf.inc Wed Jan 27 08:52:10 2016
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2014, 2015 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE modf(__CLC_GENTYPE x, global __CLC_GENTYPE *iptr);
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE modf(__CLC_GENTYPE x, local __CLC_GENTYPE *iptr);
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE modf(__CLC_GENTYPE x, private __CLC_GENTYPE *iptr);

Modified: libclc/trunk/generic/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=258933&r1=258932&r2=258933&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Wed Jan 27 08:52:10 2016
@@ -96,6 +96,7 @@ math/log10.cl
 math/log1p.cl
 math/log2.cl
 math/mad.cl
+math/modf.cl
 math/native_log.cl
 math/native_log2.cl
 math/tables.cl

Added: libclc/trunk/generic/lib/math/modf.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/modf.cl?rev=258933&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/modf.cl (added)
+++ libclc/trunk/generic/lib/math/modf.cl Wed Jan 27 08:52:10 2016
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <clc/clc.h>
+
+#include "math.h"
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+#endif
+
+#define __CLC_BODY <modf.inc>
+#include <clc/math/gentype.inc>

Added: libclc/trunk/generic/lib/math/modf.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/modf.inc?rev=258933&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/modf.inc (added)
+++ libclc/trunk/generic/lib/math/modf.inc Wed Jan 27 08:52:10 2016
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE modf(__CLC_GENTYPE x, __CLC_GENTYPE *iptr) {
+  *iptr = trunc(x);
+  return copysign(isinf(x) ? 0.0f : x - *iptr, x);
+}
+
+#define MODF_DEF(addrspace) \
+  _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE modf(__CLC_GENTYPE x, addrspace __CLC_GENTYPE *iptr) { \
+    __CLC_GENTYPE private_iptr; \
+    __CLC_GENTYPE ret = modf(x, &private_iptr); \
+    *iptr = private_iptr; \
+    return ret; \
+}
+
+MODF_DEF(local);
+MODF_DEF(global);




More information about the cfe-commits mailing list