Optimize hwFloat multiplication a bit
authorunC0Rr
Wed, 30 Nov 2022 16:07:32 +0100
changeset 15925 d2dafe1b25f5
parent 15923 9b8d4f34e0f3
child 15926 7f3d7f015aa5
Optimize hwFloat multiplication a bit
hedgewars/uFloat.pas
--- a/hedgewars/uFloat.pas	Tue Nov 15 15:26:00 2022 +0100
+++ b/hedgewars/uFloat.pas	Wed Nov 30 16:07:32 2022 +0100
@@ -298,8 +298,16 @@
 operator * (const z1, z2: hwFloat) z : hwFloat; inline;
 begin
     z.isNegative:= z1.isNegative xor z2.isNegative;
-    z.QWordValue:= QWord(z1.Round) * z2.Frac + QWord(z1.Frac) * z2.Round + ((QWord(z1.Frac) * z2.Frac) shr 32);
-    z.Round:= z.Round + QWord(z1.Round) * z2.Round;
+    
+    if (z1.Round = 0) and (z2.Round = 0) then
+        begin
+        z.QWordValue:= (QWord(z1.Frac) * z2.Frac) shr 32;
+        end 
+    else
+        begin
+        z.QWordValue:= QWord(z1.Round) * z2.Frac + QWord(z1.Frac) * z2.Round + ((QWord(z1.Frac) * z2.Frac) shr 32);
+        z.Round:= z.Round + QWord(z1.Round) * z2.Round;
+    end
 end;
 
 operator * (const z1: hwFloat; const z2: LongInt) z : hwFloat; inline;