1 /* Function hypotf vectorized with AVX-512.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 https://www.gnu.org/licenses/. */
20 * ALGORITHM DESCRIPTION:
24 * Calculate z = (x*x+y*y)
25 * Calculate reciplicle sqrt (z)
26 * Calculate make two NR iterations
30 * Multiprecision branch for _HA_ only
31 * Remove sigm from both arguments
32 * Find maximum (_x) and minimum (_y) (by abs value) between arguments
33 * Split _x int _a and _b for multiprecision
34 * If _x >> _y we will we will not split _y for multiprecision
35 * all _y will be put into lower part (_d) and higher part (_c = 0)
36 * Fixing _hilo_mask for the case _x >> _y
37 * Split _y into _c and _d for multiprecision with fixed mask
39 * compute Hi and Lo parts of _z = _x*_x + _y*_y
41 * _zHi = _a*_a + _c*_c
42 * _zLo = (_x + _a)*_b + _d*_y + _d*_c
45 * No multiprecision branch for _LA_ and _EP_
46 * _z = _VARG1 * _VARG1 + _VARG2 * _VARG2
48 * Check _z exponent to be within borders [1E3 ; 60A] else goto Callout
50 * Compute resciplicle sqrt s0 ~ 1.0/sqrt(_z),
51 * that multiplied by _z, is final result for _EP_ version.
53 * First iteration (or zero iteration):
61 * d = s * s - z (in multiprecision for _HA_)
65 * EP version of the function can be implemented as y[i]=sqrt(a[i]^2+b[i]^2)
66 * with all intermediate operations done in target precision for i=1, .., n.
67 * It can return result y[i]=0 in case a[i]^2 and b[i]^2 underflow in target
68 * precision (for some i). It can return result y[i]=NAN in case
69 * a[i]^2+b[i]^2 overflow in target precision, for some i. It can return
70 * result y[i]=NAN in case a[i] or b[i] is infinite, for some i.
75 /* Offsets for data table __svml_shypot_data_internal
79 #define _iExpBound 128
83 .section .text.evex512, "ax", @progbits
84 ENTRY(_ZGVeN16vv_hypotf_skx)
86 cfi_def_cfa_offset(16)
92 vgetexpps {sae}, %zmm0, %zmm2
93 vgetexpps {sae}, %zmm1, %zmm3
94 vmovups _sHalf+__svml_shypot_data_internal(%rip), %zmm6
95 vmaxps {sae}, %zmm3, %zmm2, %zmm4
96 vmulps {rn-sae}, %zmm0, %zmm0, %zmm2
97 vandps _sAbsMask+__svml_shypot_data_internal(%rip), %zmm4, %zmm5
98 vfmadd231ps {rn-sae}, %zmm1, %zmm1, %zmm2
99 vpcmpd $5, _iExpBound+__svml_shypot_data_internal(%rip), %zmm5, %k0
100 vrsqrt14ps %zmm2, %zmm7
102 vmulps {rn-sae}, %zmm7, %zmm2, %zmm9
103 vmulps {rn-sae}, %zmm7, %zmm6, %zmm8
104 vfnmadd231ps {rn-sae}, %zmm9, %zmm9, %zmm2
105 vfmadd213ps {rn-sae}, %zmm9, %zmm8, %zmm2
108 * VSCALEF( S, _VRES1, _VRES1, sExp );
109 * The end of implementation
113 /* Go to special inputs processing branch */
114 jne L(SPECIAL_VALUES_BRANCH)
115 # LOE rbx r12 r13 r14 r15 edx zmm0 zmm1 zmm2
118 * and exit the function
135 L(SPECIAL_VALUES_BRANCH):
136 vmovups %zmm0, 64(%rsp)
137 vmovups %zmm1, 128(%rsp)
138 vmovups %zmm2, 192(%rsp)
139 # LOE rbx r12 r13 r14 r15 edx zmm2
142 # LOE rbx r12 r13 r14 r15 eax edx
146 /* DW_CFA_expression: r12 (r12) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -240; DW_OP_plus) */
147 .cfi_escape 0x10, 0x0c, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x10, 0xff, 0xff, 0xff, 0x22
150 /* DW_CFA_expression: r13 (r13) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -248; DW_OP_plus) */
151 .cfi_escape 0x10, 0x0d, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x08, 0xff, 0xff, 0xff, 0x22
154 /* DW_CFA_expression: r14 (r14) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -256; DW_OP_plus) */
155 .cfi_escape 0x10, 0x0e, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x00, 0xff, 0xff, 0xff, 0x22
156 # LOE rbx r15 r12d r13d
165 /* Call scalar math function */
166 jc L(SCALAR_MATH_CALL)
167 # LOE rbx r15 r12d r13d
173 L(SPECIAL_VALUES_LOOP):
177 /* Check bits in range mask */
178 jl L(RANGEMASK_CHECK)
179 # LOE rbx r15 r12d r13d
187 vmovups 192(%rsp), %zmm2
191 /* DW_CFA_expression: r12 (r12) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -240; DW_OP_plus) */
192 .cfi_escape 0x10, 0x0c, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x10, 0xff, 0xff, 0xff, 0x22
193 /* DW_CFA_expression: r13 (r13) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -248; DW_OP_plus) */
194 .cfi_escape 0x10, 0x0d, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x08, 0xff, 0xff, 0xff, 0x22
195 /* DW_CFA_expression: r14 (r14) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -256; DW_OP_plus) */
196 .cfi_escape 0x10, 0x0e, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x00, 0xff, 0xff, 0xff, 0x22
197 # LOE rbx r12 r13 r14 r15 zmm2
199 /* Scalar math function call
200 * to process special input
205 vmovss 64(%rsp, %r14, 4), %xmm0
206 vmovss 128(%rsp, %r14, 4), %xmm1
208 # LOE rbx r14 r15 r12d r13d xmm0
210 vmovss %xmm0, 192(%rsp, %r14, 4)
212 /* Process special inputs in loop */
213 jmp L(SPECIAL_VALUES_LOOP)
214 # LOE rbx r15 r12d r13d
215 END(_ZGVeN16vv_hypotf_skx)
217 .section .rodata, "a"
220 #ifdef __svml_shypot_data_internal_typedef
221 typedef unsigned int VUINT32;
223 __declspec(align(64)) VUINT32 _sAbsMask[16][1];
224 __declspec(align(64)) VUINT32 _sHalf[16][1];
225 __declspec(align(64)) VUINT32 _iExpBound[16][1];
226 } __svml_shypot_data_internal;
228 __svml_shypot_data_internal:
229 .long 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff /* _sAbsMask */
231 .long 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000 /* _sHalf */
232 /* fma based algorithm*/
234 .long 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000, 0x427C0000 /* _iExpBound */
236 .type __svml_shypot_data_internal, @object
237 .size __svml_shypot_data_internal, .-__svml_shypot_data_internal