]>
Commit | Line | Data |
---|---|---|
99dee823 | 1 | /* Copyright (C) 2007-2021 Free Software Foundation, Inc. |
200359e8 L |
2 | |
3 | This file is part of GCC. | |
4 | ||
5 | GCC is free software; you can redistribute it and/or modify it under | |
6 | the terms of the GNU General Public License as published by the Free | |
748086b7 | 7 | Software Foundation; either version 3, or (at your option) any later |
200359e8 L |
8 | version. |
9 | ||
200359e8 L |
10 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
11 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 | for more details. | |
14 | ||
748086b7 JJ |
15 | Under Section 7 of GPL version 3, you are granted additional |
16 | permissions described in the GCC Runtime Library Exception, version | |
17 | 3.1, as published by the Free Software Foundation. | |
18 | ||
19 | You should have received a copy of the GNU General Public License and | |
20 | a copy of the GCC Runtime Library Exception along with this program; | |
21 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
22 | <http://www.gnu.org/licenses/>. */ | |
200359e8 | 23 | |
b2a00c89 L |
24 | #include "bid_internal.h" |
25 | #include "bid_gcc_intrinsics.h" | |
200359e8 L |
26 | |
27 | #if DECIMAL_GLOBAL_ROUNDING | |
b2a00c89 | 28 | BID_THREAD _IDEC_round _IDEC_glbround = ROUNDING_TO_NEAREST; |
200359e8 | 29 | |
b2a00c89 | 30 | #if DECIMAL_GLOBAL_ROUNDING_ACCESS_FUNCTIONS |
200359e8 | 31 | void |
b2a00c89 L |
32 | __dfp_set_round (int mode) { |
33 | _IDEC_glbround = mode; | |
200359e8 L |
34 | } |
35 | ||
36 | int | |
b2a00c89 L |
37 | __dfp_get_round (void) { |
38 | return _IDEC_glbround; | |
200359e8 L |
39 | } |
40 | #endif | |
b2a00c89 | 41 | #endif |
200359e8 L |
42 | |
43 | #if DECIMAL_GLOBAL_EXCEPTION_FLAGS | |
b2a00c89 | 44 | BID_THREAD _IDEC_flags _IDEC_glbflags = EXACT_STATUS; |
200359e8 | 45 | |
b2a00c89 | 46 | #if DECIMAL_GLOBAL_EXCEPTION_FLAGS_ACCESS_FUNCTIONS |
200359e8 L |
47 | #include <fenv.h> |
48 | ||
49 | void | |
b2a00c89 L |
50 | __dfp_clear_except (void) { |
51 | _IDEC_glbflags &= ~FLAG_MASK; | |
200359e8 L |
52 | } |
53 | ||
54 | int | |
b2a00c89 | 55 | __dfp_test_except (int mask) { |
200359e8 L |
56 | int flags = 0; |
57 | ||
b2a00c89 | 58 | if ((_IDEC_glbflags & INEXACT_EXCEPTION) != 0) |
200359e8 | 59 | flags |= mask & FE_INEXACT; |
b2a00c89 | 60 | if ((_IDEC_glbflags & UNDERFLOW_EXCEPTION) != 0) |
200359e8 | 61 | flags |= mask & FE_UNDERFLOW; |
b2a00c89 | 62 | if ((_IDEC_glbflags & OVERFLOW_EXCEPTION) != 0) |
200359e8 | 63 | flags |= mask & FE_OVERFLOW; |
b2a00c89 | 64 | if ((_IDEC_glbflags & ZERO_DIVIDE_EXCEPTION) != 0) |
200359e8 | 65 | flags |= mask & FE_DIVBYZERO; |
b2a00c89 | 66 | if ((_IDEC_glbflags & INVALID_EXCEPTION) != 0) |
200359e8 L |
67 | flags |= mask & FE_INVALID; |
68 | ||
69 | return flags; | |
70 | } | |
71 | ||
72 | void | |
b2a00c89 | 73 | __dfp_raise_except (int mask) { |
200359e8 L |
74 | _IDEC_flags flags = 0; |
75 | ||
76 | if ((mask & FE_INEXACT) != 0) | |
77 | flags |= INEXACT_EXCEPTION; | |
78 | if ((mask & FE_UNDERFLOW) != 0) | |
79 | flags |= UNDERFLOW_EXCEPTION; | |
80 | if ((mask & FE_OVERFLOW) != 0) | |
81 | flags |= OVERFLOW_EXCEPTION; | |
82 | if ((mask & FE_DIVBYZERO) != 0) | |
83 | flags |= ZERO_DIVIDE_EXCEPTION; | |
84 | if ((mask & FE_INVALID) != 0) | |
85 | flags |= INVALID_EXCEPTION; | |
86 | ||
b2a00c89 | 87 | _IDEC_glbflags |= flags; |
200359e8 | 88 | } |
b2a00c89 | 89 | #endif |
200359e8 L |
90 | #endif |
91 | ||
92 | #if DECIMAL_ALTERNATE_EXCEPTION_HANDLING | |
b2a00c89 L |
93 | #if DECIMAL_GLOBAL_EXCEPTION_MASKS |
94 | BID_THREAD _IDEC_exceptionmasks _IDEC_glbexceptionmasks = | |
95 | _IDEC_allexcmasksset; | |
96 | #endif | |
97 | #if DECIMAL_GLOBAL_EXCEPTION_INFO | |
98 | BID_THREAD _IDEC_excepthandling _IDEC_glbexcepthandling; | |
99 | #endif | |
200359e8 | 100 | #endif |