about summary refs log tree commit diff
path: root/sysdeps/x86_64/fpu/multiarch/svml_d_acos2_core_sse4.S
blob: a46ddc136ec2c78451e1991b38b62b2570a6042f (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
302
/* Function acos vectorized with SSE4.
   Copyright (C) 2021-2023 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/.  */

/*
 * ALGORITHM DESCRIPTION:
 *
 *      SelMask = (|x| >= 0.5) ? 1 : 0;
 *      R = SelMask ? sqrt(0.5 - 0.5*|x|) : |x|
 *      acos(|x|) = SelMask ? 2*Poly(R) : (Pi/2 - Poly(R))
 *      acos(x) = sign(x) ? (Pi - acos(|x|)) : acos(|x|)
 *
 */

/* Offsets for data table __svml_dacos_data_internal
 */
#define SgnBit				0
#define OneHalf				16
#define SmallNorm			32
#define MOne				48
#define Two				64
#define sqrt_coeff			80
#define poly_coeff			144
#define PiH				336
#define Pi2H				352

#include <sysdep.h>

	.section .text.sse4, "ax", @progbits
ENTRY(_ZGVbN2v_acos_sse4)
	subq	$72, %rsp
	cfi_def_cfa_offset(80)
	movaps	%xmm0, %xmm5
	movups	__svml_dacos_data_internal(%rip), %xmm3
	movups	OneHalf+__svml_dacos_data_internal(%rip), %xmm6

	/* x = -|arg| */
	movaps	%xmm3, %xmm4
	orps	%xmm5, %xmm4

	/* Y = 0.5 + 0.5*(-x) */
	movaps	%xmm6, %xmm7
	mulpd	%xmm4, %xmm7
	addpd	%xmm7, %xmm6

	/* S ~ 2*sqrt(Y) */
	cvtpd2ps %xmm6, %xmm9
	movlhps	%xmm9, %xmm9

	/* x^2 */
	movaps	%xmm4, %xmm0
	rsqrtps	%xmm9, %xmm10
	mulpd	%xmm4, %xmm0
	cvtps2pd %xmm10, %xmm11
	minpd	%xmm6, %xmm0
	movaps	%xmm6, %xmm1
	movaps	%xmm0, %xmm2
	cmpltpd	SmallNorm+__svml_dacos_data_internal(%rip), %xmm1
	cmpnltpd %xmm6, %xmm2
	addpd	%xmm6, %xmm6
	andnps	%xmm11, %xmm1
	movaps	%xmm0, %xmm11
	movaps	%xmm1, %xmm12
	andps	%xmm5, %xmm3
	mulpd	%xmm1, %xmm12
	mulpd	%xmm6, %xmm1
	mulpd	%xmm12, %xmm6
	mulpd	%xmm0, %xmm11
	subpd	Two+__svml_dacos_data_internal(%rip), %xmm6
	movups	sqrt_coeff+__svml_dacos_data_internal(%rip), %xmm13
	movaps	%xmm6, %xmm14
	mulpd	%xmm6, %xmm13
	mulpd	%xmm1, %xmm14
	addpd	sqrt_coeff+16+__svml_dacos_data_internal(%rip), %xmm13
	mulpd	%xmm6, %xmm13
	addpd	sqrt_coeff+32+__svml_dacos_data_internal(%rip), %xmm13
	mulpd	%xmm13, %xmm6

	/* polynomial */
	movups	poly_coeff+__svml_dacos_data_internal(%rip), %xmm15
	movaps	%xmm11, %xmm7
	mulpd	%xmm0, %xmm15
	addpd	sqrt_coeff+48+__svml_dacos_data_internal(%rip), %xmm6
	addpd	poly_coeff+16+__svml_dacos_data_internal(%rip), %xmm15
	mulpd	%xmm11, %xmm7
	mulpd	%xmm6, %xmm14
	mulpd	%xmm11, %xmm15
	subpd	%xmm14, %xmm1
	movups	MOne+__svml_dacos_data_internal(%rip), %xmm8
	andps	%xmm2, %xmm1

	/* NaN processed in special branch (so wind test passed) */
	cmpnlepd %xmm4, %xmm8
	movmskpd %xmm8, %edx

	/* X<X^2 iff X<0 */
	movaps	%xmm5, %xmm12
	movups	poly_coeff+32+__svml_dacos_data_internal(%rip), %xmm8
	movaps	%xmm2, %xmm13
	movups	poly_coeff+64+__svml_dacos_data_internal(%rip), %xmm6
	mulpd	%xmm0, %xmm8
	mulpd	%xmm0, %xmm6
	addpd	poly_coeff+48+__svml_dacos_data_internal(%rip), %xmm8
	addpd	poly_coeff+80+__svml_dacos_data_internal(%rip), %xmm6
	cmpltpd	%xmm0, %xmm12
	addpd	%xmm15, %xmm8
	mulpd	%xmm11, %xmm6
	mulpd	%xmm7, %xmm8
	movups	poly_coeff+96+__svml_dacos_data_internal(%rip), %xmm9
	mulpd	%xmm0, %xmm9
	addpd	poly_coeff+112+__svml_dacos_data_internal(%rip), %xmm9
	addpd	%xmm6, %xmm9
	movups	poly_coeff+128+__svml_dacos_data_internal(%rip), %xmm10
	movaps	%xmm2, %xmm6
	mulpd	%xmm0, %xmm10
	addpd	%xmm8, %xmm9
	addpd	poly_coeff+144+__svml_dacos_data_internal(%rip), %xmm10
	mulpd	%xmm11, %xmm9
	movups	poly_coeff+160+__svml_dacos_data_internal(%rip), %xmm14
	andnps	%xmm4, %xmm6
	addpd	%xmm9, %xmm10
	mulpd	%xmm0, %xmm14
	mulpd	%xmm10, %xmm11
	addpd	poly_coeff+176+__svml_dacos_data_internal(%rip), %xmm14
	addpd	%xmm11, %xmm14
	mulpd	%xmm0, %xmm14
	orps	%xmm1, %xmm6
	pxor	%xmm3, %xmm6
	mulpd	%xmm6, %xmm14
	movups	PiH+__svml_dacos_data_internal(%rip), %xmm0
	andps	%xmm2, %xmm0
	andnps	Pi2H+__svml_dacos_data_internal(%rip), %xmm13
	andps	%xmm12, %xmm0
	addpd	%xmm13, %xmm0
	addpd	%xmm14, %xmm6
	addpd	%xmm6, %xmm0
	testl	%edx, %edx

	/* Go to special inputs processing branch */
	jne	L(SPECIAL_VALUES_BRANCH)
	# LOE rbx rbp r12 r13 r14 r15 edx xmm0 xmm5

	/* Restore registers
	 * and exit the function
	 */

L(EXIT):
	addq	$72, %rsp
	cfi_def_cfa_offset(8)
	ret
	cfi_def_cfa_offset(80)

	/* Branch to process
	 * special inputs
	 */

L(SPECIAL_VALUES_BRANCH):
	movups	%xmm5, 32(%rsp)
	movups	%xmm0, 48(%rsp)
	# LOE rbx rbp r12 r13 r14 r15 edx

	xorl	%eax, %eax
	movq	%r12, 16(%rsp)
	cfi_offset(12, -64)
	movl	%eax, %r12d
	movq	%r13, 8(%rsp)
	cfi_offset(13, -72)
	movl	%edx, %r13d
	movq	%r14, (%rsp)
	cfi_offset(14, -80)
	# LOE rbx rbp r15 r12d r13d

	/* Range mask
	 * bits check
	 */

L(RANGEMASK_CHECK):
	btl	%r12d, %r13d

	/* Call scalar math function */
	jc	L(SCALAR_MATH_CALL)
	# LOE rbx rbp r15 r12d r13d

	/* Special inputs
	 * processing loop
	 */

L(SPECIAL_VALUES_LOOP):
	incl	%r12d
	cmpl	$2, %r12d

	/* Check bits in range mask */
	jl	L(RANGEMASK_CHECK)
	# LOE rbx rbp r15 r12d r13d

	movq	16(%rsp), %r12
	cfi_restore(12)
	movq	8(%rsp), %r13
	cfi_restore(13)
	movq	(%rsp), %r14
	cfi_restore(14)
	movups	48(%rsp), %xmm0

	/* Go to exit */
	jmp	L(EXIT)
	cfi_offset(12, -64)
	cfi_offset(13, -72)
	cfi_offset(14, -80)
	# LOE rbx rbp r12 r13 r14 r15 xmm0

	/* Scalar math function call
	 * to process special input
	 */

L(SCALAR_MATH_CALL):
	movl	%r12d, %r14d
	movsd	32(%rsp, %r14, 8), %xmm0
	call	acos@PLT
	# LOE rbx rbp r14 r15 r12d r13d xmm0

	movsd	%xmm0, 48(%rsp, %r14, 8)

	/* Process special inputs in loop */
	jmp	L(SPECIAL_VALUES_LOOP)
	# LOE rbx rbp r15 r12d r13d
END(_ZGVbN2v_acos_sse4)

	.section .rodata, "a"
	.align	16

#ifdef __svml_dacos_data_internal_typedef
typedef unsigned int VUINT32;
typedef struct {
	__declspec(align(16)) VUINT32 SgnBit[2][2];
	__declspec(align(16)) VUINT32 OneHalf[2][2];
	__declspec(align(16)) VUINT32 SmallNorm[2][2];
	__declspec(align(16)) VUINT32 MOne[2][2];
	__declspec(align(16)) VUINT32 Two[2][2];
	__declspec(align(16)) VUINT32 sqrt_coeff[4][2][2];
	__declspec(align(16)) VUINT32 poly_coeff[12][2][2];
	__declspec(align(16)) VUINT32 PiH[2][2];
	__declspec(align(16)) VUINT32 Pi2H[2][2];
} __svml_dacos_data_internal;
#endif
__svml_dacos_data_internal:
	/* SgnBit */
	.quad	0x8000000000000000, 0x8000000000000000
	/* OneHalf */
	.align	16
	.quad	0x3fe0000000000000, 0x3fe0000000000000
	/* SmallNorm */
	.align	16
	.quad	0x3000000000000000, 0x3000000000000000
	/* MOne */
	.align	16
	.quad	0xbff0000000000000, 0xbff0000000000000
	/* Two */
	.align	16
	.quad	0x4000000000000000, 0x4000000000000000
	/* sqrt_coeff[4] */
	.align	16
	.quad	0xbf918000993B24C3, 0xbf918000993B24C3 /* sqrt_coeff4 */
	.quad	0x3fa400006F70D42D, 0x3fa400006F70D42D /* sqrt_coeff3 */
	.quad	0xbfb7FFFFFFFFFE97, 0xbfb7FFFFFFFFFE97 /* sqrt_coeff2 */
	.quad	0x3fcFFFFFFFFFFF9D, 0x3fcFFFFFFFFFFF9D /* sqrt_coeff1 */
	/* poly_coeff[12] */
	.align	16
	.quad	0x3fa07520C70EB909, 0x3fa07520C70EB909 /* poly_coeff12 */
	.quad	0xbf90FB17F7DBB0ED, 0xbf90FB17F7DBB0ED /* poly_coeff11 */
	.quad	0x3f943F44BFBC3BAE, 0x3f943F44BFBC3BAE /* poly_coeff10 */
	.quad	0x3f7A583395D45ED5, 0x3f7A583395D45ED5 /* poly_coeff9 */
	.quad	0x3f88F8DC2AFCCAD6, 0x3f88F8DC2AFCCAD6 /* poly_coeff8 */
	.quad	0x3f8C6DBBCB88BD57, 0x3f8C6DBBCB88BD57 /* poly_coeff7 */
	.quad	0x3f91C6DCF538AD2E, 0x3f91C6DCF538AD2E /* poly_coeff6 */
	.quad	0x3f96E89CEBDEFadd, 0x3f96E89CEBDEFadd /* poly_coeff5 */
	.quad	0x3f9F1C72E13AD8BE, 0x3f9F1C72E13AD8BE /* poly_coeff4 */
	.quad	0x3fa6DB6DB3B445F8, 0x3fa6DB6DB3B445F8 /* poly_coeff3 */
	.quad	0x3fb333333337E0DE, 0x3fb333333337E0DE /* poly_coeff2 */
	.quad	0x3fc555555555529C, 0x3fc555555555529C /* poly_coeff1 */
	/* PiH */
	.align	16
	.quad	0x400921fb54442d18, 0x400921fb54442d18
	/* Pi2H */
	.align	16
	.quad	0x3ff921fb54442d18, 0x3ff921fb54442d18
	.align	16
	.type	__svml_dacos_data_internal, @object
	.size	__svml_dacos_data_internal, .-__svml_dacos_data_internal