This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: speeding up parts of gcc by using count_leading_zero (long)


>Tangentially, ffs takes an int, which is 32 bits on all supported
>hosts.  It would make sense to define __builtin_ffs32() and
>__builtin_ffs64() to nail down the sizes.  ffs64 can be implemented
>efficiently on machines with only a 32-bit ffs instruction, as
>
>         ffs    high, r
>         test   r
>         bnz    0f
>         ffs    low, r
>0f:
>
>so it is useful to provide both of them always.

If ffs returns zero if its arg is zero, and then 1 to 32 (assuming ffs
returns 1 if the msb is set), then you forgot to add 32 if the high
word is zero(unless the lower word is zero) so the result is 0 to 64:

         ffs    high, r
         test   r
         bnz    0f
         ffs    low, r
	 test	r
	 bz	0f
	 add	32, r
0f:

-- 
Peter Barada
peter@baradas.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]