Skip to content

Commit 87978ea

Browse files
authored
[libclc] Move tan to the CLC library (#139547)
There was already a __clc_tan in the OpenCL layer. This commit moves the function over whilst vectorizing it. The function __clc_tan is no longer a public symbol, which should have never been the case.
1 parent 2e13f7a commit 87978ea

File tree

11 files changed

+96
-100
lines changed

11 files changed

+96
-100
lines changed

libclc/generic/include/math/clc_tan.h renamed to libclc/clc/include/clc/math/clc_tan.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#define __CLC_FUNCTION __clc_tan
9+
#ifndef __CLC_MATH_CLC_TAN_H__
10+
#define __CLC_MATH_CLC_TAN_H__
11+
1012
#define __CLC_BODY <clc/math/unary_decl.inc>
13+
#define __CLC_FUNCTION __clc_tan
14+
1115
#include <clc/math/gentype.inc>
16+
1217
#undef __CLC_FUNCTION
18+
19+
#endif // __CLC_MATH_CLC_TAN_H__

libclc/clc/lib/generic/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ math/clc_sinpi.cl
9595
math/clc_sqrt.cl
9696
math/clc_sw_fma.cl
9797
math/clc_tables.cl
98+
math/clc_tan.cl
9899
math/clc_tanh.cl
99100
math/clc_tanpi.cl
100101
math/clc_tgamma.cl

libclc/clc/lib/generic/math/clc_sincos_helpers.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ _CLC_DECL _CLC_OVERLOAD __CLC_FLOATN __clc_tanf_piby4(__CLC_FLOATN x,
9090
__CLC_FLOATN t = __clc_mad(x * r, __clc_native_divide(a, b), x);
9191
__CLC_FLOATN tr = -MATH_RECIP(t);
9292

93-
return regn & 1 ? tr : t;
93+
return (regn & 1) != 0 ? tr : t;
9494
}
9595

9696
_CLC_DEF _CLC_OVERLOAD void __clc_fullMulS(private __CLC_FLOATN *hi,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <clc/clc_convert.h>
10+
#include <clc/float/definitions.h>
11+
#include <clc/internal/clc.h>
12+
#include <clc/math/clc_fabs.h>
13+
#include <clc/math/clc_sincos_helpers.h>
14+
#include <clc/math/clc_sincos_piby4.h>
15+
#include <clc/math/math.h>
16+
#include <clc/math/tables.h>
17+
#include <clc/relational/clc_isinf.h>
18+
#include <clc/relational/clc_isnan.h>
19+
#include <clc/relational/clc_select.h>
20+
21+
#define __CLC_BODY <clc_tan.inc>
22+
#include <clc/math/gentype.inc>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#if __CLC_FPSIZE == 32
10+
11+
_CLC_DEF _CLC_OVERLOAD __CLC_GENTYPE __clc_tan(__CLC_GENTYPE x) {
12+
__CLC_GENTYPE absx = __clc_fabs(x);
13+
__CLC_UINTN x_signbit = __CLC_AS_UINTN(x) & SIGNBIT_SP32;
14+
15+
__CLC_GENTYPE r0, r1;
16+
__CLC_INTN regn = __clc_argReductionS(&r0, &r1, absx);
17+
18+
__CLC_GENTYPE t = __clc_tanf_piby4(r0 + r1, regn);
19+
t = __CLC_AS_GENTYPE(__CLC_AS_UINTN(t) ^ x_signbit);
20+
21+
t = __clc_select(t, __CLC_GENTYPE_NAN, __clc_isnan(x) || __clc_isinf(x));
22+
// Take care of subnormals
23+
t = (x == 0.0f) ? x : t;
24+
return t;
25+
}
26+
27+
#elif __CLC_FPSIZE == 64
28+
29+
_CLC_DEF _CLC_OVERLOAD __CLC_GENTYPE __clc_tan(__CLC_GENTYPE x) {
30+
__CLC_GENTYPE y = __clc_fabs(x);
31+
32+
__CLC_BIT_INTN is_medium = y < 0x1.0p+30;
33+
34+
__CLC_INTN regn_m, regn_l;
35+
__CLC_GENTYPE r_m, r_l, rr_m, rr_l;
36+
37+
__clc_remainder_piby2_medium(y, &r_m, &rr_m, &regn_m);
38+
__clc_remainder_piby2_large(y, &r_l, &rr_l, &regn_l);
39+
40+
__CLC_GENTYPE r = is_medium ? r_m : r_l;
41+
__CLC_GENTYPE rr = is_medium ? rr_m : rr_l;
42+
__CLC_INTN regn = __CLC_CONVERT_INTN(is_medium) ? regn_m : regn_l;
43+
44+
__CLC_GENTYPE lead, tail;
45+
__clc_tan_piby4(r, rr, &lead, &tail);
46+
47+
__CLC_LONGN t =
48+
__CLC_AS_LONGN(__CLC_CONVERT_BIT_INTN((regn & 1) != 0) ? tail : lead);
49+
t ^= __CLC_CONVERT_BIT_INTN(x < 0.0) << 63;
50+
51+
return __clc_isnan(x) || __clc_isinf(x) ? __CLC_GENTYPE_NAN
52+
: __CLC_AS_GENTYPE(t);
53+
}
54+
55+
#elif __CLC_FPSIZE == 16
56+
57+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_tan(__CLC_GENTYPE x) {
58+
return __CLC_CONVERT_GENTYPE(__clc_tan(__CLC_CONVERT_FLOATN(x)));
59+
}
60+
61+
#endif

libclc/clspv/lib/SOURCES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ subnormal_config.cl
1616
../../generic/lib/math/atanh.cl
1717
../../generic/lib/math/atanpi.cl
1818
../../generic/lib/math/cbrt.cl
19-
../../generic/lib/math/clc_tan.cl
2019
../../generic/lib/math/cos.cl
2120
../../generic/lib/math/cosh.cl
2221
../../generic/lib/math/cospi.cl

libclc/generic/lib/SOURCES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ math/sincos.cl
146146
math/sinh.cl
147147
math/sinpi.cl
148148
math/sqrt.cl
149-
math/clc_tan.cl
150149
math/tan.cl
151150
math/tanh.cl
152151
math/tanpi.cl

libclc/generic/lib/math/clc_sw_unary.inc

Lines changed: 0 additions & 30 deletions
This file was deleted.

libclc/generic/lib/math/clc_tan.cl

Lines changed: 0 additions & 61 deletions
This file was deleted.

libclc/generic/lib/math/tan.cl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <clc/clc.h>
10+
#include <clc/math/clc_tan.h>
1011

11-
#include <math/clc_tan.h>
12-
13-
#define __CLC_FUNC tan
14-
#define __CLC_BODY <clc_sw_unary.inc>
12+
#define FUNCTION tan
13+
#define __CLC_BODY <clc/shared/unary_def.inc>
1514
#include <clc/math/gentype.inc>

libclc/spirv/lib/SOURCES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ math/fma.cl
6565
../../generic/lib/math/sincos.cl
6666
../../generic/lib/math/sinh.cl
6767
../../generic/lib/math/sinpi.cl
68-
../../generic/lib/math/clc_tan.cl
6968
../../generic/lib/math/tan.cl
7069
../../generic/lib/math/tanh.cl
7170
../../generic/lib/math/tanpi.cl

0 commit comments

Comments
 (0)