[libclc] r230970 - Implement step builtin

Tom Stellard thomas.stellard at amd.com
Mon Mar 2 07:29:41 PST 2015


Author: tstellar
Date: Mon Mar  2 09:29:41 2015
New Revision: 230970

URL: http://llvm.org/viewvc/llvm-project?rev=230970&view=rev
Log:
Implement step builtin

This has been tested with piglit, OpenCV, and the ocl conformance tests.

Added:
    libclc/trunk/generic/include/clc/common/step.h
    libclc/trunk/generic/include/clc/common/step.inc
    libclc/trunk/generic/lib/common/step.cl
Modified:
    libclc/trunk/generic/include/clc/clc.h
    libclc/trunk/generic/lib/SOURCES
    libclc/trunk/generic/lib/clcmacro.h

Modified: libclc/trunk/generic/include/clc/clc.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=230970&r1=230969&r2=230970&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Mon Mar  2 09:29:41 2015
@@ -112,6 +112,7 @@
 #include <clc/common/radians.h>
 #include <clc/common/sign.h>
 #include <clc/common/smoothstep.h>
+#include <clc/common/step.h>
 
 /* 6.11.5 Geometric Functions */
 #include <clc/geometric/cross.h>

Added: libclc/trunk/generic/include/clc/common/step.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/common/step.h?rev=230970&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/common/step.h (added)
+++ libclc/trunk/generic/include/clc/common/step.h Mon Mar  2 09:29:41 2015
@@ -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.
+ */
+
+#define __CLC_BODY <clc/common/step.inc>
+#include <clc/math/gentype.inc>
+#undef __CLC_BODY

Added: libclc/trunk/generic/include/clc/common/step.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/common/step.inc?rev=230970&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/common/step.inc (added)
+++ libclc/trunk/generic/include/clc/common/step.inc Mon Mar  2 09:29:41 2015
@@ -0,0 +1,28 @@
+/*
+ * 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 step(__CLC_GENTYPE edge, __CLC_GENTYPE x);
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE step(float edge, __CLC_GENTYPE x);
+
+#ifdef cl_khr_fp64
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE step(double edge, __CLC_GENTYPE x);
+#endif

Modified: libclc/trunk/generic/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=230970&r1=230969&r2=230970&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Mon Mar  2 09:29:41 2015
@@ -31,6 +31,7 @@ common/degrees.cl
 common/radians.cl
 common/sign.cl
 common/smoothstep.cl
+common/step.cl
 geometric/cross.cl
 geometric/dot.cl
 geometric/length.cl

Modified: libclc/trunk/generic/lib/clcmacro.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/clcmacro.h?rev=230970&r1=230969&r2=230970&view=diff
==============================================================================
--- libclc/trunk/generic/lib/clcmacro.h (original)
+++ libclc/trunk/generic/lib/clcmacro.h Mon Mar  2 09:29:41 2015
@@ -41,6 +41,29 @@
     return (RET_TYPE##16)(FUNCTION(x.lo, y.lo), FUNCTION(x.hi, y.hi)); \
   }
 
+#define _CLC_V_S_V_VECTORIZE(DECLSPEC, RET_TYPE, FUNCTION, ARG1_TYPE, ARG2_TYPE) \
+  DECLSPEC RET_TYPE##2 FUNCTION(ARG1_TYPE x, ARG2_TYPE##2 y) { \
+    return (RET_TYPE##2)(FUNCTION(x, y.lo), FUNCTION(x, y.hi)); \
+  } \
+\
+  DECLSPEC RET_TYPE##3 FUNCTION(ARG1_TYPE x, ARG2_TYPE##3 y) { \
+    return (RET_TYPE##3)(FUNCTION(x, y.x), FUNCTION(x, y.y), \
+                         FUNCTION(x, y.z)); \
+  } \
+\
+  DECLSPEC RET_TYPE##4 FUNCTION(ARG1_TYPE x, ARG2_TYPE##4 y) { \
+    return (RET_TYPE##4)(FUNCTION(x, y.lo), FUNCTION(x, y.hi)); \
+  } \
+\
+  DECLSPEC RET_TYPE##8 FUNCTION(ARG1_TYPE x, ARG2_TYPE##8 y) { \
+    return (RET_TYPE##8)(FUNCTION(x, y.lo), FUNCTION(x, y.hi)); \
+  } \
+\
+  DECLSPEC RET_TYPE##16 FUNCTION(ARG1_TYPE x, ARG2_TYPE##16 y) { \
+    return (RET_TYPE##16)(FUNCTION(x, y.lo), FUNCTION(x, y.hi)); \
+  } \
+\
+
 #define _CLC_TERNARY_VECTORIZE(DECLSPEC, RET_TYPE, FUNCTION, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE) \
   DECLSPEC RET_TYPE##2 FUNCTION(ARG1_TYPE##2 x, ARG2_TYPE##2 y, ARG3_TYPE##2 z) { \
     return (RET_TYPE##2)(FUNCTION(x.x, y.x, z.x), FUNCTION(x.y, y.y, z.y)); \

Added: libclc/trunk/generic/lib/common/step.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/common/step.cl?rev=230970&view=auto
==============================================================================
--- libclc/trunk/generic/lib/common/step.cl (added)
+++ libclc/trunk/generic/lib/common/step.cl Mon Mar  2 09:29:41 2015
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+#include <clc/clc.h>
+
+#include "../clcmacro.h"
+
+_CLC_OVERLOAD _CLC_DEF float step(float edge, float x) {
+  return x < edge ? 0.0f : 1.0f;
+}
+
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, step, float, float);
+
+_CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, step, float, float);
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+#define STEP_DEF(edge_type, x_type) \
+  _CLC_OVERLOAD _CLC_DEF x_type step(edge_type edge, x_type x) { \
+    return x < edge ? 0.0 : 1.0; \
+ }
+
+STEP_DEF(double, double);
+
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, step, double, double);
+_CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, step, double, double);
+
+STEP_DEF(float, double);
+STEP_DEF(double, float);
+
+_CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, step, float, double);
+_CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, step, double, float);
+
+#endif





More information about the cfe-commits mailing list