1/*
2 * Copyright (c) 2014,2015 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#include <clc/clc.h>
24
25#include "../clcmacro.h"
26
27_CLC_OVERLOAD _CLC_DEF float smoothstep(float edge0, float edge1, float x) {
28  float t = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
29  return t * t * (3.0f - 2.0f * t);
30}
31
32_CLC_TERNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, smoothstep, float, float, float);
33
34_CLC_V_S_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, smoothstep, float, float, float);
35
36#ifdef cl_khr_fp64
37#pragma OPENCL EXTENSION cl_khr_fp64 : enable
38
39#define SMOOTH_STEP_DEF(edge_type, x_type, impl) \
40  _CLC_OVERLOAD _CLC_DEF x_type smoothstep(edge_type edge0, edge_type edge1, x_type x) { \
41    double t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); \
42    return t * t * (3.0 - 2.0 * t); \
43 }
44
45SMOOTH_STEP_DEF(double, double, SMOOTH_STEP_IMPL_D);
46
47_CLC_TERNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, smoothstep, double, double, double);
48
49#if !defined(CLC_SPIRV) && !defined(CLC_SPIRV64)
50SMOOTH_STEP_DEF(float, double, SMOOTH_STEP_IMPL_D);
51SMOOTH_STEP_DEF(double, float, SMOOTH_STEP_IMPL_D);
52
53_CLC_V_S_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, smoothstep, float, float, double);
54_CLC_V_S_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, smoothstep, double, double, float);
55#endif
56
57#endif
58