public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* PowerPC suboptimal "add with carry" optimization
@ 2010-04-25 13:05 Joakim Tjernlund
  2010-04-25 19:09 ` Ian Lance Taylor
  0 siblings, 1 reply; 20+ messages in thread
From: Joakim Tjernlund @ 2010-04-25 13:05 UTC (permalink / raw)
  To: gcc


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 */

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

end of thread, other threads:[~2010-04-26 15:13 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-25 13:05 PowerPC suboptimal "add with carry" optimization Joakim Tjernlund
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

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).