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, see
16 <http://www.gnu.org/licenses/>. */
18 #include <fenv_libc.h>
21 #include <kernel-features.h>
22 #include "kernel_sysinfo.h"
26 __feraiseexcept (int excepts
)
28 INTERNAL_SYSCALL_DECL (err
);
29 unsigned long t
= excepts
;
32 r
= INTERNAL_SYSCALL (osf_setsysinfo
, err
, 2, SSI_IEEE_RAISE_EXCEPTION
, &t
);
34 #ifndef __ASSUME_IEEE_RAISE_EXCEPTION
35 if (!INTERNAL_SYSCALL_ERROR_P (r
, err
))
40 /* If we got an error from SSI_IEEE_RAISE_EXCEPTION, assume it means that
41 the system call isn't actually implemented. Do the best we can. */
43 /* Invalid implemented with 0 / 0 -> NaN. */
44 if (excepts
& FE_INVALID
)
45 __asm__
__volatile__ ("divs/su $f31,$f31,%0; trapb" : "=f"(d
) : );
47 /* Division By Zero implemented with 1 / 0 -> NaN. */
48 if (excepts
& FE_DIVBYZERO
)
49 __asm__
__volatile__ ("divs/su %1,$f31,%0; trapb" : "=&f"(d
) : "f"(1.0f
));
51 /* Overflow and underflow cannot be had all by themselves. We can
52 generate them with arithmetic, but we always get INEXACT raised
53 at the same time. Prepare to undo. */
54 if ((excepts
& (FE_OVERFLOW
| FE_UNDERFLOW
)) && !(excepts
& FE_INEXACT
))
55 INTERNAL_SYSCALL (osf_getsysinfo
, err
, 2, GSI_IEEE_FP_CONTROL
, &t
);
57 /* Overflow implemented with FLT_MAX + FLT_MAX -> Inf. */
58 if (excepts
& FE_OVERFLOW
)
59 __asm__
__volatile__ ("adds/sui %1,%1,%0; trapb"
60 : "=&f"(d
) : "f"(FLT_MAX
));
62 /* Underflow implemented with FLT_MIN * FLT_MIN -> 0. */
63 if (excepts
& FE_UNDERFLOW
)
64 __asm__
__volatile__ ("muls/sui %1,%1,%0; trapb"
65 : "=&f"(d
) : "f"(FLT_MIN
));
67 /* Inexact implemented with (long)0.5 -> 0. */
68 if ((excepts
& (FE_OVERFLOW
| FE_UNDERFLOW
| FE_INEXACT
)) == FE_INEXACT
)
69 __asm__
__volatile__ ("cvttq/svi %1,%0; trapb" : "=&f"(d
) : "f"(0.5f
));
71 /* If we raised inexact when not asked, and inexact was not previously
72 raised, then clear that exception. */
73 if ((excepts
& (FE_OVERFLOW
| FE_UNDERFLOW
))
74 && !((excepts
| t
) & FE_INEXACT
))
76 t
|= excepts
& SWCR_STATUS_MASK
;
77 INTERNAL_SYSCALL (osf_setsysinfo
, err
, 2, SSI_IEEE_FP_CONTROL
, &t
);
79 #endif /* !__ASSUME_IEEE_RAISE_EXCEPTION */
84 #include <shlib-compat.h>
85 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
86 strong_alias (__feraiseexcept
, __old_feraiseexcept
)
87 compat_symbol (libm
, __old_feraiseexcept
, feraiseexcept
, GLIBC_2_1
);
90 libm_hidden_ver (__feraiseexcept
, feraiseexcept
)
91 versioned_symbol (libm
, __feraiseexcept
, feraiseexcept
, GLIBC_2_2
);