Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: BitScan with reset - not so impressive with 3DNow!

Author: Miguel A. Ballicora

Date: 10:07:53 12/06/02

Go up one level in this thread


On December 05, 2002 at 12:21:18, Dieter Buerssner wrote:

>On December 05, 2002 at 10:40:18, Miguel A. Ballicora wrote:
>
>>On December 05, 2002 at 08:27:54, Dan Newman wrote:
>>
>>>The b & -b trick relies on having twos-complement representation for
>>
>>In C, it works even with other "internal" representations. If the representation
>>is different, the C language will make it look like it.
>
>Only for unsigned types.
>
>>My point is that the trick is perfectly portable.
>>
>>>negative numbers.  But it only works if b is signed (or perhaps with
>>>a cast to make it so).  It can be done on unsigned b with an extra
>>>operation: b & (~b + 1).
>>
>>I works with unsigned too. Some compilers issue a warning, but it is
>>perfectly legal C.
>
>IMO, it is only strictly portable for unsigned types. Practically, it will
>probably work anywhere with signed types, too.

Dieter, why do you think that the trick is not perfectly portable?

Of course, I would not recommned anybody to work with signed types with bit
manipulation, but I do not see why it would not be portable in this particular
trick.

The portability problem when one works with bits and signed types can be seen at
"right shifting" and "assigning" (or casting) an unsigned type to a signed one.
Do I miss another case? So, the problem might come when it is needed to take a
look at the bits or work with them because right shift is not portable for
signed. However, at that point it could be casted first to unsigned (that is
portable).

My point is that the particular trick "b & -b" is portable for signed types but
the problems can come later (or before!). I am assuming that we are talking
about signed and unsigned int. Please correct me if I am wrong.

Regards,
Miguel





>
>Regards,
>Dieter



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.