Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: getting the least significant bit.. optimizing java :]

Author: scott farrell

Date: 08:13:13 08/15/03

Go up one level in this thread


On August 13, 2003 at 12:38:40, Johan Wessfeldt wrote:

>Im developing a chess engine in java and Im done with the move-generation.
>Ive run a couple of tests and so far so good. No perf-test failures yet! :]
>
>Ive discovered my Least significant Bit method is really slowing me down tho..
>
>The best Ive come up with so far goes like this:
>
>private int lsb(long a){
>for(int i=63;i>0;i--){
> if( (a & mask[i] ) == mask[i] ){
> return i;      }
>}
>return 0;
>}
>
>where mask[] is a vector of all the combinations.. like mask[0] = 0001, mask[1]
>= 00010, mask[3] = 00100 ... and so on.
>
>Ive tried some well known methods but with no results since Java's long(64 bits)
>datatype is signed. It messes up the bits..
>
>(All datatypes in Java are signed)
>
>Anyone have any suggesitons on how to optimize this method?
here is mine (which is java)  - look mah - no loops:

let me know what you think, or if yours is better, or you can enhance.

public static int msb(long bitboard){
	if (bitboard==0)
		return -1;
		int w = (int)((bitboard >>> 48) & 65535);
		if (w != 0){
			return msb_table[w]+48;
		}

		w = (int)((bitboard >>> 32) & 65535);
		if (w != 0){
			return msb_table[w]+32;
		}

		w = (int)((bitboard >>> 16) & 65535);
		if (w != 0){
			return msb_table[w]+16;
		}

		w = (int)(bitboard & 65535);
		if (w != 0){
			return msb_table[w];
		}

		return -1;
	}




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.