public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* speeding up parts of gcc by using count_leading_zero (long)
@ 2003-01-05  6:16 Andrew Pinski
  2003-01-05  7:03 ` Zack Weinberg
  2003-01-06 10:51 ` speeding up parts of gcc by using ffs Andrew Pinski
  0 siblings, 2 replies; 12+ messages in thread
From: Andrew Pinski @ 2003-01-05  6:16 UTC (permalink / raw)
  To: gcc; +Cc: Andrew Pinski, apinski

There are parts of gcc which can be sped up on PPC (and other 
architectures which have something similar)  by using the instruction 
`cntlz{w,d}' (count leading zero word, double word [PPC64 only]).

Also the parts of gcc on other architectures which do not have count 
leading zero can be sped up by instead of using a for loop, a series of 
if statements:
  register int bit_num = 0;
   if (word & 0xFFFF0000)
     word >>= 16;
   else
     bit_num += 16;
   if (word & 0xFF00)
     word >>= 8;
   else
     bit_num += 8;
   if (word & 0xF0)
     word >>= 4;
   else
     bit_num += 4;
   if (word & 0xc)
     word >>= 2;
   else
     bit_num += 2;
   if (word & 0x2)
     word >>= 1;
   else
     bit_num += 1;
   if ((word & 0x1) == 0)
     bit_num += 1;
and bit_num is the result.

The functions which could benefit from this are:
function					file
_________________________________
sbitmap_first_set_bit		sbitmap.c
sbitmap_last_set_bit		sbitmap.c
bitmap_first_set_bit		bitmap.c			(this already does a series of if 
statements)
bitmap_last_set_bit		bitmap.c			(this already does a series of if 
statements)
floor_log2_wide			toplev.c
exact_log2_wide			toplev.c
compute_inverse			ggc-page.c
build_mask64_2_operands		config/rs6000/rs6000.c

This one only effects libgcc
count_leading_zero			longlong.h

also this one from libiberty
ffs						ffs.c


There might be others but these would found by doing a grep for >> and 
looking at for a counting the bits that not set until getting one that 
is set SIZEOF_INT - cntlzw (word&-word) which is the same as ffs or 
looping until the word is zero which is the same as SIZEOF_INT - cntlzw 
(word) - 1.

Where should I put the mechanism for the cntlz for HOST_WIDE_INT, int, 
HOST_WIDEST_INT (in hwint.h?) and what should I call the functions, 
count_leading_zero_wide_int, count_leading_zero_int, and 
count_leading_zero_widest_int?

Thanks,
Andrew Pinski

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

end of thread, other threads:[~2003-01-08 22:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-05  6:16 speeding up parts of gcc by using count_leading_zero (long) Andrew Pinski
2003-01-05  7:03 ` Zack Weinberg
2003-01-05  7:17   ` Peter Barada
2003-01-05  8:41     ` Zack Weinberg
2003-01-06 10:51 ` speeding up parts of gcc by using ffs Andrew Pinski
2003-01-06 18:08   ` Zack Weinberg
2003-01-06 18:28     ` Joseph S. Myers
2003-01-08  9:51     ` Andrew Pinski
2003-01-08 11:20       ` Falk Hueffner
2003-01-08 11:21         ` Andrew Pinski
2003-01-08 11:26           ` Falk Hueffner
2003-01-09  0:24       ` Richard Henderson

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