Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Function call oddity
@ 1998-07-12 18:56 Dave Gilbert
  1998-07-13  1:06 ` Quant-X Alpha Linux Support
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Gilbert @ 1998-07-12 18:56 UTC (permalink / raw)
  To: axp-list


While trying to really optimise a piece of my code I noticed the following
oddity; build a loop which calls a function many times, make sure the
compiler can't inline the function by placing it after the point of
calling.
If the function has no parameters and no results then this runs
faster than all other cases (expected).

However if the routine has one parameter and a result
then it runs faster than a similar routine without a parameter!!

This is really unexpected to me; by the look of the code it must be
to do with allocation of space on the stack at a guess - wierd!!

       parameter    no param
 
result   6            6.79
 
no res   5.28         4.53

Dave

 --------------------------------------------------------------------
/ Dr. David Alan Gilbert      | Running Linux on Alpha & ARM         \ 
\   gro.gilbert @ treblig.org | ------- Happy in hex -------         /
 \____________________________|___ http://www.treblig.demon.co.uk __/


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Function call oddity
  1998-07-12 18:56 Function call oddity Dave Gilbert
@ 1998-07-13  1:06 ` Quant-X Alpha Linux Support
  1998-07-13  4:43   ` Richard Henderson
  0 siblings, 1 reply; 4+ messages in thread
From: Quant-X Alpha Linux Support @ 1998-07-13  1:06 UTC (permalink / raw)
  To: axp-list

Hi David !

> However if the routine has one parameter and a result
> then it runs faster than a similar routine without a parameter!!
> 
> This is really unexpected to me; by the look of the code it must be
> to do with allocation of space on the stack at a guess - wierd!!

No, not stack at all. Up to six parameters will be passed by registers.
I saw the same effect two months ago.
The funny thing is: 

                void func(void)      int func(int)
caller-loop                   6                  7   instructions
func                          6                  7   instructions

The difference is in the caller loop:

Without args, we have the following scheme:

LABEL:  jsr $26, func
        ...
        ...
        ...
        bne $1, LABEL

This means two branches in two instruction cycles (first the 
conditional and then the subroutine branch.) This is IMHO not 
really optimal.

The version with a dummy arg starts with "bis $31, $31, $16" in LABEL
everything else is the same.

This is the original loop by egcs for calling void a(void); in a loop

	.align 5
$L4:
	jsr $26,a
	ldgp $29,0($26)
	bis $9,$9,$1
	cmple $1,$10,$1
	addl $9,1,$9
	bne $1,$L4

This is !!!slower!!! than

	.align 5
$L4:
	nop
	jsr $26,a
	ldgp $29,0($26)
	bis $9,$9,$1
	cmple $1,$10,$1
	addl $9,1,$9
	bne $1,$L4

I've only added the famous "nop".

I hope Richard Henderson reads this, too ;-}}


  Stefan Traby

-- 

Quant-X Service &                         Ph:  (+43) 4212 6004-0
Consulting Ges.m.b.H.                     Fax: (+43) 4212 600420
http://www.quant-x.com                    Email: support@quant-x.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Function call oddity
  1998-07-13  1:06 ` Quant-X Alpha Linux Support
@ 1998-07-13  4:43   ` Richard Henderson
  1998-07-13  5:32     ` Quant-X Alpha Linux Support
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Henderson @ 1998-07-13  4:43 UTC (permalink / raw)
  To: Quant-X Alpha Linux Support, axp-list

On Mon, Jul 13, 1998 at 03:06:31AM +0200, Quant-X Alpha Linux Support wrote:
> This is !!!slower!!! than
> 
> 	.align 5
> $L4:
> 	nop
> 	jsr $26,a
> 	ldgp $29,0($26)
> 	bis $9,$9,$1
> 	cmple $1,$10,$1
> 	addl $9,1,$9
> 	bne $1,$L4

Ok, so what.  That's not the real problem.  The real problem is that
extra bis.  Better would be

	ldq	$27,a($29)	e0
 	jsr	$26,($27),a	e1
	ldah	$29,0($26)	e0
 	cmple	$9,$10,$1	.. e1
	lda	$29,0($29)	e0
 	addl	$9,1,$9		.. e1
 	bne	$1,$L4		e1

Which is two cycles less than with your nop.  I missed whatever message
had the example code, so I can't figure out what the compiler might 
think it is doing.


r~
 
PS.

> I hope Richard Henderson reads this, too ;-}}

Better than hoping would be to actually send it to me.  I do little more
than scan the lists these days.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Function call oddity
  1998-07-13  4:43   ` Richard Henderson
@ 1998-07-13  5:32     ` Quant-X Alpha Linux Support
  0 siblings, 0 replies; 4+ messages in thread
From: Quant-X Alpha Linux Support @ 1998-07-13  5:32 UTC (permalink / raw)
  To: rth; +Cc: axp-list

Hi Richard !

> Ok, so what.  That's not the real problem.  The real problem is that
> extra bis.  Better would be
> 
> 	ldq	$27,a($29)	e0
>  	jsr	$26,($27),a	e1
> 	ldah	$29,0($26)	e0
>  	cmple	$9,$10,$1	.. e1
> 	lda	$29,0($29)	e0
>  	addl	$9,1,$9		.. e1
>  	bne	$1,$L4		e1
> 
> Which is two cycles less than with your nop.  I missed whatever message
> had the example code, so I can't figure out what the compiler might 
> think it is doing.

> > I hope Richard Henderson reads this, too ;-}}
> 
> Better than hoping would be to actually send it to me.  I do little more
> than scan the lists these days.

Sorry, but for that you replied really fast...

Here the code, I've used egcs shipped with RH5.1 (egcs-2.90.27 980315). 
I've only used -O2 to compile. (UX board, 533MHz)
The "global" variable seems useless, but when making it volatile
the WITH_ARG version is somewhat slower (2.26 : 3.95)
Using the code like here, WITH_ARG defined gives 2.07 and
undefined gives 2.26 and so "#define WITH_ARG" faster.
Maybe the "volatile" stuff is even more interesting; but
I go to bed now (it's ~7:30am here).
--------------------------------------------------
/* #define WITH_ARG */

int global = 0;

#ifdef WITH_ARG
int a(int dummy) { return ++global; }
#else
void a(void) { ++global; }
#endif

main(void)
{
  int i=0;

  while(i++ < 100000000)
    a(
#ifdef WITH_ARG
      0
#endif
     );
}
--------------------------------------------------

-- 

Quant-X Service &                         Ph:  (+43) 4212 6004-0
Consulting Ges.m.b.H.                     Fax: (+43) 4212 600420
http://www.quant-x.com                    Email: support@quant-x.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1998-07-13  5:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-07-12 18:56 Function call oddity Dave Gilbert
1998-07-13  1:06 ` Quant-X Alpha Linux Support
1998-07-13  4:43   ` Richard Henderson
1998-07-13  5:32     ` Quant-X Alpha Linux Support

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox