Author: Gerd Isenberg
Date: 10:25:08 02/23/06
Go up one level in this thread
On February 23, 2006 at 12:47:37, h.g.muller wrote: >Well, at the moment you still are, because this is only at the stage of an idea, >and it will take some development to get in the pawn double move, e.p. capture >and castling... > >Unfortunately the compiler I am using (gcc under cygwin) does not seem to know >CMOV. Even if I write something simple as > > if(a==50)b=c; > >it generates branches over a single ordinary MOV instruction: > > cmpl $50, %eax > jne L1 > movl %ecx, %ebx >L1: > >Very inconvenient, but it is not that difficult to replace such jumps by hand in >the generated assembler file, to make > > cmpl $50, %eax > cmovel %ecx, %ebx > >Perhaps a newer version of gcc can do this, I will have a look. If not, I can >write an extra compiler 'pass' that does this automatically: process the >assembler source to look for any conditional branch jxx over a single movl >instruction, and then delete the line with the branch and replace the movl by >cmovxxl. The assembler seems to understand this all right. Wow that is great - an own compiler pass. Otoh it might be a bad idea to replace all those pattern by cmov - branch predicters are clever beasts today. Have you read Agner Fog's "How to optimize for the Pentium family of microprocessors"? ========================================================================== 12.9 Avoiding jumps ... Replacing conditional jumps by conditional moves (PPro, P2, P3, P4) The PPro, P2, P3 and P4 processors have conditional move instructions intended specifically for avoiding branches, because branch misprediction is very time-consuming on these processors. There are conditional move instructions for both integer and floating-point registers (See page 110 for how to make conditional moves in MMX and XMM registers). For code that will not run on old processors you may replace poorly predictable branches with conditional moves. This example again finds the minimum of two unsigned numbers: if (b < a) a = b; CMP EAX,EBX CMOVNB EAX,EBX The misprediction penalty for a branch may be so high that it is advantageous to replace it with conditional moves even when it costs several extra instructions. But conditional move instructions have two important disadvantages: 1. they make dependence chains longer 2. they introduce an unnecessary dependence on the operand not chosen A conditional move is waiting for three operands to be ready before it can be executed: the condition flag and the two move operands. You have to consider if any of these three operands are likely to be delayed by dependence chains or cache misses. If the condition flag is available long before the move operands then you may as well use a branch, because a possible branch misprediction could be resolved while waiting for the move operands. In situations where you have to wait long for a move operand that may not be needed after all, the branch may be faster than the conditional move despite a possible misprediction penalty. The opposite situation is when the condition flag is delayed while both move operands are available early. In this situation the conditional move is preferred over the branch if misprediction is likely. ========================================================================== I like to build -1|0-mask from sign flag by cdq or sar reg32,31, which avoids flag dependency because after subtraction (but not compare) because sign resists also in the register itself. If a,b <= INTMAX/2 && a,b > INTMIN/2 one may try: if (b < a) a = b; if (b-a < 0) a = b; a += (b-a) & ((b-a)>>31);
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.