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
24 #include
<clc
/clcmacro.h
>
27 #include
"sincos_helpers.h"
28 #include
"sincospiF_piby4.h"
30 #include
"sincosD_piby4.h"
33 _CLC_OVERLOAD _CLC_DEF float cospi
(float x
)
35 int ix
= as_int
(x) & 0x7fffffff;
36 float ax
= as_float
(ix);
39 int xodd
= iax
& 0x1 ?
0x80000000 : 0;
41 // Initialize with return for
+-Inf and NaN
44 // 2^
24 <= |x|
< Inf
, the result is always even integer
45 ir
= ix
< 0x7f800000 ?
0x3f800000 : ir
;
47 // 2^
23 <= |x|
< 2^
24, the result is always integer
48 ir
= ix
< 0x4b800000 ? xodd |
0x3f800000 : ir
;
50 // 0x1.0p-7
<= |x|
< 2^
23, result depends on which
0.25 interval
55 int s
= xodd ^
0x80000000;
72 float2 t
= __libclc__sincosf_piby4
(a * M_PI_F
);
73 int jr
= s ^ as_int
(e ? t.hi
: t.lo
);
75 ir
= ix
< 0x4b000000 ? jr
: ir
;
81 _CLC_UNARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, float
, cospi
, float
);
85 #pragma OPENCL EXTENSION cl_khr_fp64
: enable
87 _CLC_OVERLOAD _CLC_DEF double cospi
(double x
) {
89 long ix
= as_long
(x) & 0x7fffffffffffffffL
;
90 double ax
= as_double
(ix);
92 double r
= ax -
(double)iax
;
93 long xodd
= iax
& 0x1L ?
0x8000000000000000L
: 0L;
95 // Initialize with return for
+-Inf and NaN
96 long ir
= 0x7ff8000000000000L
;
98 // 2^
53 <= |x|
< Inf
, the result is always even integer
99 ir
= ix
< 0x7ff0000000000000 ?
0x3ff0000000000000L
: ir
;
101 // 2^
52 <= |x|
< 2^
53, the result is always integer
102 ir
= ax
< 0x1.0p
+53 ? xodd |
0x3ff0000000000000L
: ir
;
104 // 0x1.0p-7
<= |x|
< 2^
52, result depends on which
0.25 interval
109 long s
= xodd ^
0x8000000000000000L
;
128 double2 sc
= __libclc__sincos_piby4
(a * M_PI
, 0.0);
129 long jr
= s ^ as_long
(e ? sc.hi
: sc.lo
);
131 ir
= ax
< 0x1.0p
+52 ? jr
: ir
;
133 return as_double
(ir);
135 _CLC_UNARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, double
, cospi
, double
);
138 _CLC_DEFINE_UNARY_BUILTIN_FP16
(cospi)