From: Joakim Tjernlund <joakim.tjernlund@transmode.se>
To: gcc@gcc.gnu.org
Subject: PowerPC suboptimal "add with carry" optimization
Date: Sun, 25 Apr 2010 13:05:00 -0000 [thread overview]
Message-ID: <OFDA9AAC5C.3EDC433D-ONC1257710.0045561D-C1257710.0047265E@transmode.se> (raw)
Noticed that gcc 4.3.4 doesn't optimize "add with carry" properly:
static u32
add32carry(u32 sum, u32 x)
{
u32 z = sum + x;
if (sum + x < x)
z++;
return z;
}
Becomes:
add32carry:
add 3,3,4
subfc 0,4,3
subfe 0,0,0
subfc 0,0,3
mr 3,0
Instead of:
addc 3,3,4
addze 3,3
This slows down the the Internet checksum sigificantly
Also, doing this in a loop can be further optimized:
for(;len; --len)
sum = add32carry(sum, *++buf);
addic 3, 3, 0 /* clear carry */
.L31:
lwzu 0,4(9)
adde 3, 3, 0 /* add with carry */
bdnz .L31
addze 3, 3 /* add in final carry */
next reply other threads:[~2010-04-25 13:01 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-25 13:05 Joakim Tjernlund [this message]
2010-04-25 19:09 ` Ian Lance Taylor
2010-04-26 7:43 ` Joakim Tjernlund
2010-04-26 12:10 ` Manuel López-Ibáñez
2010-04-26 12:23 ` Joakim Tjernlund
2010-04-26 12:42 ` Manuel López-Ibáñez
2010-04-26 12:45 ` Pekka Enberg
2010-04-26 12:54 ` David Edelsohn
2010-04-26 12:55 ` Pekka Enberg
2010-04-26 13:30 ` Manuel López-Ibáñez
2010-04-26 15:11 ` Pekka Enberg
2010-04-26 15:30 ` Manuel López-Ibáñez
2010-04-26 12:58 ` David Edelsohn
2010-04-26 13:27 ` Joakim Tjernlund
2010-04-26 13:38 ` Manuel López-Ibáñez
2010-04-26 13:42 ` Joakim Tjernlund
2010-04-26 14:01 ` Ian Lance Taylor
2010-04-26 13:57 ` David Edelsohn
2010-04-26 8:04 ` Joakim Tjernlund
2010-04-26 14:15 ` Ian Lance Taylor
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=OFDA9AAC5C.3EDC433D-ONC1257710.0045561D-C1257710.0047265E@transmode.se \
--to=joakim.tjernlund@transmode.se \
--cc=gcc@gcc.gnu.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 read-only IMAP folder(s) and NNTP newsgroup(s).