This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add fma support to the middle end and powerpc


This patch is the refinement of the patch I posted earlier as a RFC.  It adds
the basic infrastructure to the compiler to support the fma, fmaf, and fmal
builtins if the machine supports the fmasf4, fmadf4, etc. patterns.  I added
support in the rs6000 to support fma and fmaf if normal hardware floating point
is used.

I ripped out the code in c-family/c-cppbuiltin.c to define __FP_FAST_FMA,
__FP_FAST_FMAF, and __FP_FAST_FMAL, and moved the code to the rs6000-c.c
backend.  This is due to the fact that the c-cppbuiltin.c does not include the
rtl machinary to say whether fma's are currently generated.

I fixed the spelling of fmaf (I kept using fmas because of the spelling of the
rs6000 instruction).

Since the rs6000 is the only port (so far) that provides fma and fmaf, it was
simpler to define the macros in the backend, rather than come up with some
callback mechanism where either c-cppbuiltin calls the rtl layer to ask if it
has fma, or the rtl layer uses a target hook to define the macros if the
preprocessor is loaded.

This patch bootstraps and introduces no regressions.  Is it ok to install in
the tree?

[gcc]
2010-10-13  Michael Meissner  <meissner@linux.vnet.ibm.com>

	* doc/md.texi (Standard Names): Add fma@{var{m}4 documentation.

	* doc/rtl.texi (RTX_TERNARY): Document FMA is ternary.  Add
	SIGN_EXTRACT and ZERO_EXTRACT which were missing.
	(Standard names): Document fma.

	* doc/cpp.texi (Common Predefined Macros): Document __FP_FAST_FMA,
	__FP_FAST_FMAF, __FP_FAST_FMAL.

	* builitns.c (expand_builtin_mathfn_ternary): New function for
	expanding ternary math functions, like fma.
	(expand_builtin): Call it for the fma builtins.

	* simplify-rtx.c (simplify_ternary_operation): Don't simplify FMA
	ops at present.

	* tree-vect-stmts.c (vectorizable_call): Allow 3 argument
	vectorizable functions to support vectorizing fma.

	* config/rs6000/rs6000.c (rs6000_builtin_vectorized_function):
	Handle fma builtins.

	* config/rs6000/vsx.md (UNSPEC_VSX_MADD): Delete.
	(UNSPEC_VSX_MSUB): Ditto.
	(UNSPEC_VSX_NMADD): Ditto.
	(UNSPEC_VSX_NMSUB): Ditto.
	(vsx_fmadd<mode>4*): Rewrite to use FMA rtl in some cases instead
	of UNSPEC. Renumber combiner patterns.
	(vsx_fmsub<mode>4*): Ditto.
	(vsx_fnmadd<mode>4*): Ditto.
	(vsx_fnmsub<mode>4*): Ditto.

	* config/rs6000/altivec.md (UNSPEC_VNMSUBFP): Delete.
	(altivec_vmaddfp): Rewrite to use FMA rtl if no fused
	multiply/add.  Rename combiner pattern, and add TARGET_FUSED_MADD
	test.
	(altivec_vmaddfp_1): Ditto.
	(altivec_vmaddfp_2): Ditto.
	(atlivec_mulv4sf3): Ditto.
	(altivec_vnmsubfp): Ditto.
	(altivec_vnmsubfp_1): Ditto.
	(altivec_vnmsubfp_2): Ditto.
	(altivec_vnmsubfp_3): Delete.

	* config/rs6000/rs6000.md (UNSPEC_FMA): Delete.
	(fmasf4): Rewrite to always use FMA rtl.  Add combiners to
	generate the four fused multiply/add ops.  Combine power, powerpc
	ops.
	(fmasf4_fpr): Ditto.
	(fmssf4_fpr): Ditto.
	(fnmasf4_fpr): Ditto.
	(fnmssf4_fpr): Ditto.
	(fmadf4): Ditto.
	(fmadf4_fpr): Ditto.
	(fmsdf4_fpr): Ditto.
	(fnmadf4_fpr): Ditto.
	(fnmsdf4_fpr): Ditto.

	* config/rs6000/rs6000-c.c (rs6000_cpu_cpp_builtins): Define
	__FP_FAST_FMA, __FP_FAST_FMAF if we have normal hardware floating
	point.

	* optabs.h (OTI_fma): Add fma optab.
	(fma_optab): Ditto.

	* genopinit.c (optabs): Set fma optab.

	* rtl.def (FMA): Add FMA rtl.

[gcc/testsuite]
2010-10-13  Michael Meissner  <meissner@linux.vnet.ibm.com>

	* gcc.target/powerpc/ppc-fma-1.c: Update tests for powerpc FMA
	builtin combiner patterns.
	* gcc.target/powerpc/ppc-fma-2.c: Ditto.
	* gcc.target/powerpc/ppc-fma-3.c: Ditto.
	* gcc.target/powerpc/ppc-fma-4.c: Ditto.

-- 
Michael Meissner, IBM
5 Technology Place Drive, M/S 2757, Westford, MA 01886-3141, USA
meissner@linux.vnet.ibm.com

Attachment: gcc-power7.patch169b
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]