bid_decimal_globals.c 2.6 KB

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