This is the mail archive of the gcc-patches@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]

Re: recommended alignment for local i386 FP variables patch


> This scheme is going to require an extra register at all times

It doesn't require any more registers than the "normal" case of
compiling a function with a frame pointer and it only affects
those functions which may have a local variable which requires
extra alignment.  This does mean that the hard frame pointer
can't be eliminated in this case.  However functions which
don't need extra alignment are not affect and the frame pointer
can be eliminated.

> and grody prologue code.

I'm not sure how "grody" this make the prologue ... it only adds

  andl $0xfffffff8,%esp

to the prologue.

> Consider that you don't know the alignment as you enter the function --
> it can change dynamically,

I realize that.

> thus the offset to the args is not a compile time constant.  Bad news.

Ah, however the offset to the args * is * a compile time constant with
regards to the hard frame pointer.

> I think we are better off using the PREFERRED_STACK_ALIGNMENT support that
> Bernd put into the compiler recently.  Then we have the compiler always
> allocate doubles at an 8 byte offset from the stack pointer.

Doesn't this mean that extra instructions will be generated to align the
stack for * all * function calls in addition to potentially requiring extra
instructions in the prologue to keep the stack aligned?  My approach
doesn't require any extra instructions in the caller and only affects
callees which need the extra alignment.

Compiling:

double
funcd(double a)
  {
  volatile double b;

  b = a;
  return b;
  }

Normally generates:

_funcd:
	pushl %ebp
	movl %esp,%ebp
	subl $8,%esp
	fldl 8(%ebp)
	fstpl -8(%ebp)
	fldl -8(%ebp)
	leave
	ret

My approach results in:

	.type	 _funcd,@function
_funcd:
	push %ebp                    ; setup the hard frame pointer
	movl %esp,%ebp
	subl $8,%esp
	and $0xfffffff8,%esp         ; align the stack pointer (extra insn)
	fldl 8(%ebp)                 ; access the argument to the function
	fstpl (%esp)                 ; use the local variable
	fldl (%esp)
	leal 0(%ebp),%esp            ; restore the stack pointer (extra insn)
	leave
	ret

Cons:

  Two extra instructions in functions requiring extra alignment.

  Can't eliminate the hard frame pointer in functions requiring extra alignment.

Pros:

  Only affects functions requiring extra alignment.

BTW, this is a hand generated example so there may be "typos". :-)

-- 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]