This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
alpha IEEE floating-point patch
- To: gcc-patches at gcc dot gnu dot org
- Subject: alpha IEEE floating-point patch
- From: Brad Lucier <lucier at math dot purdue dot edu>
- Date: Wed, 25 Aug 1999 10:54:51 -0500 (EST)
- Cc: lucier at math dot purdue dot edu, staff at math dot purdue dot edu, hosking at cs dot purdue dot edu
Here are two suggested patches for gcc against 2.95.1. Everything
bootstraps fine.
The first eliminates the generation of trapb instructions if the processor
is ev6. These instructions are no-ops on ev6, but I want to eliminate
them from the instruction fetch queue. They can also inhibit later
code motion (perhaps there is no later code motion, but ...).
The second adds an option -mieee-exceptions to the alpha port. This
option means to rely on IEEE exceptions for built-in elementary functions
(currently only sqrt), not errno. I think that this is ISO-C compliant
for the following reasons (with quotations from my draft ISO-C standard):
[#2] For all functions, a domain error occurs if an input
argument is outside the domain over which the mathematical
function is defined. ...
On a domain error, the function returns an
implementation-defined value; whether the integer expression
errno acquires the value EDOM is implementation-defined.
So not setting errno to EDOM if the sqrt is given a negative argument, or
a NaN, as an argument is OK, even though
[#2] The sqrt functions compute the nonnegative square root
of x. A domain error occurs if the argument is less than
zero.
I think that further support for this position can be found in appendix
F, which does not mention domain errors at all, and which also says:
-- The sqrt function in <math.h> provides the IEC 60559
square root operation.
and
F.9.4.5 The sqrt functions
[#1] sqrt is fully specified as a basic arithmetic operation
in IEC 60559.
Since sqrt is "fully specified" in IEC 60559, and IEC 60559 does not
mention domain errors, I don't feel bad about not not setting errno to
EDOM if I don't want to. IEEE arithmetic allows one to consider
all inputs to sqrt as valid, if you want to, and I generally want to.
The second patch makes an electrostatic force calculation in a molecular
dynamics simulation (which is the main part of the computation) go about
15% faster.
Brad Lucier lucier@math.purdue.edu
===================================================================
RCS file: RCS/alpha.c,v
retrieving revision 1.1
diff -c -r1.1 alpha.c
*** /tmp/T0a003pT Wed Aug 25 09:02:14 1999
--- alpha.c Tue Aug 24 20:36:20 1999
***************
*** 150,155 ****
--- 150,160 ----
alpha_fptm = ALPHA_FPTM_SUI;
}
+ if (TARGET_IEEE_EXCEPTIONS)
+ {
+ flag_errno_math = 0;
+ }
+
if (alpha_tp_string)
{
if (! strcmp (alpha_tp_string, "p"))
***************
*** 5036,5042 ****
alpha_reorg (insns)
rtx insns;
{
! if (alpha_tp != ALPHA_TP_PROG || flag_exceptions)
alpha_handle_trap_shadows (insns);
#ifdef HAIFA
--- 5041,5049 ----
alpha_reorg (insns)
rtx insns;
{
! /* ev4 and ev5 need floating-point software trap completion */
! if (((alpha_cpu == PROCESSOR_EV4) || (alpha_cpu == PROCESSOR_EV5))
! && (alpha_tp != ALPHA_TP_PROG || flag_exceptions))
alpha_handle_trap_shadows (insns);
#ifdef HAIFA
===================================================================
RCS file: RCS/alpha.h,v
retrieving revision 1.1
diff -c -r1.1 alpha.h
*** /tmp/T0a003pT Wed Aug 25 09:02:16 1999
--- alpha.h Tue Aug 24 20:39:15 1999
***************
*** 155,160 ****
--- 155,164 ----
#define MASK_CIX (1 << 11)
#define TARGET_CIX (target_flags & MASK_CIX)
+ /* This means that the we rely on IEEE exceptions, not errno */
+ #define MASK_IEEE_EXCEPTIONS (1 << 12)
+ #define TARGET_IEEE_EXCEPTIONS (target_flags & MASK_IEEE_EXCEPTIONS)
+
/* This means that the processor is an EV5, EV56, or PCA56. This is defined
only in TARGET_CPU_DEFAULT. */
#define MASK_CPU_EV5 (1 << 28)
***************
*** 201,206 ****
--- 205,212 ----
"Emit IEEE-conformant code, without inexact exceptions"}, \
{"ieee-with-inexact", MASK_IEEE_WITH_INEXACT|MASK_IEEE_CONFORMANT, \
"Emit IEEE-conformant code, with inexact exceptions"}, \
+ {"ieee-exceptions", MASK_IEEE_EXCEPTIONS, \
+ "Rely on IEEE exceptions, not errno error handling"}, \
{"build-constants", MASK_BUILD_CONSTANTS, \
"Do not emit complex integer constants to read-only memory"}, \
{"float-vax", MASK_FLOAT_VAX, "Use VAX fp"}, \