Browse Source

Optimize generic 64-bit division code

FPC_{DIV,MOD}_QWORD now check if both inputs have their upper 32bit set
to zero and in that case use 32-bit division instead, which many
plattforms can either do in hardware or have optimized assembly code
for.

git-svn-id: trunk@28279 -
masta 11 years ago
parent
commit
66aca1b104
1 changed files with 13 additions and 0 deletions
  1. 13 0
      rtl/inc/int64.inc

+ 13 - 0
rtl/inc/int64.inc

@@ -122,6 +122,12 @@
          shift,lzz,lzn : longint;
          shift,lzz,lzn : longint;
 
 
       begin
       begin
+         { Use the usually faster 32-bit division if possible }
+	 if (hi(z) = 0) and (hi(n) = 0) then
+	 begin
+	   fpc_div_qword := Dword(z) div Dword(n);
+	   exit;
+	 end;
          fpc_div_qword:=0;
          fpc_div_qword:=0;
          if n=0 then
          if n=0 then
            HandleErrorAddrFrameInd(200,get_pc_addr,get_frame);
            HandleErrorAddrFrameInd(200,get_pc_addr,get_frame);
@@ -134,6 +140,7 @@
          { then d is greater than the n           }
          { then d is greater than the n           }
          if lzn>lzz then
          if lzn>lzz then
            exit;
            exit;
+
          shift:=lzz-lzn;
          shift:=lzz-lzn;
          n:=n shl shift;
          n:=n shl shift;
          for shift:=shift downto 0 do
          for shift:=shift downto 0 do
@@ -156,6 +163,12 @@
          shift,lzz,lzn : longint;
          shift,lzz,lzn : longint;
 
 
       begin
       begin
+         { Use the usually faster 32-bit mod if possible }
+	 if (hi(z) = 0) and (hi(n) = 0) then
+	 begin
+	   fpc_mod_qword := Dword(z) mod Dword(n);
+	   exit;
+	 end;
          fpc_mod_qword:=0;
          fpc_mod_qword:=0;
          if n=0 then
          if n=0 then
            HandleErrorAddrFrameInd(200,get_pc_addr,get_frame);
            HandleErrorAddrFrameInd(200,get_pc_addr,get_frame);