(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / hppa / fpu / fraiseexcpt.c
blobb064dc1527c6681c6e0373dee1380eae21450a4a
1 /* Raise given exceptions.
2 Copyright (C) 1997, 1999, 2000, 2002 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <fenv.h>
22 #include <float.h>
23 #include <math.h>
25 /* Please see section 10,
26 page 10-5 "Delayed Trapping" in the PA-RISC 2.0 Architecture manual */
28 int
29 feraiseexcept (int excepts)
31 /* Raise exceptions represented by EXCEPTS. But we must raise only one
32 signal at a time. It is important that if the overflow/underflow
33 exception and the divide by zero exception are given at the same
34 time, the overflow/underflow exception follows the divide by zero
35 exception. */
37 /* We do these bits in assembly to be certain GCC doesn't optimize
38 away something important, and so we can force delayed traps to
39 occur. */
41 /* We use "fldd 0(%%sr0,%%sp),%0" to flush the delayed exception */
43 /* First: Invalid exception. */
44 if (excepts & FE_INVALID)
46 /* One example of a invalid operation is 0 * Infinity. */
47 double d = HUGE_VAL;
48 __asm__ __volatile__ (
49 " fcpy,dbl %%fr0,%%fr22\n"
50 " fmpy,dbl %0,%%fr22,%0\n"
51 " fldd 0(%%sr0,%%sp),%0"
52 : "+f" (d) : : "%fr22" );
55 /* Second: Division by zero. */
56 if (excepts & FE_DIVBYZERO)
58 double d = 1.0;
59 __asm__ __volatile__ (
60 " fcpy,dbl %%fr0,%%fr22\n"
61 " fdiv,dbl %0,%%fr22,%0\n"
62 " fldd 0(%%sr0,%%sp),%0"
63 : "+f" (d) : : "%fr22" );
66 /* Third: Overflow. */
67 if (excepts & FE_OVERFLOW)
69 double d = DBL_MAX;
70 __asm__ __volatile__ (
71 " fadd,dbl %0,%0,%0\n"
72 " fldd 0(%%sr0,%%sp),%0"
73 : "+f" (d) );
76 /* Fourth: Underflow. */
77 if (excepts & FE_UNDERFLOW)
79 double d = DBL_MIN;
80 double e = 3.0;
81 __asm__ __volatile__ (
82 " fdiv,dbl %0,%1,%0\n"
83 " fldd 0(%%sr0,%%sp),%0"
84 : "+f" (d) : "f" (e) );
87 /* Fifth: Inexact */
88 if (excepts & FE_INEXACT)
90 double d = M_PI;
91 double e = 69.69;
92 __asm__ __volatile__ (
93 " fdiv,dbl %0,%1,%%fr22\n"
94 " fcnvfxt,dbl,sgl %%fr22,%%fr22L\n"
95 " fldd 0(%%sr0,%%sp),%%fr22"
96 : : "f" (d), "f" (e) : "%fr22" );
99 /* Success. */
100 return 0;
102 libm_hidden_def (feraiseexcept)