diff mbox

[ARM] Add support for crtfastmath.o

Message ID 545E3D6A.4030108@codesourcery.com
State New
Headers show

Commit Message

Sandra Loosemore Nov. 8, 2014, 3:57 p.m. UTC
This patch adds support to the ARM backend to avoid denormals by setting 
the VFP flush-to-zero bit when linking with -ffast-math and similar 
options.  The mechanism used to accomplish this is a constructor in 
libgcc that is conditionally linked in via STARTFILE_SPEC; it's 
basically identical to what a number of other backends are already doing 
here (Aarch64, i386, MIPS, etc).

I tested this by verifying that linking with -ffast-math on the GCC 
command line causes crtfastmath.o to be passed on the ld command line. 
I built libgcc with a variety of configuration options to verify that 
the constructor is suppressed for soft-float targets, that it builds 
successfully for Thumb-2 with VFP, etc.  I also regression-tested the 
gcc testsuite on an arm-none-linux-gnueabi build configured for 
-march=armv8-a with VFP floating point enabled.

OK to commit?

-Sandra

2014-11-08  Sandra Loosemore  <sandra@codesourcery.com>
	    Chris Jones  <chrisj@nvidia.com>
	    Joshua Conner  <jconner@nvidia.com>

	gcc/
	* config/arm/unknown-elf.h (STARTFILE_SPEC): Add conditional
	linking of crtfastmath.o.
	* config/arm/linux-eabi.h (STARTFILE_SPEC): Likewise.

	libgcc/
	* config.host (arm*-*-linux*): Add support for crtfastmath.o.
	(arm*-*-uclinux*): Likewise.
	(arm*-*-eabi* | arm*-*-rtems*): Likewise.
	* config/arm/crtfastmath.c: New file.

Comments

Sandra Loosemore Dec. 7, 2014, 8:52 p.m. UTC | #1
On 11/08/2014 08:57 AM, Sandra Loosemore wrote:
>
> 2014-11-08  Sandra Loosemore  <sandra@codesourcery.com>
>          Chris Jones  <chrisj@nvidia.com>
>          Joshua Conner  <jconner@nvidia.com>
>
>      gcc/
>      * config/arm/unknown-elf.h (STARTFILE_SPEC): Add conditional
>      linking of crtfastmath.o.
>      * config/arm/linux-eabi.h (STARTFILE_SPEC): Likewise.
>
>      libgcc/
>      * config.host (arm*-*-linux*): Add support for crtfastmath.o.
>      (arm*-*-uclinux*): Likewise.
>      (arm*-*-eabi* | arm*-*-rtems*): Likewise.
>      * config/arm/crtfastmath.c: New file.

Ping?

https://gcc.gnu.org/ml/gcc-patches/2014-11/msg00711.html

-Sandra
Sandra Loosemore Dec. 17, 2014, 10:21 p.m. UTC | #2
On 12/07/2014 01:52 PM, Sandra Loosemore wrote:
> On 11/08/2014 08:57 AM, Sandra Loosemore wrote:
>>
>> 2014-11-08  Sandra Loosemore  <sandra@codesourcery.com>
>>          Chris Jones  <chrisj@nvidia.com>
>>          Joshua Conner  <jconner@nvidia.com>
>>
>>      gcc/
>>      * config/arm/unknown-elf.h (STARTFILE_SPEC): Add conditional
>>      linking of crtfastmath.o.
>>      * config/arm/linux-eabi.h (STARTFILE_SPEC): Likewise.
>>
>>      libgcc/
>>      * config.host (arm*-*-linux*): Add support for crtfastmath.o.
>>      (arm*-*-uclinux*): Likewise.
>>      (arm*-*-eabi* | arm*-*-rtems*): Likewise.
>>      * config/arm/crtfastmath.c: New file.
>
> Ping?
>
> https://gcc.gnu.org/ml/gcc-patches/2014-11/msg00711.html

Ping again?

-Sandra
Sandra Loosemore Jan. 8, 2015, 10:14 p.m. UTC | #3
On 12/17/2014 03:21 PM, Sandra Loosemore wrote:
> On 12/07/2014 01:52 PM, Sandra Loosemore wrote:
>> On 11/08/2014 08:57 AM, Sandra Loosemore wrote:
>>>
>>> 2014-11-08  Sandra Loosemore  <sandra@codesourcery.com>
>>>          Chris Jones  <chrisj@nvidia.com>
>>>          Joshua Conner  <jconner@nvidia.com>
>>>
>>>      gcc/
>>>      * config/arm/unknown-elf.h (STARTFILE_SPEC): Add conditional
>>>      linking of crtfastmath.o.
>>>      * config/arm/linux-eabi.h (STARTFILE_SPEC): Likewise.
>>>
>>>      libgcc/
>>>      * config.host (arm*-*-linux*): Add support for crtfastmath.o.
>>>      (arm*-*-uclinux*): Likewise.
>>>      (arm*-*-eabi* | arm*-*-rtems*): Likewise.
>>>      * config/arm/crtfastmath.c: New file.
>>
>> Ping?
>>
>> https://gcc.gnu.org/ml/gcc-patches/2014-11/msg00711.html
>
> Ping again?

And ping again....  Can somebody please review this before stage 4 
starts and it is too late to get it into GCC 5?  This is really a very 
straightforward change and is pretty much identical to what other 
targets (including aarch64) already do.

-Sandra
diff mbox

Patch

Index: gcc/config/arm/unknown-elf.h
===================================================================
--- gcc/config/arm/unknown-elf.h	(revision 216500)
+++ gcc/config/arm/unknown-elf.h	(working copy)
@@ -32,7 +32,9 @@ 
 #define UNKNOWN_ELF_STARTFILE_SPEC	" crti%O%s crtbegin%O%s crt0%O%s"
 
 #undef  STARTFILE_SPEC
-#define STARTFILE_SPEC	UNKNOWN_ELF_STARTFILE_SPEC
+#define STARTFILE_SPEC	\
+  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} "	\
+  UNKNOWN_ELF_STARTFILE_SPEC
 
 #define UNKNOWN_ELF_ENDFILE_SPEC	"crtend%O%s crtn%O%s"
 
Index: gcc/config/arm/linux-eabi.h
===================================================================
--- gcc/config/arm/linux-eabi.h	(revision 216500)
+++ gcc/config/arm/linux-eabi.h	(working copy)
@@ -107,6 +107,7 @@ 
 
 #undef	ENDFILE_SPEC
 #define ENDFILE_SPEC \
+  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} "	\
   LINUX_OR_ANDROID_LD (GNU_USER_TARGET_ENDFILE_SPEC, ANDROID_ENDFILE_SPEC)
 
 /* Use the default LIBGCC_SPEC, not the version in linux-elf.h, as we
Index: libgcc/config.host
===================================================================
--- libgcc/config.host	(revision 216500)
+++ libgcc/config.host	(working copy)
@@ -370,14 +370,15 @@  arm*-*-netbsdelf*)
 	tmake_file="$tmake_file arm/t-arm arm/t-netbsd t-slibgcc-gld-nover"
 	;;
 arm*-*-linux*)			# ARM GNU/Linux with ELF
-	tmake_file="${tmake_file} arm/t-arm t-fixedpoint-gnu-prefix"
+	tmake_file="${tmake_file} arm/t-arm t-fixedpoint-gnu-prefix t-crtfm"
 	tmake_file="${tmake_file} arm/t-elf arm/t-bpabi arm/t-linux-eabi t-slibgcc-libgcc"
 	tm_file="$tm_file arm/bpabi-lib.h"
 	unwind_header=config/arm/unwind-arm.h
 	tmake_file="$tmake_file t-softfp-sfdf t-softfp-excl arm/t-softfp t-softfp"
+	extra_parts="$extra_parts crtfastmath.o"
 	;;
 arm*-*-uclinux*)		# ARM ucLinux
-	tmake_file="${tmake_file} t-fixedpoint-gnu-prefix"
+	tmake_file="${tmake_file} t-fixedpoint-gnu-prefix t-crtfm"
 	tmake_file="$tmake_file arm/t-arm arm/t-elf t-softfp-sfdf t-softfp-excl arm/t-softfp t-softfp"
 	tmake_file="${tmake_file} arm/t-bpabi"
 	tm_file="$tm_file arm/bpabi-lib.h"
@@ -389,7 +390,7 @@  arm*-*-eabi* | arm*-*-symbianelf* | arm*
 	tm_file="$tm_file arm/bpabi-lib.h"
 	case ${host} in
 	arm*-*-eabi* | arm*-*-rtems*)
-	  tmake_file="${tmake_file} arm/t-bpabi"
+	  tmake_file="${tmake_file} arm/t-bpabi t-crtfm"
 	  extra_parts="crtbegin.o crtend.o crti.o crtn.o"
 	  ;;
 	arm*-*-symbianelf*)
Index: libgcc/config/arm/crtfastmath.c
===================================================================
--- libgcc/config/arm/crtfastmath.c	(revision 0)
+++ libgcc/config/arm/crtfastmath.c	(revision 0)
@@ -0,0 +1,40 @@ 
+/*
+ * Copyright (C) 2014 Free Software Foundation, Inc.
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 3, or (at your option) any
+ * later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * Under Section 7 of GPL version 3, you are granted additional
+ * permissions described in the GCC Runtime Library Exception, version
+ * 3.1, as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License and
+ * a copy of the GCC Runtime Library Exception along with this program;
+ * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+/* Enable flush-to-zero support for -ffast-math on VFP targets.  */
+#ifndef __SOFTFP__
+
+#define FPSCR_FZ		(1 << 24)
+
+static void __attribute__((constructor))
+__arm_set_fast_math (void)
+{
+  unsigned int fpscr_save;
+
+  /* Set the FZ (flush-to-zero) bit in FPSCR.  */
+  __asm__("vmrs %0, fpscr" : "=r" (fpscr_save));
+  fpscr_save |= FPSCR_FZ;
+  __asm__("vmsr fpscr, %0" : : "r" (fpscr_save));
+}
+
+#endif /* __SOFTFP__  */