Author: Sune Fischer
Date: 02:10:23 01/16/02
Go up one level in this thread
On January 15, 2002 at 11:48:09, Miguel A. Ballicora wrote: One thing I don't understand; why can't the compiler see that b isn't being used? I would think a good compiler could see this and skip all the loops. Have you tried doing b+=... and then return(b)? -S. >On January 15, 2002 at 06:54:38, Koundinya Veluri wrote: > >>On my computer, bsf is faster if the 1-bit is less significant and bsr is faster >>if the 1-bit is more significant, so the FirstBit() and LastBit() versions with >>the jumps are running faster on average. How does this test on other processors? >>I'm curious... > >I think that you should check with random numbers like this > >for (i = 0; i < ITERATIONS; ++i) { > FB[i] = 1 << randomnumber(64); /* randomnumber returns random from 0-63*/ >} > >Once you fill this array, you can replace in your testing FB by FB[a] >The idea is that in your test you make things very predictable affecting >the branches and also the amount of time the bsf/bsr might take. > >Regards, >Miguel > > > > > > >> >>#include <iostream> >>using namespace std; >> >>#include <windows.h> >> >>#define ITERATIONS (1000000000) >>#define FB (0x8000000000000000) >>#define LB (1) >> >>inline const int FirstBit1(const unsigned __int64 bb); >>inline const int FirstBit2(const unsigned __int64 bb); >>inline const int LastBit1(const unsigned __int64 bb); >>inline const int LastBit2(const unsigned __int64 bb); >>inline const int LastBit3(const unsigned __int64 bb); >> >>int main() >>{ >> unsigned int a, b, t; >> >> cout << "Press enter to start..."; >> cin.ignore(); >> cout << endl; >> >> t = GetTickCount(); >> for(a = 0; a < ITERATIONS; ++a) >> b = FirstBit1(FB); >> t = GetTickCount() - t; >> cout << t << endl; >> cout.flush(); >> >> t = GetTickCount(); >> for(a = 0; a < ITERATIONS; ++a) >> b = FirstBit2(FB); >> t = GetTickCount() - t; >> cout << t << endl; >> cout.flush(); >> >> cout << endl; >> cout.flush(); >> >> t = GetTickCount(); >> for(a = 0; a < ITERATIONS; ++a) >> b = LastBit1(LB); >> t = GetTickCount() - t; >> cout << t << endl; >> cout.flush(); >> >> t = GetTickCount(); >> for(a = 0; a < ITERATIONS; ++a) >> b = LastBit2(LB); >> t = GetTickCount() - t; >> cout << t << endl; >> cout.flush(); >> >> t = GetTickCount(); >> for(a = 0; a < ITERATIONS; ++a) >> b = LastBit3(LB); >> t = GetTickCount() - t; >> cout << t << endl; >> cout.flush(); >> >> return 0; >>} >> >>const int FirstBit1(const unsigned __int64 bb) >>{ >> __asm >> { >> bsf eax, [bb] >> jnz L10 >> bsf eax, [bb + 4] >> add eax, 32 >>L10: >> } >>} >> >>const int FirstBit2(const unsigned __int64 bb) >>{ >> __asm >> { >> bsf eax, [bb + 4] >> add eax, 32 >> bsf eax, [bb] >> } >>} >> >>const int LastBit1(const unsigned __int64 bb) >>{ >> __asm >> { >> bsr eax, [bb + 4] >> jz L10 >> add eax, 32 >> jmp L11 >>L10: >> bsr eax, [bb] >>L11: >> } >>} >> >>const int LastBit2(const unsigned __int64 bb) >>{ >> __asm >> { >> bsr eax, [bb + 4] >> jnz L10 >> bsr eax, [bb] >> sub eax, 32 >>L10: >> add eax, 32 >> } >>} >> >>const int LastBit3(const unsigned __int64 bb) >>{ >> __asm >> { >> bsr eax, [bb] >> sub eax, 32 >> bsr eax, [bb + 4] >> add eax, 32 >> } >>} >> >>Output on my computer: >> >>Press enter to start... >> >>5898 >>5899 >> >>4747 >>6509 >>7080 >> >>-------- >>Regards, >>Koundinya
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.