Author: Robert Hyatt
Date: 13:59:26 07/17/03
Go up one level in this thread
On July 17, 2003 at 13:42:07, Dann Corbit wrote: >The assembly versions will surely be faster in a test harness. >But when you poke them into actual code and turn on the maximal optimizer >settings, do the assembly high and low bit functions actually beat this C code? > >I ask because it seems that the optimizer is somehow smarter when dealing with C >with some experiments that I have run. > >What happens when you try it? > The danger with any assembly code is that you get in the way of the optimizer. It can't do much to shuffle your code around, depending on how you write it. The gcc format lets you refer to "generic registers" so that the optimizer can tweak it a bit, but it still depends on you to write the code in the best way possible since it can't substitute any instructions for yours. >#ifdef _MSC_VER >typedef unsigned __int64 Bitboard; >#else >typedef unsigned long long Bitboard; >#endif > >/* Returns top bit of x, or 0 if x = 0. */ >/* This algorithm is due to Robert Harley */ >Bitboard hi_bit(Bitboard x) >{ > x |= x >> 1; > x |= x >> 2; > x |= x >> 4; > x |= x >> 8; > x |= x >> 16; > x |= x >> 32; > return x ^ x >> 1; >} /* end function top_bit */ > > >// >// Hard to say which of these will be faster on your system. >// > >Bitboard lo_bit0(Bitboard n) >{ > return ((n & (n - 1)) ^ n); >} > >Bitboard lo_bit1(Bitboard n) >{ > return n & -n; >}
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.