amd64/115581: [fix] -mfancy-math-387 has no effect

Simun Mikecin numisemis at
Thu Aug 16 09:50:02 PDT 2007

>Number:         115581
>Category:       amd64
>Synopsis:       [fix] -mfancy-math-387 has no effect
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-amd64
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug 16 16:50:01 GMT 2007
>Originator:     Simun Mikecin
>Release:        FreeBSD/amd64 7-CURRENT
32-bit compatibility libraries on FreeBSD/amd64 are compiled using -mfancy-math-387 gcc option. As stated in gcc(1):

           Some 387 emulators do not support the "sin", "cos" and "sqrt"
           instructions for the 387.  Specify this option to avoid generating
           those instructions.  This option is the default on FreeBSD, OpenBSD
           and NetBSD.  This option is overridden when -march indicates that
           the target cpu will always have an FPU and so the instruction will
           not need emulation.  As of revision 2.6.1, these instructions are
           not generated unless you also use the -funsafe-math-optimizations

So, using just -mfancy-math-387 has no effect. It should be used in combination with -funsafe-math-optimizations or it should not be used.

double test(double x) {
  return sin(x);

Try to compile using:
gcc -m32 -S -mfancy-math-387 -funsafe-math-optimizations -O2 -march=athlon64 test.c

and with:
gcc -m32 -S -mfancy-math-387 -O2 -march=athlon64 test.c

There will be a difference in assembler output. First one will use machine instruction 'fsin' and the second one will use a libm routine called 'sin'.


Patch attached with submission follows:

--- Makefile.inc1.orig	Tue Jul 10 18:39:36 2007
+++ Makefile.inc1	Thu Aug 16 18:30:44 2007
@@ -238,7 +238,7 @@
-LIB32FLAGS=	-m32 -march=${LIB32CPUTYPE} -mfancy-math-387 -DCOMPAT_32BIT \
+LIB32FLAGS=	-m32 -march=${LIB32CPUTYPE} -mfancy-math-387 -funsafe-math-optimizations -DCOMPAT_32BIT \
 		-iprefix ${LIB32TMP}/usr/ \
 		-L${LIB32TMP}/usr/lib32 \


More information about the freebsd-amd64 mailing list