Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Java versus C Speed Comparison

Author: Miguel A. Ballicora

Date: 23:00:38 01/10/03

Go up one level in this thread


On January 10, 2003 at 21:34:38, Robert Hyatt wrote:

[snip]

>>>I need a 32 bit counter.  I need a 64 bit bitboard.  I need a 16 bit index.
>>
>>Use int, long (or long long) and int, respectively. I fail to see the the
>>problem.
>
>You pointed out the problem.  I want a 64 bit value.  Do I use long or long
>long?  Impossible to answer unless I know the machine I am running on, which
>is a real _problem_.

As I said in another part of the thread, do you want portability or specificity?
If you want portability, use long long. That's it. If you want to be very
specific, you don't care, you choose the one that the compiler provides for that
machine.

>btw, "int" won't work for a 16 bit index.  IE I expect that to have values
>between 0 and 65535.  And wrap around as any 16 bit counter would do.  Dropping
>that into an int won't fly unless I am running on a 286.

Then you do not need a "mathematical" number but a "set of bits". You already
know the solution, you 'and' a proper mask and that's it. Do not tell me that it
hurts performance because a similar operation must be done by the compiler in
your scheme. Here, you have to do it by yourself. C is not a super high level
language and never intended to be, but it gives you the flexibility to do really
whatever you want.

Now, what would you do in your scheme if you need a fast integer to process very
simple arithmetic and be used in loop counters that won't reach high numbers
(i.e. 2^15)? at the same time you need to write portable code.
This is the most typical case in integer arithmetic. In C is very easy, you just
use int and you got portability and performance.

Even if you want something very specific you can use unsigned bitfields so they
will wrap after 12, 17 or whatever bits you want. Generally using the 'and' is
so simple that it doesn't justify to be bothered.


>>>What works on the Cray will fail on the PC, because "long" works for the
>>>Cray/Alpha but not for the PC if I want a 64 bit integer...
>>
>>If you want portable code, use long long for both. If it is a very important
>>variable use typedef.
>
>By that logic, all that would be safe to use is "long long" which is, in itself,
>a problem.  If I only need values that fit in 32 bits, I want to be able to use
>32 bits, and the same for 64 bits...  I want to be able to say what I need,
>and then let the compiler complain if it can't deliver that.  Which will let
>me know I have a problem, rather than the present scheme of the compiler
>assuming something that very well could be wrong...

You did not refer to the above 'if'. You want portable code or not? that is the
key.

Miguel





This page took 0.01 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.