Similarly, rounding modes are saved and restored for procedures.
Fortran has an optional IEEE module. One of its important features
is that flags (IEEE exceptions) are set to quiet on entry of a procedure
and restored to signalling if it was signalling on entry, or keep it signalling if it was raised on in the procedure. Similarly, rounding
modes are saved and restored for procedures. This is automatically
done if the right IEEE modules are used. A user can set rounding
modes or set and clear exceptions using the right modes.
Conceptually, this is the right thing to do. A library routine should
not produce different results depending on what a user did for his
own calculations.
Computationally, this can be quite expensive
- having the meaning
of a calculation changed by changing FP state should (I hope so,
for corecntess's sake) flush any calculations done with the wrong
FP mode. Just calling a small library routine which does so could
be enough.
An example of the high cost is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121570 where, depending
on the library implementation, gfortran may be over-cautious
for the ieee_next_after function by saving and restoring fp state,
but I'm not sure that the overhead is actually from the FP state or
from calling extra functions.
So... What is the best way to do allow this to be more efficient?
The CPU could speculate on the FP mode (not sure if that is actually
done). Other suggestions? How do current CPUs do so?
On Sat, 13 Sep 2025 14:55:58 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Similarly, rounding modes are saved and restored for procedures.
I am not sure that I understand.
1. Is Fortran's equivalent of C's fesetround() is considered a
languge primitive rather than procedure?
2. Does above said mean that caller has no way of modifying rounding
mode used by callee? If true, it defeats one of original reasons for
which Kahan invented rounding modes in the first place.
Michael S <already5chosen@yahoo.com> schrieb:
On Sat, 13 Sep 2025 14:55:58 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Similarly, rounding modes are saved and restored for procedures.
I am not sure that I understand.
1. Is Fortran's equivalent of C's fesetround() is considered a
languge primitive rather than procedure?
Fortran has intrinsic procedures (like SIN, MATMUL or CPU_TIME),
procedures from intrinsic modules, like COMPILER_OPTIONS
from ISO_FORTRAN_ENV, and user-defined procedures.
IEEE_SET_ROUNDING_MODE is a procedure from an intrinsic module
(but an optional one). It need not be an external function;
the compiler is free to do other things to implement it.
(Hope this answers your question)
2. Does above said mean that caller has no way of modifying rounding
mode used by callee? If true, it defeats one of original reasons for
which Kahan invented rounding modes in the first place.
The caller cannot change the callee's rounding mode without the
callee having been designed for this (by taking the rounding mode
as an extra argument and using IEEE_SET_ROUNDING_MODE itself).
I think that's a good idea. If a library routine is written
and debugged for a particular rounding mode, results should
not change because somebody up the call tree changed it.
Thomas Koenig <tkoenig@netcologne.de> posted:
Fortran has an optional IEEE module. One of its important features
is that flags (IEEE exceptions) are set to quiet on entry of a
procedure and restored to signalling if it was signalling on entry,
or keep it signalling if it was raised on in the procedure.
Similarly, rounding modes are saved and restored for procedures.
This is automatically done if the right IEEE modules are used. A
user can set rounding modes or set and clear exceptions using the
right modes.
How does a user set up his environment such that if TAN()* overflows
to infinity it returns with the OVERFLOW flag set ?!?
(*) EXP(), POW(,)
Conversely, how does one write a TAN()* subroutine with the above
property ?
Conceptually, this is the right thing to do. A library routine
should not produce different results depending on what a user did
for his own calculations.
I would think that a user setting RM=ToZero would WANT a different
result from SIN() than the same call with RM=RNE ?!?
Computationally, this can be quite expensive
And contrary to how IEEE 754 has been used for 40 years.
- having the meaning
of a calculation changed by changing FP state should (I hope so,
for corecntess's sake) flush any calculations done with the wrong
FP mode. Just calling a small library routine which does so could
be enough.
Oh, and BTW, how does a user CALL a subroutine to set his RM when
the RETURN undoes the very nature of his request ?!?
An example of the high cost is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121570 where, depending
on the library implementation, gfortran may be over-cautious
for the ieee_next_after function by saving and restoring fp state,
but I'm not sure that the overhead is actually from the FP state or
from calling extra functions.
So... What is the best way to do allow this to be more efficient?
UN DO this change to IEEE 754.
The CPU could speculate on the FP mode (not sure if that is actually
done). Other suggestions? How do current CPUs do so?
Multi-threaded cores already have to ship different RMs to FUs on
each FP instruction. The HW is all there--its the ISAs that are
screwed up.
Thomas Koenig <tkoenig@netcologne.de> posted:
Fortran has an optional IEEE module. One of its important features
is that flags (IEEE exceptions) are set to quiet on entry of a procedure
and restored to signalling if it was signalling on entry, or keep it
signalling if it was raised on in the procedure. Similarly, rounding
modes are saved and restored for procedures. This is automatically
done if the right IEEE modules are used. A user can set rounding
modes or set and clear exceptions using the right modes.
How does a user set up his environment such that if TAN()* overflows
to infinity it returns with the OVERFLOW flag set ?!?
(*) EXP(), POW(,)
Conversely, how does one write a TAN()* subroutine with the above property ?
Conceptually, this is the right thing to do. A library routine should
not produce different results depending on what a user did for his
own calculations.
I would think that a user setting RM=ToZero would WANT a different
result from SIN() than the same call with RM=RNE ?!?
Oh, and BTW, how does a user CALL a subroutine to set his RM when
the RETURN undoes the very nature of his request ?!?
An example of the high cost is
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121570 where, depending
on the library implementation, gfortran may be over-cautious
for the ieee_next_after function by saving and restoring fp state,
but I'm not sure that the overhead is actually from the FP state or
from calling extra functions.
So... What is the best way to do allow this to be more efficient?
UN DO this change to IEEE 754.
The CPU could speculate on the FP mode (not sure if that is actually
done). Other suggestions? How do current CPUs do so?
Multi-threaded cores already have to ship different RMs to FUs on
each FP instruction. The HW is all there--its the ISAs that are screwed
up.
On Sun, 14 Sep 2025 07:18:38 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Michael S <already5chosen@yahoo.com> schrieb:
On Sat, 13 Sep 2025 14:55:58 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Similarly, rounding modes are saved and restored for procedures.
I am not sure that I understand.
1. Is Fortran's equivalent of C's fesetround() is considered a
languge primitive rather than procedure?
Fortran has intrinsic procedures (like SIN, MATMUL or CPU_TIME),
procedures from intrinsic modules, like COMPILER_OPTIONS
from ISO_FORTRAN_ENV, and user-defined procedures.
IEEE_SET_ROUNDING_MODE is a procedure from an intrinsic module
(but an optional one). It need not be an external function;
the compiler is free to do other things to implement it.
(Hope this answers your question)
Michael S <already5chosen@yahoo.com> schrieb:
On Sun, 14 Sep 2025 07:18:38 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Michael S <already5chosen@yahoo.com> schrieb:
On Sat, 13 Sep 2025 14:55:58 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Similarly, rounding modes are saved and restored for
procedures.
I am not sure that I understand.
1. Is Fortran's equivalent of C's fesetround() is considered a
languge primitive rather than procedure?
Fortran has intrinsic procedures (like SIN, MATMUL or CPU_TIME),
procedures from intrinsic modules, like COMPILER_OPTIONS
from ISO_FORTRAN_ENV, and user-defined procedures.
IEEE_SET_ROUNDING_MODE is a procedure from an intrinsic module
(but an optional one). It need not be an external function;
the compiler is free to do other things to implement it.
(Hope this answers your question)
OOOPS.
Seems I misread the standard, missing out on clause 17.4 paragraph 5,
which states
In a procedure other than IEEE_SET_ROUNDING_MODE or IEEE_SET_STATUS,
the processor shall not change the rounding modes on entry, and
on return shall ensure that the rounding modes are the same as
they were on entry.
So, that part of my premise was wrong. Sorry.
MitchAlsup <user5857@newsgrouper.org.invalid> schrieb:
Thomas Koenig <tkoenig@netcologne.de> posted:
The CPU could speculate on the FP mode (not sure if that is actuallyMulti-threaded cores already have to ship different RMs to FUs on
done). Other suggestions? How do current CPUs do so?
each FP instruction. The HW is all there--its the ISAs that are screwed
up.
And that would be an interesting part - how to specify this
efficiently, and allow the microarchiteture not to flush when
rounding modes are changed.
Fortran has an optional IEEE module. One of its important features
is that flags (IEEE exceptions) are set to quiet on entry of a procedure
and restored to signalling if it was signalling on entry, or keep it signalling if it was raised on in the procedure. Similarly, rounding
modes are saved and restored for procedures. This is automatically
done if the right IEEE modules are used. A user can set rounding
modes or set and clear exceptions using the right modes.
On Sun, 14 Sep 2025 07:18:38 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Michael S <already5chosen@yahoo.com> schrieb:
On Sat, 13 Sep 2025 14:55:58 -0000 (UTC)
2. Does above said mean that caller has no way of modifying rounding
mode used by callee? If true, it defeats one of original reasons for
which Kahan invented rounding modes in the first place.
The caller cannot change the callee's rounding mode without the
callee having been designed for this (by taking the rounding mode
as an extra argument and using IEEE_SET_ROUNDING_MODE itself).
I think that's a good idea. If a library routine is written
and debugged for a particular rounding mode, results should
not change because somebody up the call tree changed it.
Personally, I never found the whole rounding modes business useful in
my practice. So, can not say with straight face whether Fortran's take
on it is good idea or not. But I can say with good level of certainty
that William Kahan meant something else.
Michael S <already5chosen@yahoo.com> schrieb:
On Sun, 14 Sep 2025 07:18:38 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Michael S <already5chosen@yahoo.com> schrieb:
On Sat, 13 Sep 2025 14:55:58 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Similarly, rounding modes are saved and restored for procedures.
I am not sure that I understand.
1. Is Fortran's equivalent of C's fesetround() is considered a
languge primitive rather than procedure?
Fortran has intrinsic procedures (like SIN, MATMUL or CPU_TIME),
procedures from intrinsic modules, like COMPILER_OPTIONS
from ISO_FORTRAN_ENV, and user-defined procedures.
IEEE_SET_ROUNDING_MODE is a procedure from an intrinsic module
(but an optional one). It need not be an external function;
the compiler is free to do other things to implement it.
(Hope this answers your question)
OOOPS.
Seems I misread the standard, missing out on clause 17.4 paragraph 5,
which states
In a procedure other than IEEE_SET_ROUNDING_MODE or IEEE_SET_STATUS,
the processor shall not change the rounding modes on entry, and
on return shall ensure that the rounding modes are the same as
they were on entry.
Personally, I never found the whole rounding modes business useful in my practice.
On Sun, 14 Sep 2025 10:52:10 +0300, Michael S wrote:
Personally, I never found the whole rounding modes business useful in myI remember one of Kahan’s writings suggesting it is useful for testing numeric stability: if your code gives results that differ only slightly in the four different rounding modes, then your calculations are *probably* stable; if the results vary a lot, then your calculations are *probably* unstable.
practice.
Lawrence D’Oliveiro [2025-09-15 02:31:04] wrote:
On Sun, 14 Sep 2025 10:52:10 +0300, Michael S wrote:
Personally, I never found the whole rounding modes business useful in my >>> practice.I remember one of Kahan’s writings suggesting it is useful for testing
numeric stability: if your code gives results that differ only slightly in >> the four different rounding modes, then your calculations are *probably*
stable; if the results vary a lot, then your calculations are *probably*
unstable.
IIUC you can get the same result by adding a bit a noise to your inputs
and compare the output.
Thomas Koenig <tkoenig@netcologne.de> wrote:
Michael S <already5chosen@yahoo.com> schrieb:
On Sun, 14 Sep 2025 07:18:38 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Michael S <already5chosen@yahoo.com> schrieb:
On Sat, 13 Sep 2025 14:55:58 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Similarly, rounding modes are saved and restored for
procedures.
I am not sure that I understand.
1. Is Fortran's equivalent of C's fesetround() is considered a
languge primitive rather than procedure?
Fortran has intrinsic procedures (like SIN, MATMUL or CPU_TIME),
procedures from intrinsic modules, like COMPILER_OPTIONS
from ISO_FORTRAN_ENV, and user-defined procedures.
IEEE_SET_ROUNDING_MODE is a procedure from an intrinsic module
(but an optional one). It need not be an external function;
the compiler is free to do other things to implement it.
(Hope this answers your question)
OOOPS.
Seems I misread the standard, missing out on clause 17.4 paragraph
5, which states
In a procedure other than IEEE_SET_ROUNDING_MODE or IEEE_SET_STATUS,
the processor shall not change the rounding modes on entry, and
on return shall ensure that the rounding modes are the same as
they were on entry.
IIUC this means that user can not define routine like
'MY_SET_ROUNDING_MODE' and get desired effect (this probably can be
worked around using foreign function interface).
On Sun, 14 Sep 2025 16:22:33 -0000 (UTC)
antispam@fricas.org (Waldek Hebisch) wrote:
Thomas Koenig <tkoenig@netcologne.de> wrote:
Michael S <already5chosen@yahoo.com> schrieb:
On Sun, 14 Sep 2025 07:18:38 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Michael S <already5chosen@yahoo.com> schrieb:
On Sat, 13 Sep 2025 14:55:58 -0000 (UTC)
Thomas Koenig <tkoenig@netcologne.de> wrote:
Similarly, rounding modes are saved and restored for
procedures.
I am not sure that I understand.
1. Is Fortran's equivalent of C's fesetround() is considered a
languge primitive rather than procedure?
Fortran has intrinsic procedures (like SIN, MATMUL or CPU_TIME),
procedures from intrinsic modules, like COMPILER_OPTIONS
from ISO_FORTRAN_ENV, and user-defined procedures.
IEEE_SET_ROUNDING_MODE is a procedure from an intrinsic module
(but an optional one). It need not be an external function;
the compiler is free to do other things to implement it.
(Hope this answers your question)
OOOPS.
Seems I misread the standard, missing out on clause 17.4 paragraph
5, which states
In a procedure other than IEEE_SET_ROUNDING_MODE or IEEE_SET_STATUS,
the processor shall not change the rounding modes on entry, and
on return shall ensure that the rounding modes are the same as
they were on entry.
IIUC this means that user can not define routine like
'MY_SET_ROUNDING_MODE' and get desired effect (this probably can be
worked around using foreign function interface).
I am not sure that I understood.
Do you want to say that user can not write routines that call IEEE_SET_ROUNDING_MODE ? I don't see anything in citation above that
suggests that.
Or do you mean something else?
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,070 |
Nodes: | 10 (0 / 10) |
Uptime: | 127:44:36 |
Calls: | 13,731 |
Calls today: | 1 |
Files: | 186,965 |
D/L today: |
1,259 files (486M bytes) |
Messages: | 2,417,822 |