Article View: gnu.gcc.help
Article #53433GCC with register args for 68000 (Minix 68k) Part 0/4
From: wd
Date: Tue, 21 Jan 1992 14:05
Date: Tue, 21 Jan 1992 14:05
184 lines
9155 bytes
9155 bytes
Or - Subject: Minix 68k: yet another C compiler (long)
Just to add another compiler version to discuss about...
I always wanted to know how big the effect of passing function
arguments in registers vs. on the stack _really_ is. Unfor-
tunately, I never found a C compiler that provides both options.
Finally I decided to change this. With some help from a friend
(thanks, Raimund Gruber!) I hacked up a configuration file for
GCC that allows for register arguments as well as stack args.
Maybe someone is interested?
The new GCC uses up to 5 registers for argument passing: D0, D1
and D2 for integer types and A0 and A1 for pointer types. All
other types are passed on the stack. The arguments for GNU
library functions (libcall) are always passed on the stack. For
functions with a varying number of arguments the last named and
all unnamed arguments are passed on the stack. WARNING: only the
stdarg.h method is supported; you will have to change code that
still uses the old method from varargs.h (supporting this method
seemed to be too difficult and not necessary -- the conversion to
stdarg is very simple). Return values are passed in D0 for
integer and in A0 for pointer types.
I will post patches against the original version of GCC-1.40 as
released by the FSF. There are two types of modifications I made:
(1) Changes to use register arguments on the 68000. This includes
patches to config/tm-m68k.h and to loop.c (thanks, Ian Lance
Taylor, for this patch!).
(2) Changes to make GCC compile under Minix68k (Atari ST in my
case) and in a cross compiling environment (UN*X System V,
big endian) with and without register arguments. These
changes are based on earlier versions of GCC for Minix68k (by
J. Bammi and others), but I had modify a lot of other things
(mostly adding include files and function prototypes). In
fact, only the driver program gcc and the preprocessor cpp
can be compiled with register args; the compiler itself (cc1)
is not enough conforming to ANSI C.
This new version of GCC operates in 4 different modes: 16 (Option
-mshort) or 32 bit ints( Option -mnoshort, default); passing args
in registers (Option -mregparm, default) or on the stack (Option
-mnoregparm). For each mode you need another version of the
startup file and the C library to link with:
-regparm -mnoregparm
(default)
-mnoshort /usr/gnu/lib/crtso.o /usr/gnu/lib/crtso.s.o
(default) /usr/gnu/lib/libc.a /usr/gnu/lib/libc.s.a
-mshort usr/gnu/lib/crtso16.o /usr/gnu/lib/crtso16.s.o
/usr/gnu/lib/libc16.a /usr/gnu/lib/libc16.s.a
If you are compiling with register arguments the preprocessor
symbol __REGPARM__ will be set so that you can #ifdef your code
where necessary. I have no idea where it _could_ be necessary in
C, but this avoids to have different versions of assembler source
code (for instance when compiling the kernel/*.cpp files in
Minix).
So what do I have to do?
========================
Take the sources of GCC-1.40, copy Makefile to Makefile.cross and
Makefile.native; then apply the patches. If you are compliling on
a Minix system: copy Makefile.native to Makefile and run
"config.gcc minix68k" [the standard minix sh will not do; either
you use ksh (probably you will have to give it some more memory
:-( ) or the simple script xconfig). Then type "make" and prepare
to do some other things (it runs for about 3 hours on a 8 MHz
Atari ST). If you are compiling on another machine: copy
Makefile.cross to Makfile and edit the following files:
Makefile
gcc.c
config/tm-minix68k.h
Replace the strings "/user1/wd/..." with pathnames that reflect
your cross compiling environment.
Problems when compiling GCC:
----------------------------
Possibly a lot, but they should be minor. On a minix system you
will probably have to change some of the header files used with
GCC (don't try to compile the new GCC with another compiler).
Your header files should contain prototypes for all routines of
the C library. On a cross system: I don't know what problems will
spring up if you compile not under System V (for BSD you may have
to change some #includes) or not on a big endian system (no idea
what this could mean).
Problems when using the new GCC:
--------------------------------
First, remember to rename your old startup file and C library.
Then recompile your library. There are a few files that have to
be changed for use with register args. I will post the versions I
am using now, but the changes are all simple.
For all compilations with the new GCC with register args: Be
_EXTREMELY_ careful to prototype _ALL_ your functions. I strongly
recommend that you _ALWAYS_ use the options "-pedantic -Wall"
with the new GCC. Then you will see where to add prototypes -
each compiler warning
foo.c:1234: warning: implicit declaration of function `foobar'
means that you are missing a prototype. If this happens it is
likely that some parameters are put in the wrong registers or the
return value is taken from the wrong register (especially true
for all functions returning pointers). The usual effect is a core
dump :-(
Programs using varargs.h will have to be changed to use stdarg.h.
I recommend you to _remove_ varargs.h from your system (or to
rename it to varargs.NOT_USABLE or so) so that any attempt to use
it will be flagged as an error. At least insert lines like these:
#ifdef __REGPARM__
#error Can't use varargs.h with register arguments
#endif
into your varargs.h.
But can't you just give us the binaries?
========================================
Of course I can. What shall do? If I put them on any ftp archive
(where should I put them?) I will get lots of messages "I don't
have ftp"; if I post them I will receive flames for posting such
an amout of pretty useless stuff. What do you want me to do?
Resume or What will I get if I use the new GCC?
===================================================
First of all: You will have lots of trouble if you try to compile
code that was written without keeping the Ten Commandments for C
Programmers in mind (GCC itself is such a thing :-( ); or if your
header files are not set up for ANSI C.
You will have 4 different libraries - maintainance becomes more
difficult.
The executables produced by the new GCC are usually 5...10%
smaller in size and about 5% faster. No, this is not very much.
If I had known before that the effect is so small I don't know if
I would have done all this work :-(. But even small improvements
sum up. (For myself: I learned a lot about how GCC is configured
and how it works.)
You may have noted that the method for chosing registers to hold
arguments is the same as used in Turbo-C (Pure-C?). As long as
there are no references to libcalls or name length problems it is
very simple to convert object files from one compiler to the
other and vice versa. (No, I have not done this and I do not plan
to do it; I am quite lucky with GCC.)
I think all of you who want "portable" code to compile without
looking at it should simply ignore this thingy. All the others
are welcome to comment on it. Flames - as usual - to /dev/null,
please.
BTW: If you want to reduce the size of your object files,
libraries and executables: compile (after debugging) with option
"-fomit-frame-pointer". And "-fcombine-regs" is a good idea, too.
Wolfgang
==================================================================
Name : Wolfgang Denk (+49)-89-68004-288
Company : PCS GmbH, Pfaelzer-Wald-Str. 36, 8000 Munich, Germany.
UUCP : ..[pyramid ;uunet!unido]!pcsbst!wd (PYRAMID PREFERRED!!)
DOMAIN : wd@pcsbst.pcs.[ COM From rest of world; DE From Europe ]
###################################################################
# "UNIX was not designed to stop you from doing stupid things, #
# because that would also stop you from doing clever things." #
# -- Doug Gwyn #
###################################################################
Technical Details
Message-ID:
<wd.696002720@tukan>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pcsbst.pcs.com!wdShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,33c0e4ee819f271d,start X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1992-01-26 09:38:26 PST Newsgroups: gnu.gcc.help Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pcsbst.pcs.com!wd From: wd@pcsbst.pcs.com (wd) Subject: GCC with register args for 68000 (Minix 68k) Part 0/4 Message-ID: <wd.696002720@tukan> Summary: GCC-1.40 for 68000 using registers to pass arguments Keywords: GCC-1.40, 68000, register args, Minix 68k, Atari ST Sender: gnulists@ai.mit.edu Organization: PCS Computer Systeme GmbH Distribution: gnu Date: Tue, 21 Jan 1992 14:05:20 GMT Lines: 185