]> gcc.gnu.org Git - gcc.git/blobdiff - libgfortran/ieee/ieee_exceptions.F90
Update copyright years.
[gcc.git] / libgfortran / ieee / ieee_exceptions.F90
index 80d546526f8f44d4b6bbc3873fe4c9d1601c874a..a4431b40b6511ac6f4515529925514fef99acda2 100644 (file)
@@ -1,5 +1,5 @@
 !    Implementation of the IEEE_EXCEPTIONS standard intrinsic module
-!    Copyright (C) 2013-2017 Free Software Foundation, Inc.
+!    Copyright (C) 2013-2023 Free Software Foundation, Inc.
 !    Contributed by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
 ! 
 ! This file is part of the GNU Fortran runtime library (libgfortran).
@@ -56,6 +56,13 @@ module IEEE_EXCEPTIONS
     character(len=GFC_FPE_STATE_BUFFER_SIZE) :: hidden
   end type
 
+  type, public :: IEEE_MODES_TYPE
+    private
+    integer :: rounding
+    integer :: underflow
+    integer :: halting
+  end type
+
   interface IEEE_SUPPORT_FLAG
     module procedure IEEE_SUPPORT_FLAG_4, &
                      IEEE_SUPPORT_FLAG_8, &
@@ -72,9 +79,65 @@ module IEEE_EXCEPTIONS
   public :: IEEE_SET_HALTING_MODE, IEEE_GET_HALTING_MODE
   public :: IEEE_SET_FLAG, IEEE_GET_FLAG
   public :: IEEE_SET_STATUS, IEEE_GET_STATUS
+  public :: IEEE_SET_MODES, IEEE_GET_MODES
 
 contains
 
+! Fortran 2018: Saving and restoring floating-point modes
+! (rounding modes, underflow mode, and halting mode)
+! 
+! For now, we only have one rounding mode for all kinds.
+! Some targets could optimize getting/setting all modes at once, but for now
+! we make three calls.  This code must be kept in sync with:
+!   - IEEE_{GET,SET}_ROUNDING_MODE
+!   - IEEE_{GET,SET}_UNDERFLOW_MODE
+!   - IEEE_{GET,SET}_HALTING_MODE
+
+  subroutine IEEE_GET_MODES (MODES)
+    implicit none
+    type(IEEE_MODES_TYPE), intent(out) :: MODES
+
+    interface
+      integer function helper_rounding() &
+        bind(c, name="_gfortrani_get_fpu_rounding_mode")
+      end function
+      integer function helper_underflow() &
+        bind(c, name="_gfortrani_get_fpu_underflow_mode")
+      end function
+      pure integer function helper_halting() &
+          bind(c, name="_gfortrani_get_fpu_trap_exceptions")
+      end function
+    end interface
+
+    MODES%rounding = helper_rounding()
+    MODES%underflow = helper_underflow()
+    MODES%halting = helper_halting()
+  end subroutine
+
+  subroutine IEEE_SET_MODES (MODES)
+    implicit none
+    type(IEEE_MODES_TYPE), intent(in) :: MODES
+
+    interface
+      subroutine helper_rounding(val) &
+          bind(c, name="_gfortrani_set_fpu_rounding_mode")
+        integer, value :: val
+      end subroutine
+      subroutine helper_underflow(val) &
+          bind(c, name="_gfortrani_set_fpu_underflow_mode")
+        integer, value :: val
+      end subroutine
+      pure subroutine helper_halting(trap, notrap) &
+          bind(c, name="_gfortrani_set_fpu_trap_exceptions")
+        integer, intent(in), value :: trap, notrap
+      end subroutine
+    end interface
+
+    call helper_rounding(MODES%rounding)
+    call helper_underflow(MODES%underflow)
+    call helper_halting(MODES%halting, NOT(MODES%halting))
+  end subroutine
+
 ! Saving and restoring floating-point status
 
   subroutine IEEE_GET_STATUS (STATUS_VALUE)
This page took 0.030786 seconds and 5 git commands to generate.