www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/31/21:02:15

Sender: nate AT cartsys DOT com
Message-ID: <35EB46EF.911D60A5@cartsys.com>
Date: Mon, 31 Aug 1998 17:59:27 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
MIME-Version: 1.0
To: GAMMELJL AT SLU DOT EDU
CC: djgpp AT delorie DOT com
Subject: Re: passing arguments in registers
References: <01J19GJU8Q9U94JXNE AT SLU DOT EDU>

GAMMELJL AT SLU DOT EDU wrote:
> 
> The following C/C++ code when compiled:
>                 gxx example9.cc -S -O2
> results in the .s file below it.  It is plain that the arguments
> of zadd are passed on the stack.  Eli Zareteskii has told me that
> passing them in registers requires
>                  __attribute__((regparm=2))
> and that the information about this is in the GCC docs.  Please:
> someone expert in searching these docs tell me exactly where this
> attribute statement goes in the C++ code below and exactly what the
> correct syntax is.

>From GCC Manual, node "Function Attributes":

#    The keyword `__attribute__' allows you to specify special
attributes
# when making a declaration.  This keyword is followed by an attribute
# specification inside double parentheses. 
...
# `regparm (NUMBER)'
#      On the Intel 386, the `regparm' attribute causes the compiler to
#      pass up to NUMBER integer arguments in registers EAX, EDX, and
ECX
#      instead of on the stack.  Functions that take a variable number
of
#      arguments will continue to be passed all of their arguments on
the
#      stack.

So:

extern int zadd(int m, int n) __attribute__((regparm(2)));

Make sure this prototype is in scope when you define `zadd'!

(I added the explicit `int').
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019