Author: Gerd Isenberg
Date: 16:27:28 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? > >#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; >} Hi Dann, the only reason nowadays to write assembler stuff is IMHO using MMX, SSE2 and special processor instructions, the compiler don't supply, like bsf and cmov for MSC. And lowlevel hardware drivers of course. State of the art compilers are very clever in instruction sheduling and register usage - and even in reorganizing expressions in a faster way. They are aware of the callee's context if inlining such functions. Regards, Gerd
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.