1 /* Copyright (C) 2004,2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 #include <fenv_libc.h>
22 #include <kernel-features.h>
23 #include "kernel_sysinfo.h"
27 __feraiseexcept (int excepts
)
29 INTERNAL_SYSCALL_DECL (err
);
30 unsigned long t
= excepts
;
33 r
= INTERNAL_SYSCALL (osf_setsysinfo
, err
, 2, SSI_IEEE_RAISE_EXCEPTION
, &t
);
35 #ifndef __ASSUME_IEEE_RAISE_EXCEPTION
36 if (!INTERNAL_SYSCALL_ERROR_P (r
, err
))
41 /* If we got an error from SSI_IEEE_RAISE_EXCEPTION, assume it means that
42 the system call isn't actually implemented. Do the best we can. */
44 /* Invalid implemented with 0 / 0 -> NaN. */
45 if (excepts
& FE_INVALID
)
46 __asm__
__volatile__ ("divs/su $f31,$f31,%0; trapb" : "=f"(d
) : );
48 /* Division By Zero implemented with 1 / 0 -> NaN. */
49 if (excepts
& FE_DIVBYZERO
)
50 __asm__
__volatile__ ("divs/su %1,$f31,%0; trapb" : "=&f"(d
) : "f"(1.0f
));
52 /* Overflow and underflow cannot be had all by themselves. We can
53 generate them with arithmetic, but we always get INEXACT raised
54 at the same time. Prepare to undo. */
55 if ((excepts
& (FE_OVERFLOW
| FE_UNDERFLOW
)) && !(excepts
& FE_INEXACT
))
56 INTERNAL_SYSCALL (osf_getsysinfo
, err
, 2, GSI_IEEE_FP_CONTROL
, &t
);
58 /* Overflow implemented with FLT_MAX + FLT_MAX -> Inf. */
59 if (excepts
& FE_OVERFLOW
)
60 __asm__
__volatile__ ("adds/sui %1,%1,%0; trapb"
61 : "=&f"(d
) : "f"(FLT_MAX
));
63 /* Underflow implemented with FLT_MIN * FLT_MIN -> 0. */
64 if (excepts
& FE_UNDERFLOW
)
65 __asm__
__volatile__ ("muls/sui %1,%1,%0; trapb"
66 : "=&f"(d
) : "f"(FLT_MIN
));
68 /* Inexact implemented with (long)0.5 -> 0. */
69 if ((excepts
& (FE_OVERFLOW
| FE_UNDERFLOW
| FE_INEXACT
)) == FE_INEXACT
)
70 __asm__
__volatile__ ("cvttq/svi %1,%0; trapb" : "=&f"(d
) : "f"(0.5f
));
72 /* If we raised inexact when not asked, and inexact was not previously
73 raised, then clear that exception. */
74 if ((excepts
& (FE_OVERFLOW
| FE_UNDERFLOW
))
75 && !((excepts
| t
) & FE_INEXACT
))
77 t
|= excepts
& SWCR_STATUS_MASK
;
78 INTERNAL_SYSCALL (osf_setsysinfo
, err
, 2, SSI_IEEE_FP_CONTROL
, &t
);
80 #endif /* !__ASSUME_IEEE_RAISE_EXCEPTION */
85 #include <shlib-compat.h>
86 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
87 strong_alias (__feraiseexcept
, __old_feraiseexcept
)
88 compat_symbol (libm
, __old_feraiseexcept
, feraiseexcept
, GLIBC_2_1
);
91 libm_hidden_ver (__feraiseexcept
, feraiseexcept
)
92 versioned_symbol (libm
, __feraiseexcept
, feraiseexcept
, GLIBC_2_2
);