* Improved generic implementations of fpc_mul_dword, fpc_mul_word, fpc_mul_byte to use less iterations and registers.

git-svn-id: trunk@46269 -
This commit is contained in:
yury 2020-08-05 17:58:46 +00:00
parent f1dbae577c
commit ec10ee8218

View File

@ -1572,19 +1572,27 @@ end;
{$ifndef FPC_SYSTEM_HAS_MUL_BYTE}
function fpc_mul_byte(f1,f2 : byte) : byte;[public,alias: 'FPC_MUL_BYTE']; compilerproc;
var
bitpos : byte;
b : byte;
v1,v2,res: byte;
begin
fpc_mul_byte := 0;
bitpos := 1;
for b := 0 to 7 do
if f1<f2 then
begin
if (f2 and bitpos) <> 0 then
fpc_mul_byte := fpc_mul_byte + f1;
f1 := f1 shl 1;
bitpos := bitpos shl 1;
v1:=f1;
v2:=f2;
end
else
begin
v1:=f2;
v2:=f1;
end;
res:=0;
while v1<>0 do
begin
if v1 and 1<>0 then
inc(res,v2);
v2:=v2 shl 1;
v1:=v1 shr 1;
end;
fpc_mul_byte:=res;
end;
function fpc_mul_byte_checkoverflow(f1,f2 : byte) : byte;[public,alias: 'FPC_MUL_BYTE_CHECKOVERFLOW']; compilerproc;
@ -1674,19 +1682,27 @@ end;
{$ifndef FPC_SYSTEM_HAS_MUL_WORD}
function fpc_mul_word(f1,f2 : word) : word;[public,alias: 'FPC_MUL_WORD']; compilerproc;
var
bitpos : word;
b : byte;
v1,v2,res: word;
begin
fpc_mul_word:=0;
bitpos:=1;
for b:=0 to 15 do
if f1<f2 then
begin
if (f2 and bitpos)<>0 then
fpc_mul_word:=fpc_mul_word+f1;
f1:=f1 shl 1;
bitpos:=bitpos shl 1;
v1:=f1;
v2:=f2;
end
else
begin
v1:=f2;
v2:=f1;
end;
res:=0;
while v1<>0 do
begin
if ALUUInt(v1) and 1<>0 then
inc(res,v2);
v2:=v2 shl 1;
v1:=v1 shr 1;
end;
fpc_mul_word:=res;
end;
function fpc_mul_word_checkoverflow(f1,f2 : word) : word;[public,alias: 'FPC_MUL_WORD_CHECKOVERFLOW']; compilerproc;
@ -1777,19 +1793,27 @@ end;
{$ifndef FPC_SYSTEM_HAS_MUL_DWORD}
function fpc_mul_dword(f1,f2 : dword) : dword;[public,alias: 'FPC_MUL_DWORD']; compilerproc;
var
bitpos : dword;
b : byte;
v1,v2,res: dword;
begin
fpc_mul_dword:=0;
bitpos:=1;
for b:=0 to 31 do
if f1<f2 then
begin
if (f2 and bitpos)<>0 then
fpc_mul_dword:=fpc_mul_dword+f1;
f1:=f1 shl 1;
bitpos:=bitpos shl 1;
v1:=f1;
v2:=f2;
end
else
begin
v1:=f2;
v2:=f1;
end;
res:=0;
while v1<>0 do
begin
if ALUUInt(v1) and 1<>0 then
inc(res,v2);
v2:=v2 shl 1;
v1:=v1 shr 1;
end;
fpc_mul_dword:=res;
end;
function fpc_mul_dword_checkoverflow(f1,f2 : dword) : dword;[public,alias: 'FPC_MUL_DWORD_CHECKOVERFLOW']; compilerproc;