1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
|
/* Copyright (C) 2007-2015 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
/*****************************************************************************
* Non-computational Operations on Flags:
****************************************************************************/
#include "bid_internal.h"
// Note the following definitions from bid_conf.h: if the status flags are
// global, they have a fixed name recognized by the library functions:
// _IDEC_glbflags; pfpsf, defined as &_IDEC_glbflags, can be used instead; no
// argument is passed for the status flags to the library functions; if the
// status flags are local then they are passed as an arument, always by
// reference, to the library functions
//
// #if !DECIMAL_GLOBAL_EXCEPTION_FLAGS
// #define _EXC_FLAGS_PARAM , _IDEC_flags *pfpsf
// #else
// extern _IDEC_flags _IDEC_glbflags;
// #define _EXC_FLAGS_PARAM
// #define pfpsf &_IDEC_glbflags
// #endif
#if DECIMAL_CALL_BY_REFERENCE
void
signalException (_IDEC_flags * pflagsmask _EXC_FLAGS_PARAM) {
// *pflagsmask is the logical OR of the flags to be set, e.g.
// *pflagsmask =INVALID_EXCEPTION | ZERO_DIVIDE_EXCEPTION | OVERFLOW_EXCEPTION
// UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION to set all five IEEE 754R
// exception flags
*pfpsf = *pfpsf | (*pflagsmask & BID_IEEE_FLAGS);
}
#else
void
signalException (_IDEC_flags flagsmask _EXC_FLAGS_PARAM) {
// flagsmask is the logical OR of the flags to be set, e.g.
// flagsmask = INVALID_EXCEPTION | ZERO_DIVIDE_EXCEPTION | OVERFLOW_EXCEPTION
// UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION to set all five IEEE 754R
// exception flags
*pfpsf = *pfpsf | (flagsmask & BID_IEEE_FLAGS);
}
#endif
#if DECIMAL_CALL_BY_REFERENCE
void
lowerFlags (_IDEC_flags * pflagsmask _EXC_FLAGS_PARAM) {
// *pflagsmask is the logical OR of the flags to be cleared, e.g.
// *pflagsmask =INVALID_EXCEPTION | ZERO_DIVIDE_EXCEPTION | OVERFLOW_EXCEPTION
// UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION to clear all five IEEE 754R
// exception flags
*pfpsf = *pfpsf & ~(*pflagsmask & BID_IEEE_FLAGS);
}
#else
void
lowerFlags (_IDEC_flags flagsmask _EXC_FLAGS_PARAM) {
// flagsmask is the logical OR of the flags to be cleared, e.g.
// flagsmask = INVALID_EXCEPTION | ZERO_DIVIDE_EXCEPTION | OVERFLOW_EXCEPTION
// UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION to clear all five IEEE 754R
// exception flags
*pfpsf = *pfpsf & ~(flagsmask & BID_IEEE_FLAGS);
}
#endif
#if DECIMAL_CALL_BY_REFERENCE
void
testFlags (_IDEC_flags * praised,
_IDEC_flags * pflagsmask _EXC_FLAGS_PARAM) {
// *praised is a pointer to the result, i.e. the logical OR of the flags
// selected by *pflagsmask that are set; e.g. if
// *pflagsmask = INVALID_EXCEPTION | UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION
// and only the invalid and inexact flags are raised (set) then upon return
// *praised = INVALID_EXCEPTION | INEXACT_EXCEPTION
*praised = *pfpsf & (*pflagsmask & BID_IEEE_FLAGS);
}
#else
_IDEC_flags
testFlags (_IDEC_flags flagsmask _EXC_FLAGS_PARAM) {
_IDEC_flags raised;
// the raturn value raised is the logical OR of the flags
// selected by flagsmask, that are set; e.g. if
// flagsmask = INVALID_EXCEPTION | UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION and
// only the invalid and inexact flags are raised (set) then the return value
// is raised = INVALID_EXCEPTION | INEXACT_EXCEPTION
raised = *pfpsf & (flagsmask & BID_IEEE_FLAGS);
return (raised);
}
#endif
#if DECIMAL_CALL_BY_REFERENCE
void
testSavedFlags (_IDEC_flags * praised, _IDEC_flags * psavedflags,
_IDEC_flags * pflagsmask) {
// *praised is a pointer to the result, i.e. the logical OR of the flags
// selected by *pflagsmask that are set in *psavedflags; e.g. if
// *pflagsmask = INVALID_EXCEPTION | UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION
// and only the invalid and inexact flags are raised (set) in *psavedflags
// then upon return *praised = INVALID_EXCEPTION | INEXACT_EXCEPTION
// Note that the flags could be saved in a global variable, but this function
// would still expect that value as an argument passed by reference
*praised = *psavedflags & (*pflagsmask & BID_IEEE_FLAGS);
}
#else
_IDEC_flags
testSavedFlags (_IDEC_flags savedflags, _IDEC_flags flagsmask) {
_IDEC_flags raised;
// the raturn value raised is the logical OR of the flags
// selected by flagsmask, that are set in savedflags; e.g. if
// flagsmask = INVALID_EXCEPTION | UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION and
// only the invalid and inexact flags are raised (set) in savedflags
// then the return value is raised = INVALID_EXCEPTION | INEXACT_EXCEPTION
// Note that the flags could be saved in a global variable, but this function
// would still expect that value as an argument passed by value
raised = savedflags & (flagsmask & BID_IEEE_FLAGS);
return (raised);
}
#endif
#if DECIMAL_CALL_BY_REFERENCE
void
restoreFlags (_IDEC_flags * pflagsvalues,
_IDEC_flags * pflagsmask _EXC_FLAGS_PARAM) {
// restore the status flags selected by *pflagsmask to the values speciafied
// (as a logical OR) in *pflagsvalues; e.g. if
// *pflagsmask = INVALID_EXCEPTION | UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION
// and only the invalid and inexact flags are raised (set) in *pflagsvalues
// then upon return the invalid status flag will be set, the underflow status
// flag will be clear, and the inexact status flag will be set
*pfpsf = *pfpsf & ~(*pflagsmask & BID_IEEE_FLAGS);
// clear flags that have to be restored
*pfpsf = *pfpsf | (*pflagsvalues & (*pflagsmask & BID_IEEE_FLAGS));
// restore flags
}
#else
void
restoreFlags (_IDEC_flags flagsvalues,
_IDEC_flags flagsmask _EXC_FLAGS_PARAM) {
// restore the status flags selected by flagsmask to the values speciafied
// (as a logical OR) in flagsvalues; e.g. if
// flagsmask = INVALID_EXCEPTION | UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION
// and only the invalid and inexact flags are raised (set) in flagsvalues
// then upon return the invalid status flag will be set, the underflow status
// flag will be clear, and the inexact status flag will be set
*pfpsf = *pfpsf & ~(flagsmask & BID_IEEE_FLAGS);
// clear flags that have to be restored
*pfpsf = *pfpsf | (flagsvalues & (flagsmask & BID_IEEE_FLAGS));
// restore flags
}
#endif
#if DECIMAL_CALL_BY_REFERENCE
void
saveFlags (_IDEC_flags * pflagsvalues,
_IDEC_flags * pflagsmask _EXC_FLAGS_PARAM) {
// return in *pflagsvalues the status flags specified (as a logical OR) in
// *pflagsmask; e.g. if
// *pflagsmask = INVALID_EXCEPTION | UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION
// and only the invalid and inexact flags are raised (set) in the status word,
// then upon return the value in *pflagsvalues will have the invalid status
// flag set, the underflow status flag clear, and the inexact status flag set
*pflagsvalues = *pfpsf & (*pflagsmask & BID_IEEE_FLAGS);
}
#else
_IDEC_flags
saveFlags (_IDEC_flags flagsmask _EXC_FLAGS_PARAM) {
_IDEC_flags flagsvalues;
// return the status flags specified (as a logical OR) in flagsmask; e.g. if
// flagsmask = INVALID_EXCEPTION | UNDERFLOW_EXCEPTION | INEXACT_EXCEPTION
// and only the invalid and inexact flags are raised (set) in the status word,
// then the return value will have the invalid status flag set, the
// underflow status flag clear, and the inexact status flag set
flagsvalues = *pfpsf & (flagsmask & BID_IEEE_FLAGS);
return (flagsvalues);
}
#endif
// Note the following definitions from bid_conf.h (rearranged): if the rounding
// mode is global, it has a fixed name recognized by the library functions:
// _IDEC_glbround; rnd_mode, defined as &_IDEC_glbround, can be used instead; no
// argument is passed for the rounding mode to the library functions; if the
// rounding mode is local then it is passed as an arument, by reference or by
// value, to the library functions
//
// #if DECIMAL_CALL_BY_REFERENCE
// #if !DECIMAL_GLOBAL_ROUNDING
// #define _RND_MODE_PARAM , _IDEC_round *prnd_mode
// #else
// #define _RND_MODE_PARAM
// #define rnd_mode _IDEC_glbround
// #endif
// #else
// #if !DECIMAL_GLOBAL_ROUNDING
// #define _RND_MODE_PARAM , _IDEC_round rnd_mode
// #else
// #define _RND_MODE_PARAM
// #define rnd_mode _IDEC_glbround
// #endif
// #endif
#if DECIMAL_CALL_BY_REFERENCE
#if !DECIMAL_GLOBAL_ROUNDING
// #define _RND_MODE_PARAM , _IDEC_round *prnd_mode
void
getDecimalRoundingDirection (_IDEC_round * rounding_mode
_RND_MODE_PARAM) {
// returns the current rounding mode
*rounding_mode = *prnd_mode;
}
#else
// #define _RND_MODE_PARAM
// #define rnd_mode _IDEC_glbround
void
getDecimalRoundingDirection (_IDEC_round * rounding_mode
_RND_MODE_PARAM) {
// returns the current rounding mode
*rounding_mode = rnd_mode;
}
#endif
#else
#if !DECIMAL_GLOBAL_ROUNDING
// #define _RND_MODE_PARAM , _IDEC_round rnd_mode
_IDEC_round
getDecimalRoundingDirection (_IDEC_round rnd_mode) {
// returns the current rounding mode
return (rnd_mode);
}
#else
// #define _RND_MODE_PARAM
// #define rnd_mode _IDEC_glbround
_IDEC_round
getDecimalRoundingDirection (void) {
// returns the current rounding mode
return (rnd_mode);
}
#endif
#endif
#if DECIMAL_CALL_BY_REFERENCE
#if !DECIMAL_GLOBAL_ROUNDING
// #define _RND_MODE_PARAM , _IDEC_round *prnd_mode
void
setDecimalRoundingDirection (_IDEC_round * rounding_mode
_RND_MODE_PARAM) {
// sets the current rounding mode to the value in *rounding_mode, if valid
if (*rounding_mode == ROUNDING_TO_NEAREST ||
*rounding_mode == ROUNDING_DOWN ||
*rounding_mode == ROUNDING_UP ||
*rounding_mode == ROUNDING_TO_ZERO ||
*rounding_mode == ROUNDING_TIES_AWAY) {
*prnd_mode = *rounding_mode;
}
}
#else
// #define _RND_MODE_PARAM
// #define rnd_mode _IDEC_glbround
void
setDecimalRoundingDirection (_IDEC_round * rounding_mode
) {
// sets the global rounding mode to the value in *rounding_mode, if valid
if (*rounding_mode == ROUNDING_TO_NEAREST ||
*rounding_mode == ROUNDING_DOWN ||
*rounding_mode == ROUNDING_UP ||
*rounding_mode == ROUNDING_TO_ZERO ||
*rounding_mode == ROUNDING_TIES_AWAY) {
rnd_mode = *rounding_mode;
}
}
#endif
#else
#if !DECIMAL_GLOBAL_ROUNDING
// #define _RND_MODE_PARAM , _IDEC_round rnd_mode
_IDEC_round
setDecimalRoundingDirection (_IDEC_round rounding_mode _RND_MODE_PARAM) {
// sets the current rounding mode to the value in rounding_mode;
// however, when arguments are passed by value and the rounding mode
// is a local variable, this is not of any use
if (rounding_mode == ROUNDING_TO_NEAREST ||
rounding_mode == ROUNDING_DOWN ||
rounding_mode == ROUNDING_UP ||
rounding_mode == ROUNDING_TO_ZERO ||
rounding_mode == ROUNDING_TIES_AWAY) {
return (rounding_mode);
}
return (rnd_mode);
}
#else
// #define _RND_MODE_PARAM
// #define rnd_mode _IDEC_glbround
void
setDecimalRoundingDirection (_IDEC_round rounding_mode) {
// sets the current rounding mode to the value in rounding_mode, if valid;
if (rounding_mode == ROUNDING_TO_NEAREST ||
rounding_mode == ROUNDING_DOWN ||
rounding_mode == ROUNDING_UP ||
rounding_mode == ROUNDING_TO_ZERO ||
rounding_mode == ROUNDING_TIES_AWAY) {
rnd_mode = rounding_mode;
}
}
#endif
#endif
#if DECIMAL_CALL_BY_REFERENCE
void
is754 (int *retval) {
*retval = 0;
}
#else
int
is754 (void) {
return 0;
}
#endif
#if DECIMAL_CALL_BY_REFERENCE
void
is754R (int *retval) {
*retval = 1;
}
#else
int
is754R (void) {
return 1;
}
#endif
|