This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PREFERRED_STACK_BOUNDARY clarification desired


I'm a little confused as to how this is implemented.  I was under
the impression that definining it resulted in the total number
of argument bytes being rounded to it, however what I see is
that total number of argument bytes + return PC being rounded
to it.  For example ... defining PREFERRED_STACK_BOUNDARY on
the i386 as 64 and compile (using stage1/xgcc -Bstage1/ -O -S):

  int subr1(int a, int b, int c);

  int subr2(int a, int b, int c);

  void
  func(a, b)
    {

    printf("a = %d  b = %d  subr1 = %d  subr2 = %d\n",
      a, b, subr1(a, b, 1), subr2(a, b, 1));
    }

resultings in:

func:
        pushl %ebp
        movl %esp,%ebp
        pushl %esi
        pushl %ebx           ; prologue ends here
        movl 8(%ebp),%esi
        movl 12(%ebp),%ebx
        addl $-4,%esp
        addl $-4,%esp
        pushl $1
        pushl %ebx
        pushl %esi
        call subr2

  1) The total stack change prior to the call is 20 bytes (two adds +
     three pushes).  This doesn't result in a 64 bit boundary unless
     you include the return PC which is pushed by the call.

  2) The two adds cancel each other out ... they should be eliminated,
     or at the very least combined.

I believe that I have the i386 machine specific changes necessary to
preserve the preferred stack boundary completed ... I'm just unclear
as to if they need to take the pushed PC into consideration, or if
the generic back end does this.  This comment from calls.c:


   STACK_SIZE is the number of bytes of arguments on the stack,
   rounded up to PREFERRED_STACK_BOUNDARY; zero if the size is variable.
   This is both to put into the call insn and
   to generate explicit popping code if necessary.

leads me to believe that I need to handle it, however this isn't
what I see being generated.

-- John
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]