]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/i386/fpu/fraiseexcpt.c
1 /* Raise given exceptions.
2 Copyright (C) 1997-2022 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/>. */
23 __feraiseexcept (int excepts
)
25 /* Raise exceptions represented by EXPECTS. But we must raise only
26 one signal at a time. It is important that if the overflow/underflow
27 exception and the inexact exception are given at the same time,
28 the overflow/underflow exception follows the inexact exception. */
30 /* First: invalid exception. */
31 if ((FE_INVALID
& excepts
) != 0)
33 /* One example of an invalid operation is 0.0 / 0.0. */
35 __asm__
__volatile__ ("fldz; fdiv %%st, %%st(0); fwait" : "=t" (d
));
39 /* Next: division by zero. */
40 if ((FE_DIVBYZERO
& excepts
) != 0)
43 __asm__
__volatile__ ("fldz; fld1; fdivp %%st, %%st(1); fwait"
49 if ((FE_OVERFLOW
& excepts
) != 0)
51 /* There is no way to raise only the overflow flag. Do it the
55 /* Bah, we have to clear selected exceptions. Since there is no
56 `fldsw' instruction we have to do it the hard way. */
57 __asm__
__volatile__ ("fnstenv %0" : "=m" (*&temp
));
59 /* Set the relevant bits. */
60 temp
.__status_word
|= FE_OVERFLOW
;
62 /* Put the new data in effect. */
63 __asm__
__volatile__ ("fldenv %0" : : "m" (*&temp
));
65 /* And raise the exception. */
66 __asm__
__volatile__ ("fwait");
69 /* Next: underflow. */
70 if ((FE_UNDERFLOW
& excepts
) != 0)
72 /* There is no way to raise only the underflow flag. Do it the
76 /* Bah, we have to clear selected exceptions. Since there is no
77 `fldsw' instruction we have to do it the hard way. */
78 __asm__
__volatile__ ("fnstenv %0" : "=m" (*&temp
));
80 /* Set the relevant bits. */
81 temp
.__status_word
|= FE_UNDERFLOW
;
83 /* Put the new data in effect. */
84 __asm__
__volatile__ ("fldenv %0" : : "m" (*&temp
));
86 /* And raise the exception. */
87 __asm__
__volatile__ ("fwait");
91 if ((FE_INEXACT
& excepts
) != 0)
93 /* There is no way to raise only the inexact flag. Do it the
97 /* Bah, we have to clear selected exceptions. Since there is no
98 `fldsw' instruction we have to do it the hard way. */
99 __asm__
__volatile__ ("fnstenv %0" : "=m" (*&temp
));
101 /* Set the relevant bits. */
102 temp
.__status_word
|= FE_INEXACT
;
104 /* Put the new data in effect. */
105 __asm__
__volatile__ ("fldenv %0" : : "m" (*&temp
));
107 /* And raise the exception. */
108 __asm__
__volatile__ ("fwait");
115 #include <shlib-compat.h>
116 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
117 strong_alias (__feraiseexcept
, __old_feraiseexcept
)
118 compat_symbol (libm
, __old_feraiseexcept
, feraiseexcept
, GLIBC_2_1
);
121 libm_hidden_def (__feraiseexcept
)
122 libm_hidden_ver (__feraiseexcept
, feraiseexcept
)
123 versioned_symbol (libm
, __feraiseexcept
, feraiseexcept
, GLIBC_2_2
);