Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: EMMS: to Dr. Nalimov and other assembly programmers

Author: Robert Hyatt

Date: 18:44:21 11/08/99

Go up one level in this thread


On November 08, 1999 at 08:50:52, Dezhi Zhao wrote:

>On November 08, 1999 at 06:28:03, Gunnar Andersson wrote:
>
>>My impression is that many (most?) of the amateur programs use bitboards, and
>>several seem to contain Assembler code for basic operations.
>>
>>Question to programmers: Do you use MMX operations?
>>
>>To me they seem pretty useful because
>>(i)  there are 8 registers of 64 bits each, much better than the old
>>     x386 set of registers
>>(ii) e.g. shifting a 64-bit register takes only one clock cycle whereas this
>>     operation would take 5 (I think) operations when simulated using two
>>     32-bit registers
>>
>>OTOH two 32-bit operations can be performed concurrently in the u- and v- pipes,
>>so there's probably no gain if e.g. only ANDs and ORs are performed in a small
>>number of 64-bit variables.
>>
>>I guess it would be even better to use the two integer 32-bit pipes for one
>>64-bit operation and the MMX/FP pipe for another 64-bit operation, and in
>>loopfree code this might be realizable.
>>
>>For programs that keep stuff in floating-point variables this might be a bad
>>idea - you will have to remember to insert the EMMS instruction before any
>>floating-point operation, and this operation takes some time (about 10 clock
>>cycles I think, but I haven't looked this up).
>>
>>/ Gunnar
>
>Hi
>
>I planed to use MMX instructions. However MMX is perhaps not very documented
>well by Intel. I searched Intel site and only got a MMX instruction list.
>
>I inlined MMX instructions in a test program. However, the EMMS instruction
>really bothered me. The VC6.0 compiler kept warning me that there should
>be an EMMS _before_ the end of the function that contains MMX.
>
>As you said, EMMS is a slow instruction. It should be avoided whenever possible.
>For short functions an EMMS would eat up all the gain from MMX instructions.
>Just like other chess programmers, I use virtually no floating-point stuff
>in engine thread. So my question is:
>Could I do without EMMS instructions? Or could I leave EMMS in only a few
>places, say just before engine thread exit point?
>
>I worried if this simplication is safe for a multi-thread/process program
>and the operation system. I am not sure it is safe for the user interaface
>thread that is derived from MFC and may use folat instructions.
>
>Any suggestions?
>
>Dezhi Zhao


This is a _huge_ gamble that will cost you dearly at some point in the
future.  IE there is _no_ standard that dictates when a compiler would switch
the FPU from normal FP mode to MMX mode.  If you expect the mode to be
unchanged, that is a guaranteed way to run into a bug with the next compiler
release.  We did such nonsense in Cray Blitz, and had to develop a software
procedure to test for 'new' behavior.  IE we could assume that the FP vector
registers were not used, as were a bunch of temp registers.  But each new
compiler version would see some of that 'slack' eroded as the compiler guys
found new ways to use more registers to optimize things.

All I can say is 'be careful' or you will debug this several times...  when
you least expect it.



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.