Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / i386 / fpu / fraiseexcpt.c
blob076477fc5d65f4196d751c24c3c310fd159afa55
1 /* Raise given exceptions.
2 Copyright (C) 1997-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
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.
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
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <fenv.h>
21 #include <math.h>
23 int
24 __feraiseexcept (int excepts)
26 /* Raise exceptions represented by EXPECTS. But we must raise only
27 one signal at a time. It is important that if the overflow/underflow
28 exception and the inexact exception are given at the same time,
29 the overflow/underflow exception follows the inexact exception. */
31 /* First: invalid exception. */
32 if ((FE_INVALID & excepts) != 0)
34 /* One example of an invalid operation is 0.0 / 0.0. */
35 double d;
36 __asm__ __volatile__ ("fldz; fdiv %%st, %%st(0); fwait" : "=t" (d));
37 (void) &d;
40 /* Next: division by zero. */
41 if ((FE_DIVBYZERO & excepts) != 0)
43 double d;
44 __asm__ __volatile__ ("fldz; fld1; fdivp %%st, %%st(1); fwait"
45 : "=t" (d));
46 (void) &d;
49 /* Next: overflow. */
50 if ((FE_OVERFLOW & excepts) != 0)
52 /* There is no way to raise only the overflow flag. Do it the
53 hard way. */
54 fenv_t temp;
56 /* Bah, we have to clear selected exceptions. Since there is no
57 `fldsw' instruction we have to do it the hard way. */
58 __asm__ __volatile__ ("fnstenv %0" : "=m" (*&temp));
60 /* Set the relevant bits. */
61 temp.__status_word |= FE_OVERFLOW;
63 /* Put the new data in effect. */
64 __asm__ __volatile__ ("fldenv %0" : : "m" (*&temp));
66 /* And raise the exception. */
67 __asm__ __volatile__ ("fwait");
70 /* Next: underflow. */
71 if ((FE_UNDERFLOW & excepts) != 0)
73 /* There is no way to raise only the underflow flag. Do it the
74 hard way. */
75 fenv_t temp;
77 /* Bah, we have to clear selected exceptions. Since there is no
78 `fldsw' instruction we have to do it the hard way. */
79 __asm__ __volatile__ ("fnstenv %0" : "=m" (*&temp));
81 /* Set the relevant bits. */
82 temp.__status_word |= FE_UNDERFLOW;
84 /* Put the new data in effect. */
85 __asm__ __volatile__ ("fldenv %0" : : "m" (*&temp));
87 /* And raise the exception. */
88 __asm__ __volatile__ ("fwait");
91 /* Last: inexact. */
92 if ((FE_INEXACT & excepts) != 0)
94 /* There is no way to raise only the inexact flag. Do it the
95 hard way. */
96 fenv_t temp;
98 /* Bah, we have to clear selected exceptions. Since there is no
99 `fldsw' instruction we have to do it the hard way. */
100 __asm__ __volatile__ ("fnstenv %0" : "=m" (*&temp));
102 /* Set the relevant bits. */
103 temp.__status_word |= FE_INEXACT;
105 /* Put the new data in effect. */
106 __asm__ __volatile__ ("fldenv %0" : : "m" (*&temp));
108 /* And raise the exception. */
109 __asm__ __volatile__ ("fwait");
112 /* Success. */
113 return 0;
116 #include <shlib-compat.h>
117 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
118 strong_alias (__feraiseexcept, __old_feraiseexcept)
119 compat_symbol (libm, __old_feraiseexcept, feraiseexcept, GLIBC_2_1);
120 #endif
122 libm_hidden_ver (__feraiseexcept, feraiseexcept)
123 versioned_symbol (libm, __feraiseexcept, feraiseexcept, GLIBC_2_2);