home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
PERFORM
/
LONGINT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-07-10
|
6KB
|
192 lines
{$IFDEF VER70}
{$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,P-,Q-,R-,S+,T-,V-,X+}
{$ELSE}
{$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,R-,S+,V-,X+}
{$ENDIF}
{$M 16384,0,655360}
{
LongInt
Borland Pascal (Objects) 7.0.
Copyright (c) 10-7-1993 DwarFools & Consultancy by drs. Robert E. Swart.
P.O. box 799
5702 NP Helmond
The Netherlands
Code size: 5840 bytes
Data size: 690 bytes
.EXE size: 6176 bytes
-------------------------------------------------------------------------
This program provides four routines to speed up the '*', 'div', and 'mod'
operations on a combination of LongInts and Integers. LongMul can be used
to multiply two Integers and yield a LongInt result. LongDiv and LongMod
can be used to divide a LongInt by an Integer yielding resp. the quotient
or the remainder of the division.
The speed results are as follows:
reps Bob Swart Borland speed
LongMul: 20613 10916 189%
LongDiv: 17919 9490 189%
LongMod: 18193 9493 192%
}
function LongMul(X,Y: Integer): LongInt;
InLine(
$5A/ { pop DX }
$58/ { pop AX }
$F7/$EA); { imul DX }
function LongDiv(X: LongInt; Y: Integer): Integer;
InLine(
$59/ { pop CX }
$58/ { pop AX }
$5A/ { pop DX }
$F7/$F9); { idiv CX }
function LongMod(X: LongInt; Y: Integer): Integer;
InLine(
$59/ { pop CX }
$58/ { pop AX }
$5A/ { pop DX }
$F7/$F9/ { idiv CX }
$89/$D0); { mov AX,DX }
var TimerTick: Word absolute $0040:$006C;
StartTick: Word;
BobSwart,Reps: LongInt;
var X,Y,Z: Integer;
L: LongInt;
begin
writeln('reps Bob Swart Borland speed');
X := 100;
Y := 1000;
write('LongMul: ');
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
L := LongMul(X,Y);
Inc(Reps);
until StartTick <> TimerTick;
write(Reps:8);
BobSwart := Reps;
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
L := LongInt(X) * Y;
Inc(Reps);
until StartTick <> TimerTick;
writeln(Reps:9,100.0*BobSwart/Reps:6:0,'%');
write('LongDiv: ');
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
X := LongDiv(L,Y);
Inc(Reps);
until StartTick <> TimerTick;
write(Reps:8);
BobSwart := Reps;
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
X := L div Y;
Inc(Reps);
until StartTick <> TimerTick;
writeln(Reps:9,100.0*BobSwart/Reps:6:0,'%');
write('LongMod: ');
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
Z := LongMod(L,25);
Inc(Reps);
until StartTick <> TimerTick;
write(Reps:8);
BobSwart := Reps;
Reps := 0;
StartTick := TimerTick;
while StartTick = TimerTick do {wait for end of TimerTick};
StartTick := TimerTick;
repeat
Z := L mod 25;
Inc(Reps);
until StartTick <> TimerTick;
writeln(Reps:9,100.0*BobSwart/Reps:6:0,'%');
end.
LONGINT.PAS#31: L := LongInt(X) * Y;
0000:001B A15200 MOV AX,[0052]
0000:001E 99 CWD
0000:001F 8BC8 MOV CX,AX
0000:0021 8BDA MOV BX,DX
0000:0023 A15000 MOV AX,[0050]
0000:0026 99 CWD
0000:0027 9A99040B00 CALL FAR 000B:0499
0000:002C A35600 MOV [0056],AX
0000:002F 89165800 MOV [0058],DX
LONGINT.PAS#32: X := L div Y;
0000:0033 A15200 MOV AX,[0052]
0000:0036 99 CWD
0000:0037 8BC8 MOV CX,AX
0000:0039 8BDA MOV BX,DX
0000:003B A15600 MOV AX,[0056]
0000:003E 8B165800 MOV DX,[0058]
0000:0042 9AD6040B00 CALL FAR 000B:04D6
0000:0047 A35000 MOV [0050],AX
LONGINT.PAS#33: Z := L mod 25;
0000:004A A15600 MOV AX,[0056]
0000:004D 8B165800 MOV DX,[0058]
0000:0051 B91900 MOV CX,0019
0000:0054 31DB XOR BX,BX
0000:0056 9AD6040B00 CALL FAR 000B:04D6
0000:005B 89C8 MOV AX,CX
0000:005D 89DA MOV DX,BX
0000:005F A35400 MOV [0054],AX
LONGINT.PAS#34: L := LongMul(X,Y);
0000:0062 FF365000 PUSH [0050]
0000:0066 FF365200 PUSH [0052]
0000:006A 5A POP DX
0000:006B 58 POP AX
0000:006C F7EA IMUL DX
0000:006E A35600 MOV [0056],AX
0000:0071 89165800 MOV [0058],DX
LONGINT.PAS#35: X := LongDiv(L,Y);
0000:0075 FF365800 PUSH [0058]
0000:0079 FF365600 PUSH [0056]
0000:007D FF365200 PUSH [0052]
0000:0081 59 POP CX
0000:0082 58 POP AX
0000:0083 5A POP DX
0000:0084 F7F9 IDIV CX
0000:0086 A35000 MOV [0050],AX
LONGINT.PAS#36: Z := LongMod(L,25);
0000:0089 FF365800 PUSH [0058]
0000:008D FF365600 PUSH [0056]
0000:0091 B81900 MOV AX,0019
0000:0094 50 PUSH AX
0000:0095 59 POP CX
0000:0096 58 POP AX
0000:0097 5A POP DX
0000:0098 F7F9 IDIV CX
0000:009A 89D0 MOV AX,DX
0000:009C A35400 MOV [0054],AX