On 10/19/2017 06:07 AM, Wilco Dijkstra wrote: > Vladimir wrote: > > +# Disable floating-point expression contraction > +LIBGCC2_FFP_CONTRAST_CFLAGS = -ffp-contract=off > + > > It looks like this disables fp-contract in all of libgcc... > What is the the number of FMAs in libgcc before/after? In original (without my fix) libgcc_s.so: % objdump -d libgcc_s.so| egrep '(fmadd|fmsub|fnmadd|fnmsub)'|wc -l 38
In my new libgcc_s.so ( see my fix below) % objdump -d libgcc_s.so| egrep '(fmadd|fmsub|fnmadd|fnmsub)'|wc -l 8 > If it disables anything other than the ones in complex division, it > would have an unintended performance impact. It's best to do > this just for complex division. On 10/19/2017 10:17 AM, Wilco Dijkstra wrote: > Vladimir Mezentsev <vladimir.mezent...@oracle.com> >> On 10/19/2017 06:37 AM, Richard Earnshaw (lists) wrote: >>> On 19/10/17 14:07, Wilco Dijkstra wrote: >>>> Vladimir wrote: >>>> >>>> +# Disable floating-point expression contraction >>>> +LIBGCC2_FFP_CONTRAST_CFLAGS = -ffp-contract=off >>>> + >>>> >>>> It looks like this disables fp-contract in all of libgcc... >>>> What is the the number of FMAs in libgcc before/after? >> How can I find this number ? >> dis <all functions in libgcc> | grep <all FMAs> | wc > Eg. objdump -d ~/install/gcc/lib64/libgcc_s.so | grep -c fmadd > Also grep fmsub, fnmadd, fnmsub. > >>> It's probably better to do this with an attribute >>> >>> __attribute__((optimize("fp-contract=off"))) >>> >>> on the affected functions. >> I like your suggestion. > I don't think this will work in general, IIRC only a few targets correctly > implement the optimize pragma. Changing the makefile to build only > __divdc3/__divtc3/__divsc3/__divhc3 without FMA looks like a better > approach. Only 3 (_divdc3 / _divhc3 / _divsc3) have FMAs. The other FMAs are in: _fixunsdfdi.o _fixunsdfdi_s.o _fixunssfdi.o _fixunssfdi_s.o _muldc3.o _muldc3_s.o _mulhc3.o _mulhc3_s.o _mulsc3.o _mulsc3_s.o I suggest the following fix: % git diff diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in index a1a392d..f313556 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -455,6 +455,14 @@ ifeq ($(LIB2_SIDITI_CONV_FUNCS),) lib2funcs += $(subst XX,di,$(dwfloatfuncs)) endif +# Disable FMA (floating-point multiply-add) instructions for complex division. +# These instructions can produce different result if two operations executed separately. +LIBGCC2_FFP_CONTRAST_CFLAGS = -ffp-contract=off +LIB2_DIV3_FUNCS = _divdc3 _divhc3 _divsc3 +lib2-div3-o = $(patsubst %,%$(objext),$(LIB2_DIV3_FUNCS)) +lib2-div3-s-o = $(patsubst %,%_s$(objext),$(LIB2_DIV3_FUNCS)) +$(lib2-div3-o) $(lib2-div3-s-o): LIBGCC2_CFLAGS += $(LIBGCC2_FFP_CONTRAST_CFLAGS) + If my fix will be approved I send ChangeLog and a patch file tomorrow. -Vladimir > However we also need to decide whether this is the best possible fix. > It will affect accuracy of other inputs as well... > > Wilco