Computer Chess Club Archives


Search

Terms

Messages

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

Author: Gerd Isenberg

Date: 12:41:02 12/05/02

Go up one level in this thread


On December 05, 2002 at 12:48:02, Dieter Buerssner wrote:

>On December 05, 2002 at 11:25:27, Gerd Isenberg wrote:
>
>>Most (All?) C-compilers have no problem with unary minus and constants:
>>
>>unsigned int A = -CONST;
>
>Assume 32 bit integers, and const is -2^31.
>I believe, the above is undefined behaviour. In this case a cast will make it
>defined behaviour:
>
>  unsigned int A = -(unsigned)CONST.
>

Hi Dieter,

I guess it's null, because 2^31 is INT_MIN. I had small constants in mind.
So -1 is very common to to set all bits in an unsigned variable, don't care
about the word size.

unsigned int A = -1;
if ( popCount(A) == 64)
{
   // ah, nice native 64 bit ints
}

Where i have some problems with sometimes, is the implicite type of a direct
constant expressions, calculated by the compiler, specially with propritary
64 bit integers types.

Eg.: MSC6.0

unsigned __int64 FFFF = -1;     // that' fine, all 64 bits set
unsigned __int64 H8BB = 1<<63;  // oups zero

produces an internal unsigned int overflow and assigns zero( without any
warning, even with warning level 4). Why isn't the compiler able to cast the 1
implicitly to the 64bit type?

unsigned __int64 H8BB = (unsigned __int64)1<<63; // that's ok
unsigned __int64 H8BB = (-1)<<63; // also wrong


>Totally unrelated to chess. If you want to write a function to convert int to
>ASCII (without using sprintf) the typical way may be:
>
>  int toconvert;
>  unsigned uval;
>  if (toconvert < 0)
>    uval = -toconvert; /* Oops, may not work for toconvert = INT_MIN */
>  /* and go on to convert the unsigned value */
>
>>Because -CONST is a kind synonym for the compiler which means implicitly
>>  (2**wordLengthInBits) - CONST ==> 0 - CONST
>
>All unsigned arithmetics is guaranteed to yield results mod 2 ^ bits.

except imul and idiv ;-)

>
>Cheers,
>Dieter

See you,
Gerd



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.