aboutsummaryrefslogtreecommitdiff
path: root/pl/math/poly_sve_generic.h
blob: b568e4cddff38af19f90a09c73f250997172043a (plain) (blame)
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
 * Helpers for evaluating polynomials with various schemes - specific to SVE
 * but precision-agnostic.
 *
 * Copyright (c) 2023, Arm Limited.
 * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
 */

#ifndef VTYPE
# error Cannot use poly_generic without defining VTYPE
#endif
#ifndef STYPE
# error Cannot use poly_generic without defining STYPE
#endif
#ifndef VWRAP
# error Cannot use poly_generic without defining VWRAP
#endif
#ifndef DUP
# error Cannot use poly_generic without defining DUP
#endif

static inline VTYPE VWRAP (pairwise_poly_3) (svbool_t pg, VTYPE x, VTYPE x2,
					     const STYPE *poly)
{
  /* At order 3, Estrin and Pairwise Horner are identical.  */
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  VTYPE p23 = svmla_x (pg, DUP (poly[2]), x, poly[3]);
  return svmla_x (pg, p01, p23, x2);
}

static inline VTYPE VWRAP (estrin_4) (svbool_t pg, VTYPE x, VTYPE x2, VTYPE x4,
				      const STYPE *poly)
{
  VTYPE p03 = VWRAP (pairwise_poly_3) (pg, x, x2, poly);
  return svmla_x (pg, p03, x4, poly[4]);
}
static inline VTYPE VWRAP (estrin_5) (svbool_t pg, VTYPE x, VTYPE x2, VTYPE x4,
				      const STYPE *poly)
{
  VTYPE p03 = VWRAP (pairwise_poly_3) (pg, x, x2, poly);
  VTYPE p45 = svmla_x (pg, DUP (poly[4]), x, poly[5]);
  return svmla_x (pg, p03, p45, x4);
}
static inline VTYPE VWRAP (estrin_6) (svbool_t pg, VTYPE x, VTYPE x2, VTYPE x4,
				      const STYPE *poly)
{
  VTYPE p03 = VWRAP (pairwise_poly_3) (pg, x, x2, poly);
  VTYPE p45 = svmla_x (pg, DUP (poly[4]), x, poly[5]);
  VTYPE p46 = svmla_x (pg, p45, x, poly[6]);
  return svmla_x (pg, p03, p46, x4);
}
static inline VTYPE VWRAP (estrin_7) (svbool_t pg, VTYPE x, VTYPE x2, VTYPE x4,
				      const STYPE *poly)
{
  VTYPE p03 = VWRAP (pairwise_poly_3) (pg, x, x2, poly);
  VTYPE p47 = VWRAP (pairwise_poly_3) (pg, x, x2, poly + 4);
  return svmla_x (pg, p03, p47, x4);
}
static inline VTYPE VWRAP (estrin_8) (svbool_t pg, VTYPE x, VTYPE x2, VTYPE x4,
				      VTYPE x8, const STYPE *poly)
{
  return svmla_x (pg, VWRAP (estrin_7) (pg, x, x2, x4, poly), x8, poly[8]);
}
static inline VTYPE VWRAP (estrin_9) (svbool_t pg, VTYPE x, VTYPE x2, VTYPE x4,
				      VTYPE x8, const STYPE *poly)
{
  VTYPE p89 = svmla_x (pg, DUP (poly[8]), x, poly[9]);
  return svmla_x (pg, VWRAP (estrin_7) (pg, x, x2, x4, poly), p89, x8);
}
static inline VTYPE VWRAP (estrin_10) (svbool_t pg, VTYPE x, VTYPE x2,
				       VTYPE x4, VTYPE x8, const STYPE *poly)
{
  VTYPE p89 = svmla_x (pg, DUP (poly[8]), x, poly[9]);
  VTYPE p8_10 = svmla_x (pg, p89, x2, poly[10]);
  return svmla_x (pg, VWRAP (estrin_7) (pg, x, x2, x4, poly), p8_10, x8);
}
static inline VTYPE VWRAP (estrin_11) (svbool_t pg, VTYPE x, VTYPE x2,
				       VTYPE x4, VTYPE x8, const STYPE *poly)
{
  VTYPE p8_11 = VWRAP (pairwise_poly_3) (pg, x, x2, poly + 8);
  return svmla_x (pg, VWRAP (estrin_7) (pg, x, x2, x4, poly), p8_11, x8);
}
static inline VTYPE VWRAP (estrin_12) (svbool_t pg, VTYPE x, VTYPE x2,
				       VTYPE x4, VTYPE x8, const STYPE *poly)
{
  return svmla_x (pg, VWRAP (estrin_7) (pg, x, x2, x4, poly),
		  VWRAP (estrin_4) (pg, x, x2, x4, poly + 8), x8);
}
static inline VTYPE VWRAP (estrin_13) (svbool_t pg, VTYPE x, VTYPE x2,
				       VTYPE x4, VTYPE x8, const STYPE *poly)
{
  return svmla_x (pg, VWRAP (estrin_7) (pg, x, x2, x4, poly),
		  VWRAP (estrin_5) (pg, x, x2, x4, poly + 8), x8);
}
static inline VTYPE VWRAP (estrin_14) (svbool_t pg, VTYPE x, VTYPE x2,
				       VTYPE x4, VTYPE x8, const STYPE *poly)
{
  return svmla_x (pg, VWRAP (estrin_7) (pg, x, x2, x4, poly),
		  VWRAP (estrin_6) (pg, x, x2, x4, poly + 8), x8);
}
static inline VTYPE VWRAP (estrin_15) (svbool_t pg, VTYPE x, VTYPE x2,
				       VTYPE x4, VTYPE x8, const STYPE *poly)
{
  return svmla_x (pg, VWRAP (estrin_7) (pg, x, x2, x4, poly),
		  VWRAP (estrin_7) (pg, x, x2, x4, poly + 8), x8);
}
static inline VTYPE VWRAP (estrin_16) (svbool_t pg, VTYPE x, VTYPE x2,
				       VTYPE x4, VTYPE x8, VTYPE x16,
				       const STYPE *poly)
{
  return svmla_x (pg, VWRAP (estrin_15) (pg, x, x2, x4, x8, poly), x16,
		  poly[16]);
}
static inline VTYPE VWRAP (estrin_17) (svbool_t pg, VTYPE x, VTYPE x2,
				       VTYPE x4, VTYPE x8, VTYPE x16,
				       const STYPE *poly)
{
  VTYPE p16_17 = svmla_x (pg, DUP (poly[16]), x, poly[17]);
  return svmla_x (pg, VWRAP (estrin_15) (pg, x, x2, x4, x8, poly), p16_17,
		  x16);
}
static inline VTYPE VWRAP (estrin_18) (svbool_t pg, VTYPE x, VTYPE x2,
				       VTYPE x4, VTYPE x8, VTYPE x16,
				       const STYPE *poly)
{
  VTYPE p16_17 = svmla_x (pg, DUP (poly[16]), x, poly[17]);
  VTYPE p16_18 = svmla_x (pg, p16_17, x2, poly[18]);
  return svmla_x (pg, VWRAP (estrin_15) (pg, x, x2, x4, x8, poly), p16_18,
		  x16);
}
static inline VTYPE VWRAP (estrin_19) (svbool_t pg, VTYPE x, VTYPE x2,
				       VTYPE x4, VTYPE x8, VTYPE x16,
				       const STYPE *poly)
{
  return svmla_x (pg, VWRAP (estrin_15) (pg, x, x2, x4, x8, poly),
		  VWRAP (pairwise_poly_3) (pg, x, x2, poly + 16), x16);
}

static inline VTYPE VWRAP (horner_3) (svbool_t pg, VTYPE x, const STYPE *poly)
{
  VTYPE p = svmla_x (pg, DUP (poly[2]), x, poly[3]);
  p = svmad_x (pg, x, p, poly[1]);
  p = svmad_x (pg, x, p, poly[0]);
  return p;
}
static inline VTYPE VWRAP (horner_4) (svbool_t pg, VTYPE x, const STYPE *poly)
{
  VTYPE p = svmla_x (pg, DUP (poly[3]), x, poly[4]);
  p = svmad_x (pg, x, p, poly[2]);
  p = svmad_x (pg, x, p, poly[1]);
  p = svmad_x (pg, x, p, poly[0]);
  return p;
}
static inline VTYPE VWRAP (horner_5) (svbool_t pg, VTYPE x, const STYPE *poly)
{
  return svmad_x (pg, x, VWRAP (horner_4) (pg, x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (horner_6) (svbool_t pg, VTYPE x, const STYPE *poly)
{
  return svmad_x (pg, x, VWRAP (horner_5) (pg, x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (horner_7) (svbool_t pg, VTYPE x, const STYPE *poly)
{
  return svmad_x (pg, x, VWRAP (horner_6) (pg, x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (horner_8) (svbool_t pg, VTYPE x, const STYPE *poly)
{
  return svmad_x (pg, x, VWRAP (horner_7) (pg, x, poly + 1), poly[0]);
}
static inline VTYPE VWRAP (horner_9) (svbool_t pg, VTYPE x, const STYPE *poly)
{
  return svmad_x (pg, x, VWRAP (horner_8) (pg, x, poly + 1), poly[0]);
}
static inline VTYPE
sv_horner_10_f32_x (svbool_t pg, VTYPE x, const STYPE *poly)
{
  return svmad_x (pg, x, VWRAP (horner_9) (pg, x, poly + 1), poly[0]);
}
static inline VTYPE
sv_horner_11_f32_x (svbool_t pg, VTYPE x, const STYPE *poly)
{
  return svmad_x (pg, x, sv_horner_10_f32_x (pg, x, poly + 1), poly[0]);
}
static inline VTYPE
sv_horner_12_f32_x (svbool_t pg, VTYPE x, const STYPE *poly)
{
  return svmad_x (pg, x, sv_horner_11_f32_x (pg, x, poly + 1), poly[0]);
}

static inline VTYPE VWRAP (pw_horner_4) (svbool_t pg, VTYPE x, VTYPE x2,
					 const STYPE *poly)
{
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  VTYPE p23 = svmla_x (pg, DUP (poly[2]), x, poly[3]);
  VTYPE p;
  p = svmla_x (pg, p23, x2, poly[4]);
  p = svmla_x (pg, p01, x2, p);
  return p;
}
static inline VTYPE VWRAP (pw_horner_5) (svbool_t pg, VTYPE x, VTYPE x2,
					 const STYPE *poly)
{
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  VTYPE p23 = svmla_x (pg, DUP (poly[2]), x, poly[3]);
  VTYPE p45 = svmla_x (pg, DUP (poly[4]), x, poly[5]);
  VTYPE p;
  p = svmla_x (pg, p23, x2, p45);
  p = svmla_x (pg, p01, x2, p);
  return p;
}
static inline VTYPE VWRAP (pw_horner_6) (svbool_t pg, VTYPE x, VTYPE x2,
					 const STYPE *poly)
{
  VTYPE p26 = VWRAP (pw_horner_4) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p26);
}
static inline VTYPE VWRAP (pw_horner_7) (svbool_t pg, VTYPE x, VTYPE x2,
					 const STYPE *poly)
{
  VTYPE p27 = VWRAP (pw_horner_5) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p27);
}
static inline VTYPE VWRAP (pw_horner_8) (svbool_t pg, VTYPE x, VTYPE x2,
					 const STYPE *poly)
{
  VTYPE p28 = VWRAP (pw_horner_6) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p28);
}
static inline VTYPE VWRAP (pw_horner_9) (svbool_t pg, VTYPE x, VTYPE x2,
					 const STYPE *poly)
{
  VTYPE p29 = VWRAP (pw_horner_7) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p29);
}
static inline VTYPE VWRAP (pw_horner_10) (svbool_t pg, VTYPE x, VTYPE x2,
					  const STYPE *poly)
{
  VTYPE p2_10 = VWRAP (pw_horner_8) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p2_10);
}
static inline VTYPE VWRAP (pw_horner_11) (svbool_t pg, VTYPE x, VTYPE x2,
					  const STYPE *poly)
{
  VTYPE p2_11 = VWRAP (pw_horner_9) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p2_11);
}
static inline VTYPE VWRAP (pw_horner_12) (svbool_t pg, VTYPE x, VTYPE x2,
					  const STYPE *poly)
{
  VTYPE p2_12 = VWRAP (pw_horner_10) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p2_12);
}
static inline VTYPE VWRAP (pw_horner_13) (svbool_t pg, VTYPE x, VTYPE x2,
					  const STYPE *poly)
{
  VTYPE p2_13 = VWRAP (pw_horner_11) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p2_13);
}
static inline VTYPE VWRAP (pw_horner_14) (svbool_t pg, VTYPE x, VTYPE x2,
					  const STYPE *poly)
{
  VTYPE p2_14 = VWRAP (pw_horner_12) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p2_14);
}
static inline VTYPE VWRAP (pw_horner_15) (svbool_t pg, VTYPE x, VTYPE x2,
					  const STYPE *poly)
{
  VTYPE p2_15 = VWRAP (pw_horner_13) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p2_15);
}
static inline VTYPE VWRAP (pw_horner_16) (svbool_t pg, VTYPE x, VTYPE x2,
					  const STYPE *poly)
{
  VTYPE p2_16 = VWRAP (pw_horner_14) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p2_16);
}
static inline VTYPE VWRAP (pw_horner_17) (svbool_t pg, VTYPE x, VTYPE x2,
					  const STYPE *poly)
{
  VTYPE p2_17 = VWRAP (pw_horner_15) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p2_17);
}
static inline VTYPE VWRAP (pw_horner_18) (svbool_t pg, VTYPE x, VTYPE x2,
					  const STYPE *poly)
{
  VTYPE p2_18 = VWRAP (pw_horner_16) (pg, x, x2, poly + 2);
  VTYPE p01 = svmla_x (pg, DUP (poly[0]), x, poly[1]);
  return svmla_x (pg, p01, x2, p2_18);
}