This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: xscale-elf -mstrict-prototypes
- From: James Lemke <jim at wasabisystems dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 19 Feb 2004 11:32:48 -0500
- Subject: RFA: xscale-elf -mstrict-prototypes
Given this source (gcc/testsuite/arm-g4-1.c):
short int addhi3 (short int a, short int b) __attribute__ ((naked));
short int addhi3 (short int a, short int b)
{
return a + b + (short int)32;
}
The assembler generated (xscale-elf-gcc -O2 -S) is rather poor:
.file "arm-g4-1.c"
.text
.align 2
.global addhi3
.type addhi3, %function
addhi3:
@ Naked Function: prologue and epilogue provided by programmer.
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
mov r1, r1, asl #16
mov r0, r0, asl #16
mov r1, r1, asr #16
add r1, r1, r0, asr #16
add r1, r1, #32
mov r1, r1, asl #16
mov r0, r1, asr #16
.size addhi3, .-addhi3
.ident "GCC: (GNU) 3.5.0 20040216 (experimental)"
This is because of argument widening even in the presence of a
prototype. The attached patch adds the option -mstrict-prototypes (off
by default) which suppresses the widening. So we get (xscale-elf-gcc
-O2 -mstrict-prototypes -S):
.file "arm-g4-1.c"
.text
.align 2
.global addhi3
.type addhi3, %function
addhi3:
@ Naked Function: prologue and epilogue provided by programmer.
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
add r1, r0, r1
add r1, r1, #32
mov r1, r1, asl #16
mov r0, r1, asr #16
.size addhi3, .-addhi3
.ident "GCC: (GNU) 3.5.0 20040216 (experimental)"
make check-gcc shows no regressions.
Patch is attached.
OK to commit?
Jim.
--
James Lemke jim@wasabisystems.com Orillia, Ontario
http://www.wasabisystems.com
Index: gcc/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ChangeLog,v
retrieving revision 2.2789
diff -u -p -r2.2789 ChangeLog
--- gcc/ChangeLog 16 Feb 2004 17:16:40 -0000 2.2789
+++ gcc/ChangeLog 18 Feb 2004 15:47:25 -0000
@@ -1,3 +1,9 @@
+2004-02-18 James Lemke <jim@wasabisystems.com>
+
+ * config/arm/arm.h: Add -mstrict-prototypes.
+ * config/arm/arm.c: Add -mstrict-prototypes.
+ * doc/invoke.texi (-mstrict-prototypes): Document.
+
2004-02-16 Joseph S. Myers <jsm@polyomino.org.uk>
* doc/sourcebuild.texi: Mention backends.html.
Index: gcc/config/arm/arm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/arm/arm.c,v
retrieving revision 1.330
diff -u -p -r1.330 arm.c
--- gcc/config/arm/arm.c 13 Feb 2004 21:49:26 -0000 1.330
+++ gcc/config/arm/arm.c 18 Feb 2004 15:47:50 -0000
@@ -138,6 +138,7 @@ static rtx safe_vector_operand (rtx, enu
static rtx arm_expand_binop_builtin (enum insn_code, tree, rtx);
static rtx arm_expand_unop_builtin (enum insn_code, tree, rtx, int);
static rtx arm_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
+static bool arm_promote_prototypes (tree);
#ifdef OBJECT_FORMAT_ELF
static void arm_elf_asm_named_section (const char *, unsigned int);
@@ -242,7 +243,7 @@ static void arm_setup_incoming_varargs (
#undef TARGET_PROMOTE_FUNCTION_ARGS
#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
#undef TARGET_PROMOTE_PROTOTYPES
-#define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
+#define TARGET_PROMOTE_PROTOTYPES arm_promote_prototypes
#undef TARGET_STRUCT_VALUE_RTX
#define TARGET_STRUCT_VALUE_RTX arm_struct_value_rtx
@@ -12105,6 +12106,14 @@ arm_expand_builtin (tree exp,
/* @@@ Should really do something sensible here. */
return NULL_RTX;
+}
+
+/* Chars and shorts should be passed as ints, unless
+ -mstrict-prototypes is used. */
+static bool
+arm_promote_prototypes (tree a ATTRIBUTE_UNUSED)
+{
+ return ! TARGET_STRICT_PROTOTYPES;
}
/* Recursively search through all of the blocks in a function
Index: gcc/config/arm/arm.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/arm/arm.h,v
retrieving revision 1.222
diff -u -p -r1.222 arm.h
--- gcc/config/arm/arm.h 13 Feb 2004 21:49:26 -0000 1.222
+++ gcc/config/arm/arm.h 18 Feb 2004 15:47:54 -0000
@@ -442,6 +442,9 @@ extern GTY(()) rtx aof_pic_label;
/* Fix invalid Cirrus instruction combinations by inserting NOPs. */
#define CIRRUS_FIX_INVALID_INSNS (1 << 23)
+/* Set if we should not promote types in function prototypes. */
+#define ARM_FLAG_STRICT_PROTOTYPES (1 << 24)
+
#define TARGET_APCS_FRAME (target_flags & ARM_FLAG_APCS_FRAME)
#define TARGET_POKE_FUNCTION_NAME (target_flags & ARM_FLAG_POKE)
#define TARGET_FPE (target_flags & ARM_FLAG_FPE)
@@ -475,6 +478,7 @@ extern GTY(()) rtx aof_pic_label;
? (target_flags & THUMB_FLAG_LEAF_BACKTRACE) \
: (target_flags & THUMB_FLAG_BACKTRACE))
#define TARGET_CIRRUS_FIX_INVALID_INSNS (target_flags & CIRRUS_FIX_INVALID_INSNS)
+#define TARGET_STRICT_PROTOTYPES (target_flags & ARM_FLAG_STRICT_PROTOTYPES)
/* SUBTARGET_SWITCHES is used to add flags on a per-config basis. */
#ifndef SUBTARGET_SWITCHES
@@ -557,6 +561,9 @@ extern GTY(()) rtx aof_pic_label;
N_("Cirrus: Place NOPs to avoid invalid instruction combinations") }, \
{"no-cirrus-fix-invalid-insns", -CIRRUS_FIX_INVALID_INSNS, \
N_("Cirrus: Do not break up invalid instruction combinations with NOPs") },\
+ {"strict-prototypes", ARM_FLAG_STRICT_PROTOTYPES, \
+ N_("Don't promote char/short to int in function prototypes") }, \
+ {"no-strict-prototypes", -ARM_FLAG_STRICT_PROTOTYPES, "" }, \
SUBTARGET_SWITCHES \
{"", TARGET_DEFAULT, "" } \
}
Index: gcc/doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.408
diff -u -p -r1.408 invoke.texi
--- gcc/doc/invoke.texi 6 Feb 2004 20:03:45 -0000 1.408
+++ gcc/doc/invoke.texi 18 Feb 2004 15:48:16 -0000
@@ -386,6 +386,7 @@ in the following sections.
-mnop-fun-dllimport @gol
-mcirrus-fix-invalid-insns -mno-cirrus-fix-invalid-insns @gol
-mpoke-function-name @gol
+-mstrict-prototypes -mno-strict-prototypes @gol
-mthumb -marm @gol
-mtpcs-frame -mtpcs-leaf-frame @gol
-mcaller-super-interworking -mcallee-super-interworking}
@@ -2807,6 +2808,18 @@ Warn if a function is declared or define
argument types. (An old-style function definition is permitted without
a warning if preceded by a declaration which specifies the argument
types.)
+
+@item -mstrict-prototypes
+@itemx -mno-strict-prototypes
+@opindex mstrict-prototypes
+@opindex mno-strict-prototypes
+The @option{-mstrict-prototypes} switch (disabled by default)
+causes the compiler to implement functions and function calls with
+parameter sizes according to their types, wherever possible.
+With @option{-mno-strict-prototypes} the compiler will ensure all call
+parameters have at least integer size. Also, function prologues will
+convert parameters back to the sizes of their declared types.
+This may be necessary for compatibility with older object code.
@item -Wold-style-definition @r{(C only)}
@opindex Wold-style-definition
Index: gcc/testsuite/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/ChangeLog,v
retrieving revision 1.3504
diff -u -p -r1.3504 ChangeLog
--- gcc/testsuite/ChangeLog 16 Feb 2004 02:35:49 -0000 1.3504
+++ gcc/testsuite/ChangeLog 18 Feb 2004 15:48:45 -0000
@@ -1,3 +1,7 @@
+2004-02-17 James Lemke <jim@wasabisystems.com>
+
+ * testsuite/gcc.dg/arm-g4-{1,1a,2,2a}.c: New files.
+
2004-02-15 Mark Mitchell <mark@codesourcery.com>
PR c++/13971
Index: gcc/testsuite/gcc.dg/arm-g4-1.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/arm-g4-1.c
diff -N gcc/testsuite/gcc.dg/arm-g4-1.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gcc.dg/arm-g4-1.c 18 Feb 2004 15:49:09 -0000
@@ -0,0 +1,12 @@
+/* Verify that input arguments are not extended before use on XScale. */
+/* { dg-do compile { target xscale*-*-* } } */
+/* { dg-options "-mcpu=xscale -O2 -mstrict-prototypes" } */
+
+short int addhi3 (short int a, short int b) __attribute__ ((naked));
+short int addhi3 (short int a, short int b)
+{
+ return a + b + (short int)32;
+}
+
+/* We want to suppress running for -mthumb but not for -mthumb-interwork. */
+/* { dg-final { global compiler_flags; if ![string match "*-mthumb *" $compiler_flags] { scan-assembler-not "add\[ \t]r., *r\[01], *r\[01], *asr \#16" } } } */
Index: gcc/testsuite/gcc.dg/arm-g4-1a.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/arm-g4-1a.c
diff -N gcc/testsuite/gcc.dg/arm-g4-1a.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gcc.dg/arm-g4-1a.c 18 Feb 2004 15:49:09 -0000
@@ -0,0 +1,12 @@
+/* Verify that input arguments are not extended before use on XScale. */
+/* { dg-do compile { target xscale*-*-* } } */
+/* { dg-options "-mcpu=xscale -O2 -mno-strict-prototypes" } */
+
+short int addhi3 (short int a, short int b) __attribute__ ((naked));
+short int addhi3 (short int a, short int b)
+{
+ return a + b + (short int)32;
+}
+
+/* We want to suppress running for -mthumb but not for -mthumb-interwork. */
+/* { dg-final { global compiler_flags; if ![string match "*-mthumb *" $compiler_flags] { scan-assembler "add\[ \t]r., *r\[01], *r\[01], *asr \#16" } } } */
Index: gcc/testsuite/gcc.dg/arm-g4-2.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/arm-g4-2.c
diff -N gcc/testsuite/gcc.dg/arm-g4-2.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gcc.dg/arm-g4-2.c 18 Feb 2004 15:49:09 -0000
@@ -0,0 +1,13 @@
+/* Verify that input arguments are not extended before use on XScale. */
+/* This should be the default. -mno-strict-prototypes should reverse it. */
+/* { dg-do compile { target xscale*-*-* } } */
+/* { dg-options "-mcpu=xscale -O2" } */
+
+char addqi3 (char a, char b) __attribute__ ((naked));
+char addqi3 (char a, char b)
+{
+ return a + b + (char)32;
+}
+
+/* We want to suppress running for -mthumb but not for -mthumb-interwork. */
+/* { dg-final { global compiler_flags; if ![string match "*-mthumb *" $compiler_flags] { scan-assembler-not "and\[ \t]r1, *r1, *\#255" } } } */
Index: gcc/testsuite/gcc.dg/arm-g4-2a.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/arm-g4-2a.c
diff -N gcc/testsuite/gcc.dg/arm-g4-2a.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gcc.dg/arm-g4-2a.c 18 Feb 2004 15:49:09 -0000
@@ -0,0 +1,13 @@
+/* Verify that input arguments are not extended before use on XScale. */
+/* This should be the default. -mno-strict-prototypes should reverse it. */
+/* { dg-do compile { target xscale*-*-* } } */
+/* { dg-options "-mcpu=xscale -O2 -mno-strict-prototypes" } */
+
+char addqi3 (char a, char b) __attribute__ ((naked));
+char addqi3 (char a, char b)
+{
+ return a + b + (char)32;
+}
+
+/* We want to suppress running for -mthumb but not for -mthumb-interwork. */
+/* { dg-final { global compiler_flags; if ![string match "*-mthumb *" $compiler_flags] { scan-assembler "and\[ \t]r1, *r1, *\#255" } } } */