From: "J.A. Magallon" <jamagallon@able.es>
To: Lista Linux-Kernel <linux-kernel@vger.kernel.org>
Subject: gcc -O3 and register usage
Date: Tue, 19 Aug 2003 02:15:07 +0200 [thread overview]
Message-ID: <20030819001507.GA2015@werewolf.able.es> (raw)
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))
next reply other threads:[~2003-08-19 0:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-19 0:15 J.A. Magallon [this message]
2003-08-19 10:17 ` gcc -O3 and register usage Felipe Alfaro Solana
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030819001507.GA2015@werewolf.able.es \
--to=jamagallon@able.es \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).