1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
/* Generic helpers for evaluating polynomials with various schemes.
Copyright (C) 2023-2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#ifndef VTYPE
# error Cannot use poly_generic without defining VTYPE
#endif
#ifndef VWRAP
# error Cannot use poly_generic without defining VWRAP
#endif
#ifndef FMA
# error Cannot use poly_generic without defining FMA
#endif
static inline VTYPE VWRAP (pairwise_poly_3) (VTYPE x, VTYPE x2,
const VTYPE *poly)
{
/* At order 3, Estrin and Pairwise Horner are identical. */
VTYPE p01 = FMA (poly[1], x, poly[0]);
VTYPE p23 = FMA (poly[3], x, poly[2]);
return FMA (p23, x2, p01);
}
static inline VTYPE VWRAP (estrin_4) (VTYPE x, VTYPE x2, VTYPE x4,
const VTYPE *poly)
{
VTYPE p03 = VWRAP (pairwise_poly_3) (x, x2, poly);
return FMA (poly[4], x4, p03);
}
static inline VTYPE VWRAP (estrin_5) (VTYPE x, VTYPE x2, VTYPE x4,
const VTYPE *poly)
{
VTYPE p03 = VWRAP (pairwise_poly_3) (x, x2, poly);
VTYPE p45 = FMA (poly[5], x, poly[4]);
return FMA (p45, x4, p03);
}
static inline VTYPE VWRAP (estrin_6) (VTYPE x, VTYPE x2, VTYPE x4,
const VTYPE *poly)
{
VTYPE p03 = VWRAP (pairwise_poly_3) (x, x2, poly);
VTYPE p45 = FMA (poly[5], x, poly[4]);
VTYPE p46 = FMA (poly[6], x2, p45);
return FMA (p46, x4, p03);
}
static inline VTYPE VWRAP (estrin_7) (VTYPE x, VTYPE x2, VTYPE x4,
const VTYPE *poly)
{
VTYPE p03 = VWRAP (pairwise_poly_3) (x, x2, poly);
VTYPE p47 = VWRAP (pairwise_poly_3) (x, x2, poly + 4);
return FMA (p47, x4, p03);
}
static inline VTYPE VWRAP (estrin_8) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
const VTYPE *poly)
{
return FMA (poly[8], x8, VWRAP (estrin_7) (x, x2, x4, poly));
}
static inline VTYPE VWRAP (estrin_9) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
const VTYPE *poly)
{
VTYPE p89 = FMA (poly[9], x, poly[8]);
return FMA (p89, x8, VWRAP (estrin_7) (x, x2, x4, poly));
}
static inline VTYPE VWRAP (estrin_10) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
const VTYPE *poly)
{
VTYPE p89 = FMA (poly[9], x, poly[8]);
VTYPE p8_10 = FMA (poly[10], x2, p89);
return FMA (p8_10, x8, VWRAP (estrin_7) (x, x2, x4, poly));
}
static inline VTYPE VWRAP (estrin_11) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
const VTYPE *poly)
{
VTYPE p8_11 = VWRAP (pairwise_poly_3) (x, x2, poly + 8);
return FMA (p8_11, x8, VWRAP (estrin_7) (x, x2, x4, poly));
}
static inline VTYPE VWRAP (estrin_12) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
const VTYPE *poly)
{
return FMA (VWRAP (estrin_4) (x, x2, x4, poly + 8), x8,
VWRAP (estrin_7) (x, x2, x4, poly));
}
static inline VTYPE VWRAP (estrin_13) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
const VTYPE *poly)
{
return FMA (VWRAP (estrin_5) (x, x2, x4, poly + 8), x8,
VWRAP (estrin_7) (x, x2, x4, poly));
}
static inline VTYPE VWRAP (estrin_14) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
const VTYPE *poly)
{
return FMA (VWRAP (estrin_6) (x, x2, x4, poly + 8), x8,
VWRAP (estrin_7) (x, x2, x4, poly));
}
static inline VTYPE VWRAP (estrin_15) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
const VTYPE *poly)
{
return FMA (VWRAP (estrin_7) (x, x2, x4, poly + 8), x8,
VWRAP (estrin_7) (x, x2, x4, poly));
}
static inline VTYPE VWRAP (estrin_16) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
VTYPE x16, const VTYPE *poly)
{
return FMA (poly[16], x16, VWRAP (estrin_15) (x, x2, x4, x8, poly));
}
static inline VTYPE VWRAP (estrin_17) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
VTYPE x16, const VTYPE *poly)
{
VTYPE p16_17 = FMA (poly[17], x, poly[16]);
return FMA (p16_17, x16, VWRAP (estrin_15) (x, x2, x4, x8, poly));
}
static inline VTYPE VWRAP (estrin_18) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
VTYPE x16, const VTYPE *poly)
{
VTYPE p16_17 = FMA (poly[17], x, poly[16]);
VTYPE p16_18 = FMA (poly[18], x2, p16_17);
return FMA (p16_18, x16, VWRAP (estrin_15) (x, x2, x4, x8, poly));
}
static inline VTYPE VWRAP (estrin_19) (VTYPE x, VTYPE x2, VTYPE x4, VTYPE x8,
VTYPE x16, const VTYPE *poly)
{
VTYPE p16_19 = VWRAP (pairwise_poly_3) (x, x2, poly + 16);
return FMA (p16_19, x16, VWRAP (estrin_15) (x, x2, x4, x8, poly));
}
static inline VTYPE VWRAP (horner_3) (VTYPE x, const VTYPE *poly)
{
VTYPE p = FMA (poly[3], x, poly[2]);
p = FMA (x, p, poly[1]);
p = FMA (x, p, poly[0]);
return p;
}
static inline VTYPE VWRAP (horner_4) (VTYPE x, const VTYPE *poly)
{
VTYPE p = FMA (poly[4], x, poly[3]);
p = FMA (x, p, poly[2]);
p = FMA (x, p, poly[1]);
p = FMA (x, p, poly[0]);
return p;
}
static inline VTYPE VWRAP (horner_5) (VTYPE x, const VTYPE *poly)
{
return FMA (x, VWRAP (horner_4) (x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (horner_6) (VTYPE x, const VTYPE *poly)
{
return FMA (x, VWRAP (horner_5) (x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (horner_7) (VTYPE x, const VTYPE *poly)
{
return FMA (x, VWRAP (horner_6) (x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (horner_8) (VTYPE x, const VTYPE *poly)
{
return FMA (x, VWRAP (horner_7) (x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (horner_9) (VTYPE x, const VTYPE *poly)
{
return FMA (x, VWRAP (horner_8) (x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (horner_10) (VTYPE x, const VTYPE *poly)
{
return FMA (x, VWRAP (horner_9) (x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (horner_11) (VTYPE x, const VTYPE *poly)
{
return FMA (x, VWRAP (horner_10) (x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (horner_12) (VTYPE x, const VTYPE *poly)
{
return FMA (x, VWRAP (horner_11) (x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (pw_horner_4) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p01 = FMA (poly[1], x, poly[0]);
VTYPE p23 = FMA (poly[3], x, poly[2]);
VTYPE p;
p = FMA (x2, poly[4], p23);
p = FMA (x2, p, p01);
return p;
}
static inline VTYPE VWRAP (pw_horner_5) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p01 = FMA (poly[1], x, poly[0]);
VTYPE p23 = FMA (poly[3], x, poly[2]);
VTYPE p45 = FMA (poly[5], x, poly[4]);
VTYPE p;
p = FMA (x2, p45, p23);
p = FMA (x2, p, p01);
return p;
}
static inline VTYPE VWRAP (pw_horner_6) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p26 = VWRAP (pw_horner_4) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p26, p01);
}
static inline VTYPE VWRAP (pw_horner_7) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p27 = VWRAP (pw_horner_5) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p27, p01);
}
static inline VTYPE VWRAP (pw_horner_8) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p28 = VWRAP (pw_horner_6) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p28, p01);
}
static inline VTYPE VWRAP (pw_horner_9) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p29 = VWRAP (pw_horner_7) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p29, p01);
}
static inline VTYPE VWRAP (pw_horner_10) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p2_10 = VWRAP (pw_horner_8) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p2_10, p01);
}
static inline VTYPE VWRAP (pw_horner_11) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p2_11 = VWRAP (pw_horner_9) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p2_11, p01);
}
static inline VTYPE VWRAP (pw_horner_12) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p2_12 = VWRAP (pw_horner_10) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p2_12, p01);
}
static inline VTYPE VWRAP (pw_horner_13) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p2_13 = VWRAP (pw_horner_11) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p2_13, p01);
}
static inline VTYPE VWRAP (pw_horner_14) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p2_14 = VWRAP (pw_horner_12) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p2_14, p01);
}
static inline VTYPE VWRAP (pw_horner_15) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p2_15 = VWRAP (pw_horner_13) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p2_15, p01);
}
static inline VTYPE VWRAP (pw_horner_16) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p2_16 = VWRAP (pw_horner_14) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p2_16, p01);
}
static inline VTYPE VWRAP (pw_horner_17) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p2_17 = VWRAP (pw_horner_15) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p2_17, p01);
}
static inline VTYPE VWRAP (pw_horner_18) (VTYPE x, VTYPE x2, const VTYPE *poly)
{
VTYPE p2_18 = VWRAP (pw_horner_16) (x, x2, poly + 2);
VTYPE p01 = FMA (poly[1], x, poly[0]);
return FMA (x2, p2_18, p01);
}
|