This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, MIPS] .gnu.attribute support for sdemtk -mno-float
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: Jim Wilson <wilson at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 08 May 2010 17:55:47 +0100
- Subject: Re: [PATCH, MIPS] .gnu.attribute support for sdemtk -mno-float
- References: <1272073570.2650.122.camel@localhost> <871vdwnigy.fsf@firetop.home> <1272917991.3996.77.camel@localhost>
Jim Wilson <wilson@codesourcery.com> writes:
> Suppose you are a 3rd party library vendor, and you want to build and
> distribute a library compatible with an MTI and/or CodeSourcery
> toolchain. Your library does not use any FP code. And yet, because of
> the FP ABI encoded into .gnu_attribute, you must build and distribute 4
> different versions of your library compiled for the 4 different FP ABIs.
> The -mno-float option solves this problem. It is a compile time
> assertion that there is no FP code, and hence the result is compatible
> with all 4 FP ABIs. If you compile with -mno-float, you now need only
> one version of the library for the different FP ABIs.
Right, I appreciate that. It was more...
> It is true, the current implementation of -mno-float only differs in
> library construction and preprocessor macros. It is possible that
> future implementations could do more to verify the compile-time
> assertion. Meanwhile, however, the main purpose of the -mno-float
> option is currently not being served, because an important piece is
> missing, the gnu_attribute setting. I believe the .gnu_attribute patch
> should be added in, irrespective of whether the -mno-float
> implementation is improved. I think improving the -mno-float
> implementation to do more compile-time checking for FP code should be a
> separate issue.
...this that I was worried about. We wouldn't want the same behaviour
for -msoft-float -DSOME_MACRO, even though that's actually entirely
equivalent to what -mno-float does from a compiler perspective.
I think this is one of those situations where neither of us is going to
convince the other. Since I've noted my reservations, and since it's an
SDE-specific patch, I'll back down.
However, I don't like the idea of hiding the option behind even more
hooks. I'd prefer to expose TARGET_NO_FLOAT to the generic code instead.
Any objections to the following alternative? Tested on mipsisa64-elf
and by inspection on mipsisa64-sde-elf.
I've kept the option specific to SDE targets for now. I'd be happy
to open it up to other targets in future if the lack of FP operations
is ever properly enforced.
Richard
2010-05-08 Richard Sandiford <rdsandiford@googlemail.com>
Jim Wilson <wilson@codesourcery.com>
gcc/
* config.gcc (mips*-sde-elf*): Don't use sdemtk.opt.
* config/mips/mips.h (TARGET_CPU_CPP_BUILTINS): Define __mips_no_float
for TARGET_NO_FLOAT.
* config/mips/mips.c (mips_file_start): Expand conditional expression
into "if" statements. Use .gnu_attribute 4,0 for TARGET_NO_FLOAT.
(mips_override_options): Move -mno-float override -msoft-float and
-mhard-float.
* config/mips/mips.opt (mno-float): Move from sdemtk.opt, but add
Condition(TARGET_SUPPORTS_NO_FLOAT).
* config/mips/sdemtk.h (TARGET_OS_CPP_BUILTINS): Don't set
__mips_no_float here.
(SUBTARGET_OVERRIDE_OPTIONS): Delete.
(TARGET_SUPPORTS_NO_FLOAT): Define.
* config/mips/sdemtk.opt: Delete.
Index: gcc/config.gcc
===================================================================
--- gcc/config.gcc 2010-05-08 08:46:49.000000000 +0100
+++ gcc/config.gcc 2010-05-08 08:46:56.000000000 +0100
@@ -1764,7 +1764,6 @@ mips*-sde-elf*)
# MIPS toolkit libraries.
tm_file="$tm_file mips/sdemtk.h"
tmake_file="$tmake_file mips/t-sdemtk"
- extra_options="$extra_options mips/sdemtk.opt"
case ${enable_threads} in
"" | yes | mipssde)
thread_file='mipssde'
Index: gcc/config/mips/mips.h
===================================================================
--- gcc/config/mips/mips.h 2010-05-08 08:48:57.000000000 +0100
+++ gcc/config/mips/mips.h 2010-05-08 08:49:22.000000000 +0100
@@ -537,7 +537,9 @@ #define TARGET_CPU_CPP_BUILTINS() \
\
/* These defines reflect the ABI in use, not whether the \
FPU is directly accessible. */ \
- if (TARGET_HARD_FLOAT_ABI) \
+ if (TARGET_NO_FLOAT) \
+ builtin_define ("__mips_no_float"); \
+ else if (TARGET_HARD_FLOAT_ABI) \
builtin_define ("__mips_hard_float"); \
else \
builtin_define ("__mips_soft_float"); \
Index: gcc/config/mips/mips.c
===================================================================
--- gcc/config/mips/mips.c 2010-05-08 08:51:55.000000000 +0100
+++ gcc/config/mips/mips.c 2010-05-08 09:01:56.000000000 +0100
@@ -8185,10 +8185,27 @@ mips_file_start (void)
"\t.previous\n", TARGET_LONG64 ? 64 : 32);
#ifdef HAVE_AS_GNU_ATTRIBUTE
- fprintf (asm_out_file, "\t.gnu_attribute 4, %d\n",
- (TARGET_HARD_FLOAT_ABI
- ? (TARGET_DOUBLE_FLOAT
- ? ((!TARGET_64BIT && TARGET_FLOAT64) ? 4 : 1) : 2) : 3));
+ {
+ int attr;
+
+ /* No floating-point operations, -mno-float. */
+ if (TARGET_NO_FLOAT)
+ attr = 0;
+ /* Soft-float code, -msoft-float. */
+ else if (!TARGET_HARD_FLOAT_ABI)
+ attr = 3;
+ /* Single-float code, -msingle-float. */
+ else if (!TARGET_DOUBLE_FLOAT)
+ attr = 2;
+ /* 64-bit FP registers on a 32-bit target, -mips32r2 -mfp64. */
+ else if (!TARGET_64BIT && TARGET_FLOAT64)
+ attr = 4;
+ /* Regular FP code, FP regs same size as GP regs, -mdouble-float. */
+ else
+ attr = 1;
+
+ fprintf (asm_out_file, "\t.gnu_attribute 4, %d\n", attr);
+ }
#endif
}
@@ -15389,6 +15406,13 @@ mips_override_options (void)
SUBTARGET_OVERRIDE_OPTIONS;
#endif
+ /* -mno-float overrides -mhard-float and -msoft-float. */
+ if (TARGET_NO_FLOAT)
+ {
+ target_flags |= MASK_SOFT_FLOAT_ABI;
+ target_flags_explicit |= MASK_SOFT_FLOAT_ABI;
+ }
+
/* Set the small data limit. */
mips_small_data_threshold = (g_switch_set
? g_switch_value
Index: gcc/config/mips/mips.opt
===================================================================
--- gcc/config/mips/mips.opt 2010-05-08 08:57:22.000000000 +0100
+++ gcc/config/mips/mips.opt 2010-05-08 08:57:50.000000000 +0100
@@ -224,6 +224,10 @@ mmt
Target Report Var(TARGET_MT)
Allow the use of MT instructions
+mno-float
+Target Report RejectNegative Var(TARGET_NO_FLOAT) Condition(TARGET_SUPPORTS_NO_FLOAT)
+Prevent the use of all floating-point operations
+
mno-flush-func
Target RejectNegative
Do not use a cache-flushing function before calling stack trampolines
Index: gcc/config/mips/sdemtk.h
===================================================================
--- gcc/config/mips/sdemtk.h 2010-05-08 08:48:45.000000000 +0100
+++ gcc/config/mips/sdemtk.h 2010-05-08 08:58:41.000000000 +0100
@@ -35,10 +35,7 @@ #define TARGET_OS_CPP_BUILTINS() \
builtin_define ("__mipsfp64"); \
\
if (TARGET_NO_FLOAT) \
- { \
- builtin_define ("__NO_FLOAT"); \
- builtin_define ("__mips_no_float"); \
- } \
+ builtin_define ("__NO_FLOAT"); \
else if (TARGET_SOFT_FLOAT_ABI) \
builtin_define ("__SOFT_FLOAT"); \
else if (TARGET_SINGLE_FLOAT) \
@@ -57,18 +54,6 @@ #define TARGET_OS_CPP_BUILTINS() \
} \
while (0)
-#undef SUBTARGET_OVERRIDE_OPTIONS
-#define SUBTARGET_OVERRIDE_OPTIONS \
- do \
- { \
- if (TARGET_NO_FLOAT) \
- { \
- target_flags |= MASK_SOFT_FLOAT_ABI; \
- target_flags_explicit |= MASK_SOFT_FLOAT_ABI; \
- } \
- } \
- while (0)
-
/* For __clear_cache in libgcc2.c. */
#ifdef IN_LIBGCC2
extern void mips_sync_icache (void *beg, unsigned long len);
@@ -113,3 +98,6 @@ #define FUNCTION_PROFILER(FILE, LABELNO)
/* ...nor does the call sequence preserve $31. */
#undef MIPS_SAVE_REG_FOR_PROFILING_P
#define MIPS_SAVE_REG_FOR_PROFILING_P(REGNO) ((REGNO) == RETURN_ADDR_REGNUM)
+
+/* Compile in support for the -mno-float option. */
+#define TARGET_SUPPORTS_NO_FLOAT 1
Index: gcc/config/mips/sdemtk.opt
===================================================================
--- gcc/config/mips/sdemtk.opt 2010-05-08 08:58:54.000000000 +0100
+++ /dev/null 2010-05-08 09:05:06.395398768 +0100
@@ -1,23 +0,0 @@
-; Options for the MIPS SDE configuration.
-;
-; Copyright (C) 2007 Free Software Foundation, Inc.
-;
-; This file is part of GCC.
-;
-; GCC 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.
-;
-; GCC 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.
-;
-; You should have received a copy of the GNU General Public License
-; along with GCC; see the file COPYING3. If not see
-; <http://www.gnu.org/licenses/>.
-
-mno-float
-Target Report RejectNegative Var(TARGET_NO_FLOAT)
-Prevent the use of all floating-point operations