Skip to content

Commit 18836cf

Browse files
wenju-heaokblast
authored andcommitted
[libclc] Move functions definition from header clc_sincos_piby4.inc into clc_sincos_helpers.cl (llvm#164028)
inline functions defined in clc_sincos_piby4.inc miss static specifier and are deleted by EliminateAvailableExternallyPass when not inlined. This PR fix the problem by removing inline and moving function definition into clc/lib/generic/math/clc_sincos_helpers.cl. It makes sense to put all sin/cos helpers definitions in one file clc_sincos_helpers.cl.
1 parent 0557fd4 commit 18836cf

File tree

12 files changed

+174
-194
lines changed

12 files changed

+174
-194
lines changed

libclc/clc/include/clc/math/clc_sincos_helpers.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ _CLC_DECL _CLC_OVERLOAD __CLC_FLOATN __clc_sinf_piby4(__CLC_FLOATN x,
1010
__CLC_FLOATN y);
1111
_CLC_DECL _CLC_OVERLOAD __CLC_FLOATN __clc_cosf_piby4(__CLC_FLOATN x,
1212
__CLC_FLOATN y);
13+
14+
_CLC_DECL _CLC_OVERLOAD void __clc_sincos_piby4(__CLC_FLOATN x,
15+
private __CLC_FLOATN *sinval,
16+
private __CLC_FLOATN *cosval);
17+
1318
_CLC_DECL _CLC_OVERLOAD __CLC_FLOATN __clc_tanf_piby4(__CLC_FLOATN x,
1419
__CLC_INTN regn);
1520

libclc/clc/include/clc/math/clc_sincos_helpers_fp64.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
_CLC_DECL _CLC_OVERLOAD void __clc_sincos_piby4(__CLC_DOUBLEN x,
10+
__CLC_DOUBLEN xx,
11+
private __CLC_DOUBLEN *sinval,
12+
private __CLC_DOUBLEN *cosval);
13+
14+
_CLC_DECL _CLC_OVERLOAD void __clc_tan_piby4(__CLC_DOUBLEN x, __CLC_DOUBLEN xx,
15+
private __CLC_DOUBLEN *leadval,
16+
private __CLC_DOUBLEN *tailval);
17+
918
_CLC_DECL _CLC_OVERLOAD void
1019
__clc_remainder_piby2_medium(__CLC_DOUBLEN x, private __CLC_DOUBLEN *r,
1120
private __CLC_DOUBLEN *rr,

libclc/clc/include/clc/math/clc_sincos_piby4.h

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

libclc/clc/include/clc/math/clc_sincos_piby4.inc

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

libclc/clc/lib/generic/math/clc_cos.cl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <clc/float/definitions.h>
1111
#include <clc/math/clc_fabs.h>
1212
#include <clc/math/clc_sincos_helpers.h>
13-
#include <clc/math/clc_sincos_piby4.h>
1413
#include <clc/math/math.h>
1514
#include <clc/relational/clc_isinf.h>
1615
#include <clc/relational/clc_isnan.h>

libclc/clc/lib/generic/math/clc_cospi.cl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <clc/internal/clc.h>
1212
#include <clc/math/clc_fabs.h>
1313
#include <clc/math/clc_sincos_helpers.h>
14-
#include <clc/math/clc_sincos_piby4.h>
1514
#include <clc/math/math.h>
1615

1716
#define __CLC_BODY <clc_cospi.inc>

libclc/clc/lib/generic/math/clc_sin.cl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <clc/internal/clc.h>
1212
#include <clc/math/clc_fabs.h>
1313
#include <clc/math/clc_sincos_helpers.h>
14-
#include <clc/math/clc_sincos_piby4.h>
1514
#include <clc/math/clc_trunc.h>
1615
#include <clc/math/math.h>
1716
#include <clc/math/tables.h>

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,43 @@ _CLC_DEF _CLC_OVERLOAD __CLC_FLOATN __clc_cosf_piby4(__CLC_FLOATN x,
7474
return ret;
7575
}
7676

77+
// Evaluate single precisions sin and cos of value in interval [-pi/4, pi/4]
78+
_CLC_DEF _CLC_OVERLOAD void __clc_sincos_piby4(__CLC_FLOATN x,
79+
private __CLC_FLOATN *sinval,
80+
private __CLC_FLOATN *cosval) {
81+
// Taylor series for sin(x) is x - x^3/3! + x^5/5! - x^7/7! ...
82+
// = x * (1 - x^2/3! + x^4/5! - x^6/7! ...
83+
// = x * f(w)
84+
// where w = x*x and f(w) = (1 - w/3! + w^2/5! - w^3/7! ...
85+
// We use a minimax approximation of (f(w) - 1) / w
86+
// because this produces an expansion in even powers of x.
87+
88+
// Taylor series for cos(x) is 1 - x^2/2! + x^4/4! - x^6/6! ...
89+
// = f(w)
90+
// where w = x*x and f(w) = (1 - w/2! + w^2/4! - w^3/6! ...
91+
// We use a minimax approximation of (f(w) - 1 + w/2) / (w*w)
92+
// because this produces an expansion in even powers of x.
93+
94+
const __CLC_FLOATN sc1 = -0.166666666638608441788607926e0F;
95+
const __CLC_FLOATN sc2 = 0.833333187633086262120839299e-2F;
96+
const __CLC_FLOATN sc3 = -0.198400874359527693921333720e-3F;
97+
const __CLC_FLOATN sc4 = 0.272500015145584081596826911e-5F;
98+
99+
const __CLC_FLOATN cc1 = 0.41666666664325175238031e-1F;
100+
const __CLC_FLOATN cc2 = -0.13888887673175665567647e-2F;
101+
const __CLC_FLOATN cc3 = 0.24800600878112441958053e-4F;
102+
const __CLC_FLOATN cc4 = -0.27301013343179832472841e-6F;
103+
104+
__CLC_FLOATN x2 = x * x;
105+
106+
*sinval = __clc_mad(
107+
x * x2, __clc_mad(x2, __clc_mad(x2, __clc_mad(x2, sc4, sc3), sc2), sc1),
108+
x);
109+
*cosval = __clc_mad(
110+
x2 * x2, __clc_mad(x2, __clc_mad(x2, __clc_mad(x2, cc4, cc3), cc2), cc1),
111+
__clc_mad(x2, -0.5f, 1.0f));
112+
}
113+
77114
_CLC_DEF _CLC_OVERLOAD __CLC_FLOATN __clc_tanf_piby4(__CLC_FLOATN x,
78115
__CLC_INTN regn) {
79116
// Core Remez [1,2] approximation to tan(x) on the interval [0,pi/4].

0 commit comments

Comments
 (0)