This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
speeding up parts of gcc by using count_leading_zero (long)
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: gcc at gcc dot gnu dot org
- Cc: Andrew Pinski <pinskia at physics dot uc dot edu>, apinski at apple dot com
- Date: Sat, 4 Jan 2003 22:06:48 -0800
- Subject: speeding up parts of gcc by using count_leading_zero (long)
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