]>
Commit | Line | Data |
---|---|---|
a92599ea | 1 | /* Compute the hypothenuse of X and Y. |
2b778ceb | 2 | Copyright (C) 1998-2021 Free Software Foundation, Inc. |
a92599ea UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
a92599ea UD |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
a92599ea | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 17 | License along with the GNU C Library; if not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
a92599ea UD |
19 | |
20 | #include <sysdep.h> | |
6f0f237b | 21 | #include <i386-math-asm.h> |
220622dd | 22 | #include <libm-alias-finite.h> |
a92599ea | 23 | |
f6987f5a JM |
24 | DEFINE_DBL_MIN |
25 | ||
26 | #ifdef PIC | |
27 | # define MO(op) op##@GOTOFF(%edx) | |
28 | #else | |
29 | # define MO(op) op | |
30 | #endif | |
31 | ||
a92599ea UD |
32 | .text |
33 | ENTRY(__ieee754_hypot) | |
f6987f5a JM |
34 | #ifdef PIC |
35 | LOAD_PIC_REG (dx) | |
36 | #endif | |
a92599ea UD |
37 | fldl 4(%esp) // x |
38 | fxam | |
39 | fnstsw | |
40 | fldl 12(%esp) // y : x | |
41 | movb %ah, %ch | |
42 | fxam | |
43 | fnstsw | |
44 | movb %ah, %al | |
45 | orb %ch, %ah | |
46 | sahf | |
47 | jc 1f | |
48 | fmul %st(0) // y * y : x | |
49 | fxch // x : y * y | |
50 | fmul %st(0) // x * x : y * y | |
51 | faddp // x * x + y * y | |
52 | fsqrt | |
f6987f5a | 53 | DBL_NARROW_EVAL_UFLOW_NONNEG |
a92599ea UD |
54 | 2: ret |
55 | ||
56 | // We have to test whether any of the parameters is Inf. | |
57 | // In this case the result is infinity. | |
58 | 1: andb $0x45, %al | |
59 | cmpb $5, %al | |
60 | je 3f // jump if y is Inf | |
61 | andb $0x45, %ch | |
62 | cmpb $5, %ch | |
63 | jne 4f // jump if x is not Inf | |
64 | fxch | |
65 | 3: fstp %st(1) | |
66 | fabs | |
67 | jmp 2b | |
68 | ||
69 | 4: testb $1, %al | |
70 | jnz 5f // y is NaN | |
71 | fxch | |
72 | 5: fstp %st(1) | |
73 | jmp 2b | |
0ac5ae23 | 74 | |
a92599ea | 75 | END(__ieee754_hypot) |
220622dd | 76 | libm_alias_finite (__ieee754_hypot, __hypot) |