From 9d0d374c5bf7072814caf9c153b12010f115367b Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Mon, 2 Mar 2015 15:29:41 +0000 Subject: [PATCH] Implement step builtin This has been tested with piglit, OpenCV, and the ocl conformance tests. llvm-svn: 230970 --- libclc/generic/include/clc/clc.h | 1 + libclc/generic/include/clc/common/step.h | 25 ++++++++++++++ libclc/generic/include/clc/common/step.inc | 28 ++++++++++++++++ libclc/generic/lib/SOURCES | 1 + libclc/generic/lib/clcmacro.h | 23 +++++++++++++ libclc/generic/lib/common/step.cl | 54 ++++++++++++++++++++++++++++++ 6 files changed, 132 insertions(+) create mode 100644 libclc/generic/include/clc/common/step.h create mode 100644 libclc/generic/include/clc/common/step.inc create mode 100644 libclc/generic/lib/common/step.cl diff --git a/libclc/generic/include/clc/clc.h b/libclc/generic/include/clc/clc.h index 4a2d29e..92ef769 100644 --- a/libclc/generic/include/clc/clc.h +++ b/libclc/generic/include/clc/clc.h @@ -112,6 +112,7 @@ #include #include #include +#include /* 6.11.5 Geometric Functions */ #include diff --git a/libclc/generic/include/clc/common/step.h b/libclc/generic/include/clc/common/step.h new file mode 100644 index 0000000..9c0bee4 --- /dev/null +++ b/libclc/generic/include/clc/common/step.h @@ -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 +#include +#undef __CLC_BODY diff --git a/libclc/generic/include/clc/common/step.inc b/libclc/generic/include/clc/common/step.inc new file mode 100644 index 0000000..f606b7c --- /dev/null +++ b/libclc/generic/include/clc/common/step.inc @@ -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 diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES index ba5b409..f0488ef 100644 --- a/libclc/generic/lib/SOURCES +++ b/libclc/generic/lib/SOURCES @@ -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 diff --git a/libclc/generic/lib/clcmacro.h b/libclc/generic/lib/clcmacro.h index 39636c9..346adf2 100644 --- a/libclc/generic/lib/clcmacro.h +++ b/libclc/generic/lib/clcmacro.h @@ -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)); \ diff --git a/libclc/generic/lib/common/step.cl b/libclc/generic/lib/common/step.cl new file mode 100644 index 0000000..4b022f1 --- /dev/null +++ b/libclc/generic/lib/common/step.cl @@ -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 + +#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 -- 2.7.4