J
juergen perlinger
Hello out there.
sometimes I need to have proper control of the floating point arithmetic of
the C(and C++) runtime system, and using the f.p. exception handling of the
C99 standard is quite handy for that purpose. The only problem when dealing
with f.p. exception signals is that there is (afaik) no specification *when*
the f.p. exception is raised, with one notable exception:
'feraiseexcept(int)' raises the exceptions passed in the argument mask
before it returns.
Imagine a series of operations that might fail with an FPU exception
(SIGFPE, if your UN*X bound). The FPU might excute the instructions on her
own schedule, not too tightly coupled to the CPU. At certain points I must
be sure that there are no more pending f.p. exceptions slumbering in the
FPU, so you need to enforce a synchronisation between CPU and FPU. To
execute 'feraiseexcept(fetestexcept(FE_ALL_EXCEPT))' just to make sure of
that seems quite heavy-handed.
After working through the documentation of the open group and the
implementation of
Cygnus/ReadHat 'newlib' as well as the GNU libc source I still found no
other portable way to make sure that there are no pending exceptions after a
synchronisation point.
Perhaps I'm just misinterpreting standards; but if there's anything I've
learned about standards it's one thing: *NEVER*ASSUME*ANYTHING*. So, could
someone give some more hints about the synchronization properties of the
functions defined in the C99 <fenv.h> header and the underlying FPU
hardware, if there are any?
regards
pearly
--never use a computer when an abacus is sufficient--
sometimes I need to have proper control of the floating point arithmetic of
the C(and C++) runtime system, and using the f.p. exception handling of the
C99 standard is quite handy for that purpose. The only problem when dealing
with f.p. exception signals is that there is (afaik) no specification *when*
the f.p. exception is raised, with one notable exception:
'feraiseexcept(int)' raises the exceptions passed in the argument mask
before it returns.
Imagine a series of operations that might fail with an FPU exception
(SIGFPE, if your UN*X bound). The FPU might excute the instructions on her
own schedule, not too tightly coupled to the CPU. At certain points I must
be sure that there are no more pending f.p. exceptions slumbering in the
FPU, so you need to enforce a synchronisation between CPU and FPU. To
execute 'feraiseexcept(fetestexcept(FE_ALL_EXCEPT))' just to make sure of
that seems quite heavy-handed.
After working through the documentation of the open group and the
implementation of
Cygnus/ReadHat 'newlib' as well as the GNU libc source I still found no
other portable way to make sure that there are no pending exceptions after a
synchronisation point.
Perhaps I'm just misinterpreting standards; but if there's anything I've
learned about standards it's one thing: *NEVER*ASSUME*ANYTHING*. So, could
someone give some more hints about the synchronization properties of the
functions defined in the C99 <fenv.h> header and the underlying FPU
hardware, if there are any?
regards
pearly
--never use a computer when an abacus is sufficient--