1 /* Copyright (C) 1997-2017 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 License as
7 published by the Free Software Foundation; either version 2.1 of the
8 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 <http://www.gnu.org/licenses/>. */
20 #include <fpu_control.h>
24 __feraiseexcept (int excepts
)
27 const float fp_zero
= 0.0;
28 const float fp_one
= 1.0;
29 const float fp_max
= FLT_MAX
;
30 const float fp_min
= FLT_MIN
;
31 const float fp_1e32
= 1.0e32f
;
32 const float fp_two
= 2.0;
33 const float fp_three
= 3.0;
35 /* Raise exceptions represented by EXCEPTS. But we must raise only
36 one signal at a time. It is important that if the OVERFLOW or
37 UNDERFLOW exception and the inexact exception are given at the
38 same time, the OVERFLOW or UNDERFLOW exception precedes the
41 After each exception we read from the FPSR, to force the
42 exception to be raised immediately. */
44 if (FE_INVALID
& excepts
)
45 __asm__
__volatile__ (
48 "mrs %0, fpsr" : "=r" (fpsr
)
52 if (FE_DIVBYZERO
& excepts
)
53 __asm__
__volatile__ (
57 "mrs %0, fpsr" : "=r" (fpsr
)
58 : "m" (fp_one
), "m" (fp_zero
)
61 if (FE_OVERFLOW
& excepts
)
62 /* There's no way to raise overflow without also raising inexact. */
63 __asm__
__volatile__ (
67 "mrs %0, fpsr" : "=r" (fpsr
)
68 : "m" (fp_max
), "m" (fp_1e32
)
71 if (FE_UNDERFLOW
& excepts
)
72 __asm__
__volatile__ (
76 "mrs %0, fpsr" : "=r" (fpsr
)
77 : "m" (fp_min
), "m" (fp_three
)
80 if (FE_INEXACT
& excepts
)
81 __asm__
__volatile__ (
85 "mrs %0, fpsr" : "=r" (fpsr
)
86 : "m" (fp_two
), "m" (fp_three
)
91 libm_hidden_def (__feraiseexcept
)
92 weak_alias (__feraiseexcept
, feraiseexcept
)
93 libm_hidden_weak (feraiseexcept
)