2 * Copyright
(c) 2014 Advanced Micro Devices
, Inc.
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
:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
25 _CLC_OVERLOAD _CLC_DEF float length
(float p
) {
29 #define V_FLENGTH
(p) \
30 float l2
= dot
(p, p
); \
34 return sqrt
(dot(p, p
)) * 0x1.0p-86F
; \
35 } else if
(l2 == INFINITY
) { \
37 return sqrt
(dot(p, p
)) * 0x1.0p
+65F
; \
42 _CLC_OVERLOAD _CLC_DEF float length
(float2 p
) {
46 _CLC_OVERLOAD _CLC_DEF float length
(float3 p
) {
50 _CLC_OVERLOAD _CLC_DEF float length
(float4 p
) {
55 #pragma OPENCL EXTENSION cl_khr_fp64
: enable
57 _CLC_OVERLOAD _CLC_DEF double length
(double p
){
61 #define V_DLENGTH
(p) \
62 double l2
= dot
(p, p
); \
66 return sqrt
(dot(p, p
)) * 0x1.0p-563
; \
67 } else if
(l2 == INFINITY
) { \
69 return sqrt
(dot(p, p
)) * 0x1.0p
+513; \
74 _CLC_OVERLOAD _CLC_DEF double length
(double2 p
) {
78 _CLC_OVERLOAD _CLC_DEF double length
(double3 p
) {
82 _CLC_OVERLOAD _CLC_DEF double length
(double4 p
) {
89 #pragma OPENCL EXTENSION cl_khr_fp16
: enable
91 _CLC_OVERLOAD _CLC_DEF half length
(half p
){
95 // Only available in CLC1.2
97 #define HALF_MIN
0x1.0p-14h
100 #define V_HLENGTH
(p) \
101 half l2
= dot
(p, p
); \
103 if
(l2 < HALF_MIN
) { \
105 return sqrt
(dot(p, p
)) * 0x1.0p-12h
; \
106 } else if
(l2 == INFINITY
) { \
108 return sqrt
(dot(p, p
)) * 0x1.0p
+7h
; \
113 _CLC_OVERLOAD _CLC_DEF half length
(half2 p
) {
117 _CLC_OVERLOAD _CLC_DEF half length
(half3 p
) {
121 _CLC_OVERLOAD _CLC_DEF half length
(half4 p
) {