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
"sincospiF_piby4.h"
29 #include
"sincosD_piby4.h"
32 _CLC_OVERLOAD _CLC_DEF float sinpi
(float x
)
35 int xsgn
= ix
& 0x80000000;
37 float ax
= as_float
(ix);
40 int xodd
= xsgn ^
(iax & 0x1 ?
0x80000000 : 0);
42 // Initialize with return for
+-Inf and NaN
45 // 2^
23 <= |x|
< Inf
, the result is always integer
46 ir
= ix
< 0x7f800000 ? xsgn
: ir
;
48 // 0x1.0p-7
<= |x|
< 2^
23, result depends on which
0.25 interval
68 float2 t
= __libclc__sincosf_piby4
(a * M_PI_F
);
69 int jr
= xodd ^ as_int
(e ? t.hi
: t.lo
);
71 ir
= ix
< 0x4b000000 ? jr
: ir
;
76 _CLC_UNARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, float
, sinpi
, float
);
80 #pragma OPENCL EXTENSION cl_khr_fp64
: enable
82 _CLC_OVERLOAD _CLC_DEF double sinpi
(double x
)
85 long xsgn
= ix
& 0x8000000000000000L
;
87 double ax
= as_double
(ix);
89 double r
= ax -
(double)iax
;
90 long xodd
= xsgn ^
(iax & 0x1L ?
0x8000000000000000L
: 0L);
92 // Initialize with return for
+-Inf and NaN
93 long ir
= 0x7ff8000000000000L
;
95 // 2^
23 <= |x|
< Inf
, the result is always integer
96 ir
= ix
< 0x7ff0000000000000 ? xsgn
: ir
;
98 // 0x1.0p-7
<= |x|
< 2^
23, result depends on which
0.25 interval
120 double api
= a
* M_PI
;
121 double2 sc
= __libclc__sincos_piby4
(api, 0.0);
122 long jr
= xodd ^ as_long
(e ? sc.hi
: sc.lo
);
124 ir
= ax
< 0x1.0p
+52 ? jr
: ir
;
126 return as_double
(ir);
129 _CLC_UNARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, double
, sinpi
, double
)
133 _CLC_DEFINE_UNARY_BUILTIN_FP16
(sinpi)