"Jim Rogers" , haber iletisinde �unlar� yazd�:DYBYd.373707$w62.141894@bgtnsc05-news.ops.worldnet.att.net... > "Aslan Kral" wrote in > news:39g6jbF62g4qjU1@individual.net: > > > > > "Aslan Kral" , haber iletisinde �unlar� > > yazd�:39fr2iF5uq3mvU1@individual.net... > >> > IIRC, the C codes that were posted to find the highest bit set > >> > thread were about 1/10th of that number. Just to double check, I > >> > wrote and measured some C code. On my 3GHz Xeon running with cygwin > >> > on WinXP, when compiled with gcc3.3.3 using -mpcu=i686 -O0, I got a > >> > total run-time of 2.3s, for about 69 cycles/iteration, and with -O2 > >> > I get 0.94s for about 28 cycles/iteration. > >> > > >> > > > > Oops! I failed to read the -O2 part. It makes sense now. And your code > > doesn't use any lookup table that is why it is slower than Willem's. > > Anyway the version with lookup table is quite close to "bsr" version. > > So yours also can get faster with the addition of lookup table. It > > would be interesting to see how much Ada can get close to "bsr" > > version below! (By adding a lookup table, I mean.) > > > > __inline unsigned FindHighestBit(unsigned n) > > { > > __asm > > { > > bsr eax, n > > } > > } > > . > > > > I sems to have lost the C version of the lookup table. > Could you please repost that or send me the version. > > Thanks. > > Jim Rogers > OK. static unsigned highBitSmall[256] = { 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 }; __inline unsigned FindHighestBit( unsigned n ) { unsigned bits = 0; if (n >> 16) { n = n >> 16; bits = 16; } if (n >> 8) { n = n >> 8; bits += 8; } return bits + highBitSmall[n]; }