]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgcc/config/libbid/decimal_globals.c
re PR tree-optimization/33565 (spurious warning: assuming signed overflow does not...
[thirdparty/gcc.git] / libgcc / config / libbid / decimal_globals.c
1 /* Copyright (C) 2007 Free Software Foundation, Inc.
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
7 Software Foundation; either version 2, or (at your option) any later
8 version.
9
10 In addition to the permissions in the GNU General Public License, the
11 Free Software Foundation gives you unlimited permission to link the
12 compiled version of this file into combinations with other programs,
13 and to distribute those combinations without any restriction coming
14 from the use of this file. (The General Public License restrictions
15 do apply in other respects; for example, they cover modification of
16 the file, and distribution when not linked into a combine
17 executable.)
18
19 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with GCC; see the file COPYING. If not, write to the Free
26 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27 02110-1301, USA. */
28
29 #include "bid_conf.h"
30 #include "bid_functions.h"
31
32 #if DECIMAL_GLOBAL_ROUNDING
33 BID_THREAD _IDEC_round __bid_IDEC_glbround = ROUNDING_TO_NEAREST;
34
35 void
36 __dfp_set_round (int mode)
37 {
38 __bid_IDEC_glbround = mode;
39 }
40
41 int
42 __dfp_get_round (void)
43 {
44 return __bid_IDEC_glbround;
45 }
46 #endif
47
48 #if DECIMAL_GLOBAL_EXCEPTION_FLAGS
49 BID_THREAD _IDEC_flags __bid_IDEC_glbflags = EXACT_STATUS;
50
51 #include <fenv.h>
52
53 void
54 __dfp_clear_except (void)
55 {
56 __bid_IDEC_glbflags &= ~FLAG_MASK;
57 }
58
59 int
60 __dfp_test_except (int mask)
61 {
62 int flags = 0;
63
64 if ((__bid_IDEC_glbflags & INEXACT_EXCEPTION) != 0)
65 flags |= mask & FE_INEXACT;
66 if ((__bid_IDEC_glbflags & UNDERFLOW_EXCEPTION) != 0)
67 flags |= mask & FE_UNDERFLOW;
68 if ((__bid_IDEC_glbflags & OVERFLOW_EXCEPTION) != 0)
69 flags |= mask & FE_OVERFLOW;
70 if ((__bid_IDEC_glbflags & ZERO_DIVIDE_EXCEPTION) != 0)
71 flags |= mask & FE_DIVBYZERO;
72 if ((__bid_IDEC_glbflags & INVALID_EXCEPTION) != 0)
73 flags |= mask & FE_INVALID;
74
75 return flags;
76 }
77
78 void
79 __dfp_raise_except (int mask)
80 {
81 _IDEC_flags flags = 0;
82
83 if ((mask & FE_INEXACT) != 0)
84 flags |= INEXACT_EXCEPTION;
85 if ((mask & FE_UNDERFLOW) != 0)
86 flags |= UNDERFLOW_EXCEPTION;
87 if ((mask & FE_OVERFLOW) != 0)
88 flags |= OVERFLOW_EXCEPTION;
89 if ((mask & FE_DIVBYZERO) != 0)
90 flags |= ZERO_DIVIDE_EXCEPTION;
91 if ((mask & FE_INVALID) != 0)
92 flags |= INVALID_EXCEPTION;
93
94 __bid_IDEC_glbflags |= flags;
95 }
96
97 #endif
98
99 #if DECIMAL_ALTERNATE_EXCEPTION_HANDLING
100 #if DECIMAL_GLOBAL_EXCEPTION_MASKS
101 _IDEC_exceptionmasks _IDEC_glbexceptionmasks = _IDEC_allexcmasksset;
102 #endif
103 #if DECIMAL_GLOBAL_EXCEPTION_INFO
104 _IDEC_excepthandling _IDEC_glbexcepthandling;
105 #endif
106 #endif