linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* gcc -O3 and register usage
@ 2003-08-19  0:15 J.A. Magallon
  2003-08-19 10:17 ` Felipe Alfaro Solana
  0 siblings, 1 reply; 2+ messages in thread
From: J.A. Magallon @ 2003-08-19  0:15 UTC (permalink / raw)
  To: Lista Linux-Kernel

Hi all...

I was playing looking at the code gcc gives for some simple operations,
and got this...

Simple C program (do you recognise it ;) ?):

struct list_head
{
	struct list_head *next, *prev;
};

static inline int list_empty(struct list_head *head)
{
	return head->next == head;
}

int use(struct list_head *l)
{
	return list_empty(l);
}

I use gcc 3.3.1.
Compile at -O2:

use:
	pushl	%ebp
	movl	%esp, %ebp
	movl	8(%ebp), %eax
	popl	%ebp
	cmpl	%eax, (%eax)
	sete	%al
	movzbl	%al, %eax
	ret

Compile at -O3:

use:
	pushl	%ebp
	movl	%esp, %ebp
	movl	8(%ebp), %edx
	popl	%ebp
	cmpl	%edx, (%edx)
	sete	%al
	andl	$255, %eax
	ret

Compile at -O3 and (at least) -march=pentiumpro:

use:
	pushl	%ebp
	movl	%esp, %ebp
	movl	8(%ebp), %edx
	popl	%ebp
	cmpl	%edx, (%edx)
	sete	%dl
	movzbl	%dl, %eax
	ret

Go back to -O2, but keep -march=pentiumpro:

use:
	pushl	%ebp
	movl	%esp, %ebp
	movl	8(%ebp), %eax
	popl	%ebp
	cmpl	%eax, (%eax)
	sete	%al
	movzbl	%al, %eax
	ret

Does this mean that since PentiumPro gcc has one other register (%dl)
available, and it uses it only at -O3 ?
This can be a _big_ advantage to reduce register spilling (stack
traffic...)

The above effect is due to the -frename-registers activated in -O3.
This option is used in arch/ia64/Makefile, but it is supposed to
benefit more to arches with few registers (I suppose ia64 has a ton more
that ia32...)

Would if be useful ?

TIA

-- 
J.A. Magallon <jamagallon@able.es>      \                 Software is like sex:
werewolf.able.es                         \           It's better when it's free
Mandrake Linux release 9.2 (Cooker) for i586
Linux 2.4.22-rc2-jam1m (gcc 3.3.1 (Mandrake Linux 9.2 3.3.1-1mdk))

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

* Re: gcc -O3 and register usage
  2003-08-19  0:15 gcc -O3 and register usage J.A. Magallon
@ 2003-08-19 10:17 ` Felipe Alfaro Solana
  0 siblings, 0 replies; 2+ messages in thread
From: Felipe Alfaro Solana @ 2003-08-19 10:17 UTC (permalink / raw)
  To: J.A. Magallon; +Cc: Lista Linux-Kernel

On Tue, 2003-08-19 at 02:15, J.A. Magallon wrote:

> Does this mean that since PentiumPro gcc has one other register (%dl)
> available, and it uses it only at -O3 ?

AFAIK, the EDX 32-bit register is splitted in two 16-bit halves, being
the least significant half called DX which, at the sime time, is
splitted in two 8-bit halves of which the most significant is called DH,
while the least significant is called DL.

So, DL is not a new register, but the least significant 8-bits from the
EDX CPU register.


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

end of thread, other threads:[~2003-08-19 10:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-19  0:15 gcc -O3 and register usage J.A. Magallon
2003-08-19 10:17 ` Felipe Alfaro Solana

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).