1 /* Raise given exceptions.
2 Copyright (C) 2000-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <fenv_libc.h>
24 static __inline__
void
25 fexceptdiv (float d
, float e
)
27 __asm__
__volatile__ ("debr %0,%1" : : "f" (d
), "f" (e
) );
30 static __inline__
void
31 fexceptadd (float d
, float e
)
33 __asm__
__volatile__ ("aebr %0,%1" : : "f" (d
), "f" (e
) );
36 #ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
37 static __inline__
void
38 fexceptround (double e
)
41 /* Load rounded from double to float with M3 = round toward 0, M4 = Suppress
42 IEEE-inexact exception.
43 In case of e=0x1p128 and the overflow-mask bit is zero, only the
44 IEEE-overflow flag is set. If overflow-mask bit is one, DXC field is set to
45 0x20 "IEEE overflow, exact".
46 In case of e=0x1p-150 and the underflow-mask bit is zero, only the
47 IEEE-underflow flag is set. If underflow-mask bit is one, DXC field is set
48 to 0x10 "IEEE underflow, exact".
49 This instruction is available with a zarch machine >= z196. */
50 __asm__
__volatile__ ("ledbra %0,5,%1,4" : "=f" (d
) : "f" (e
) );
55 __feraiseexcept (int excepts
)
57 /* Raise exceptions represented by EXPECTS. But we must raise only
58 one signal at a time. It is important that if the overflow/underflow
59 exception and the inexact exception are given at the same time,
60 the overflow/underflow exception follows the inexact exception. */
62 /* First: invalid exception. */
63 if (FE_INVALID
& excepts
)
64 fexceptdiv (0.0, 0.0);
66 /* Next: division by zero. */
67 if (FE_DIVBYZERO
& excepts
)
68 fexceptdiv (1.0, 0.0);
71 if (FE_OVERFLOW
& excepts
)
73 #ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
74 fexceptround (0x1p
128);
76 /* If overflow-mask bit is zero, both IEEE-overflow and IEEE-inexact flags
77 are set. If overflow-mask bit is one, DXC field is set to 0x2C "IEEE
78 overflow, inexact and incremented". */
79 fexceptadd (FLT_MAX
, 1.0e32
);
83 /* Next: underflow. */
84 if (FE_UNDERFLOW
& excepts
)
86 #ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
87 fexceptround (0x1p
-150);
89 /* If underflow-mask bit is zero, both IEEE-underflow and IEEE-inexact
90 flags are set. If underflow-mask bit is one, DXC field is set to 0x1C
91 "IEEE underflow, inexact and incremented". */
92 fexceptdiv (FLT_MIN
, 3.0);
97 if (FE_INEXACT
& excepts
)
98 fexceptdiv (2.0, 3.0);
103 libm_hidden_def (__feraiseexcept
)
104 weak_alias (__feraiseexcept
, feraiseexcept
)
105 libm_hidden_weak (feraiseexcept
)