Next: , Previous: -malways-restore-a4, Up: Invocation

2.12 -mregparm

On the ‘m68k’ architecture, ‘GCC’ passes function arguments on the stack by default.

-mregparm’ allows for passing arguments in registers. This can be slightly faster than the standard method of passing arguments on the stack.

The full syntax of this option is:


value’ should be an integer ranging from 1 to 4. If no ‘value’ is provided, 2 will be used.

Four types of function arguments are recognized:

Integer numbers (this includes enumerations, small structures and ‘bool’ in ‘C++’, but excludes ‘long long’, which is too large). They are passed in data registers, starting from ‘d0’.
Pointers to objects or functions (this includes ‘C++’ references and the implicit ‘this’ argument). They are passed in address registers, starting from ‘a0’.
Floating point numbers. If the floating point code generation is enabled, they are passed in floating point registers, starting from ‘fp0’. Otherwise, they are handled like the next type.
All the other types of arguments, like large structures, pointers to class methods in ‘C++’, etc. They are always passed on the stack.

The value given for ‘-mregparm’ indicates how many arguments of each of the above first three types should be passed in registers.

Example: ‘GCC’ is invoked with ‘-mregparm’ (without any value, so 2 will be used) to compile a source containing the function:

     void fun(int a, char *str, char b, int c);

a’ and ‘b’ will be passed in ‘d0’ and ‘d1’, respectively, ‘str’ will be passed in ‘a0’, and ‘c’ will be passed on the stack.

Note: To use this option properly, it is very important that all sources are fully prototyped. There may be very serious problems if they are not, since ‘GCC’ will have to “guess” where to put arguments, potentially making a wrong decission. Example:
     [in file1.c]
     void f(void)
        g(0); /* Call to a function with no prototype.  The argument
                 will be put in d0, since it is an integer.  */
     [in file2.c]
     void g(char *a) /* The argument is expected in a0, since it is
                        a pointer.  */

-Wimplicit -Wstrict-prototypes’ should be used to ensure that there are no prototypes missing.

In case of ‘stdargs’ functions, such as ‘printf’, all arguments are passed on the stack.

As of this writing, ‘-mregparm’ is supported by neither ‘IXEmul’ nor ‘LibNIX’, so its usefulness is very limited.

This option was first made available in the ‘GCC’, ‘Geek Gadgets’ snapshot ‘961012’.

The negative form of ‘-mregparm’ is ‘-mno-regparm’, and is on by default.