Author: Dezhi Zhao
Date: 08:49:58 01/16/99
Go up one level in this thread
On January 16, 1999 at 10:00:51, Bo Persson wrote: >This is my solution for VC6, not perfect but working! > >// warning C4035: 'BSF' : no return value >#pragma warning(disable : 4035) > > inline unsigned BSF(unsigned Bits) > { > __asm mov eax,[Bits] > __asm bsf eax,eax > } > >#pragma warning(default : 4035) I'm glad we share the same experience. This inline BSF func is equivalent to my second approach in my post. However inlining your BSF() into a C function will affect the optimization. BSF() uses eax and the VC compiler will generate the 2 lines as you write verbatim. If eax has been taken by another varible, which is very likely to happen, the complier has to generate extra save/reload instructions. It would be better if the compiler has a directive (hint to compiler), saying eax can be renamed during compiling time. > > inline SQUARE BitBoard::GetLowMember() > { > if (Half[0] != 0) > { > const unsigned BitFound = BSF(Half[0]); > Half[0] ^= (1 << BitFound); > return static_cast<SQUARE>(BitFound); > } > else > { > const unsigned BitFound = BSF(Half[1]); > Half[1] ^= (1 << BitFound); > return static_cast<SQUARE>(BitFound + 4 * FILES); > } > > } /* GetLowMember */ > > >VC6 still puts the argument 'Bits' on the stack and reloads it, so you loose a >few instructions but still come out faster *on a PII*. > >Compared to a 16-bit table lookup, the BSF is faster on a PII, makes no >difference on an AMD K6 and is actually *slower* on a Pentium 133! > > > >BTW, you don't have to invent new operators for C/C++ to improve inlining. Many >years ago I used the TopSpeed C++ that solved regsiter assignment with special >pragmas, like: > >#pragma call(reg_param=>(cx,dx), reg_return=>ax) > >Worked fine! > > > >Bo Persson >bop@malmo.mail.telia.com I agree that a directive will also do that. But a new operator can even save the asm stuff. is TopSpeed C++ a 32 bit one? How about code quality generated by it, especially compared with VC6? Dezhi Zhao
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.