Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / hppa / fpu / fraiseexcpt.c
blob74e93508f39dfd59ba99e4218938feb83c7acf9c
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 David Huggins-Daines <dhd@debian.org>
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 <float.h>
22 #include <math.h>
24 /* Please see section 10,
25 page 10-5 "Delayed Trapping" in the PA-RISC 2.0 Architecture manual */
27 int
28 feraiseexcept (int excepts)
30 /* Raise exceptions represented by EXCEPTS. But we must raise only one
31 signal at a time. It is important that if the overflow/underflow
32 exception and the divide by zero exception are given at the same
33 time, the overflow/underflow exception follows the divide by zero
34 exception. */
36 /* We do these bits in assembly to be certain GCC doesn't optimize
37 away something important, and so we can force delayed traps to
38 occur. */
40 /* We use "fldd 0(%%sr0,%%sp),%0" to flush the delayed exception */
42 /* First: Invalid exception. */
43 if (excepts & FE_INVALID)
45 /* One example of an invalid operation is 0 * Infinity. */
46 double d = HUGE_VAL;
47 __asm__ __volatile__ (
48 " fcpy,dbl %%fr0,%%fr22\n"
49 " fmpy,dbl %0,%%fr22,%0\n"
50 " fldd 0(%%sr0,%%sp),%0"
51 : "+f" (d) : : "%fr22" );
54 /* Second: Division by zero. */
55 if (excepts & FE_DIVBYZERO)
57 double d = 1.0;
58 __asm__ __volatile__ (
59 " fcpy,dbl %%fr0,%%fr22\n"
60 " fdiv,dbl %0,%%fr22,%0\n"
61 " fldd 0(%%sr0,%%sp),%0"
62 : "+f" (d) : : "%fr22" );
65 /* Third: Overflow. */
66 if (excepts & FE_OVERFLOW)
68 double d = DBL_MAX;
69 __asm__ __volatile__ (
70 " fadd,dbl %0,%0,%0\n"
71 " fldd 0(%%sr0,%%sp),%0"
72 : "+f" (d) );
75 /* Fourth: Underflow. */
76 if (excepts & FE_UNDERFLOW)
78 double d = DBL_MIN;
79 double e = 3.0;
80 __asm__ __volatile__ (
81 " fdiv,dbl %0,%1,%0\n"
82 " fldd 0(%%sr0,%%sp),%0"
83 : "+f" (d) : "f" (e) );
86 /* Fifth: Inexact */
87 if (excepts & FE_INEXACT)
89 double d = M_PI;
90 double e = 69.69;
91 __asm__ __volatile__ (
92 " fdiv,dbl %0,%1,%%fr22\n"
93 " fcnvfxt,dbl,sgl %%fr22,%%fr22L\n"
94 " fldd 0(%%sr0,%%sp),%%fr22"
95 : : "f" (d), "f" (e) : "%fr22" );
98 /* Success. */
99 return 0;
101 libm_hidden_def (feraiseexcept)