Micro optimize extension() in search.cpp
authorMarco Costalba <mcostalba@gmail.com>
Sat, 25 Jul 2009 15:16:28 +0000 (16:16 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 25 Jul 2009 15:48:28 +0000 (16:48 +0100)
Small micro-optimization in this very
time critical function.

Use bitwise 'or' instead of logic 'or' to avoid branches
in the assembly and use the result to skip an handful of checks.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/search.cpp

index 75b6bd0caefd42ebf5f4c2c7bced970b88d66074..fb3084247761dca2a60a4155546620fc936eff81 100644 (file)
@@ -2202,16 +2202,19 @@ namespace {
     assert(m != MOVE_NONE);
 
     Depth result = Depth(0);
-    *dangerous = check || singleReply || mateThreat;
+    *dangerous = check | singleReply | mateThreat;
 
-    if (check)
-        result += CheckExtension[pvNode];
+    if (*dangerous)
+    {
+        if (check)
+            result += CheckExtension[pvNode];
 
-    if (singleReply)
-        result += SingleReplyExtension[pvNode];
+        if (singleReply)
+            result += SingleReplyExtension[pvNode];
 
-    if (mateThreat)
-        result += MateThreatExtension[pvNode];
+        if (mateThreat)
+            result += MateThreatExtension[pvNode];
+    }
 
     if (pos.type_of_piece_on(move_from(m)) == PAWN)
     {