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 >
Pascal/Delphi Source File  |  1993-07-10  |  6KB  |  192 lines

  1. {$IFDEF VER70}
  2. {$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,P-,Q-,R-,S+,T-,V-,X+}
  3. {$ELSE}
  4. {$A+,B-,D-,E-,F-,G-,I-,L-,N-,O-,R-,S+,V-,X+}
  5. {$ENDIF}
  6. {$M 16384,0,655360}
  7. {
  8.     LongInt
  9.     Borland Pascal (Objects) 7.0.
  10.     Copyright (c) 10-7-1993 DwarFools & Consultancy by drs. Robert E. Swart.
  11.                             P.O. box 799
  12.                             5702 NP  Helmond
  13.                             The Netherlands
  14.     Code size: 5840 bytes
  15.     Data size:  690 bytes
  16.     .EXE size: 6176 bytes
  17.     -------------------------------------------------------------------------
  18.     This program provides four routines to speed up the '*', 'div', and 'mod'
  19.     operations on a combination of LongInts and Integers. LongMul can be used
  20.     to multiply two Integers and yield a LongInt result.  LongDiv and LongMod
  21.     can be used to divide a LongInt by an Integer yielding resp. the quotient
  22.     or the remainder of the division.
  23.  
  24.     The speed results are as follows:
  25.  
  26.     reps    Bob Swart  Borland  speed
  27.     LongMul:    20613    10916   189%
  28.     LongDiv:    17919     9490   189%
  29.     LongMod:    18193     9493   192%
  30. }
  31.  
  32.  
  33.  function LongMul(X,Y: Integer): LongInt;
  34.  InLine(
  35.    $5A/          {   pop   DX  }
  36.    $58/          {   pop   AX  }
  37.    $F7/$EA);     {   imul  DX  }
  38.  
  39.  function LongDiv(X: LongInt; Y: Integer): Integer;
  40.  InLine(
  41.    $59/          {   pop   CX  }
  42.    $58/          {   pop   AX  }
  43.    $5A/          {   pop   DX  }
  44.    $F7/$F9);     {   idiv  CX  }
  45.  
  46.  function LongMod(X: LongInt; Y: Integer): Integer;
  47.  InLine(
  48.    $59/          {  pop   CX     }
  49.    $58/          {  pop   AX     }
  50.    $5A/          {  pop   DX     }
  51.    $F7/$F9/      {  idiv  CX     }
  52.    $89/$D0);     {  mov   AX,DX  }
  53.  
  54.  
  55. var TimerTick: Word absolute $0040:$006C;
  56.     StartTick: Word;
  57.     BobSwart,Reps: LongInt;
  58.  
  59. var X,Y,Z: Integer;
  60.     L: LongInt;
  61.  
  62. begin
  63.   writeln('reps    Bob Swart  Borland  speed');
  64.   X := 100;
  65.   Y := 1000;
  66.  
  67.   write('LongMul: ');
  68.   Reps := 0;
  69.   StartTick := TimerTick;
  70.   while StartTick = TimerTick do {wait for end of TimerTick};
  71.   StartTick := TimerTick;
  72.   repeat
  73.     L := LongMul(X,Y);
  74.     Inc(Reps);
  75.   until StartTick <> TimerTick;
  76.   write(Reps:8);
  77.   BobSwart := Reps;
  78.   Reps := 0;
  79.   StartTick := TimerTick;
  80.   while StartTick = TimerTick do {wait for end of TimerTick};
  81.   StartTick := TimerTick;
  82.   repeat
  83.     L := LongInt(X) * Y;
  84.     Inc(Reps);
  85.   until StartTick <> TimerTick;
  86.   writeln(Reps:9,100.0*BobSwart/Reps:6:0,'%');
  87.  
  88.   write('LongDiv: ');
  89.   Reps := 0;
  90.   StartTick := TimerTick;
  91.   while StartTick = TimerTick do {wait for end of TimerTick};
  92.   StartTick := TimerTick;
  93.   repeat
  94.     X := LongDiv(L,Y);
  95.     Inc(Reps);
  96.   until StartTick <> TimerTick;
  97.   write(Reps:8);
  98.   BobSwart := Reps;
  99.   Reps := 0;
  100.   StartTick := TimerTick;
  101.   while StartTick = TimerTick do {wait for end of TimerTick};
  102.   StartTick := TimerTick;
  103.   repeat
  104.     X := L div Y;
  105.     Inc(Reps);
  106.   until StartTick <> TimerTick;
  107.   writeln(Reps:9,100.0*BobSwart/Reps:6:0,'%');
  108.  
  109.   write('LongMod: ');
  110.   Reps := 0;
  111.   StartTick := TimerTick;
  112.   while StartTick = TimerTick do {wait for end of TimerTick};
  113.   StartTick := TimerTick;
  114.   repeat
  115.     Z := LongMod(L,25);
  116.     Inc(Reps);
  117.   until StartTick <> TimerTick;
  118.   write(Reps:8);
  119.   BobSwart := Reps;
  120.   Reps := 0;
  121.   StartTick := TimerTick;
  122.   while StartTick = TimerTick do {wait for end of TimerTick};
  123.   StartTick := TimerTick;
  124.   repeat
  125.     Z := L mod 25;
  126.     Inc(Reps);
  127.   until StartTick <> TimerTick;
  128.   writeln(Reps:9,100.0*BobSwart/Reps:6:0,'%');
  129. end.
  130.  
  131. LONGINT.PAS#31:    L := LongInt(X) * Y;
  132.   0000:001B A15200          MOV     AX,[0052]
  133.   0000:001E 99              CWD
  134.   0000:001F 8BC8            MOV     CX,AX
  135.   0000:0021 8BDA            MOV     BX,DX
  136.   0000:0023 A15000          MOV     AX,[0050]
  137.   0000:0026 99              CWD
  138.   0000:0027 9A99040B00      CALL    FAR 000B:0499
  139.   0000:002C A35600          MOV     [0056],AX
  140.   0000:002F 89165800        MOV     [0058],DX
  141.  
  142. LONGINT.PAS#32:    X := L div Y;
  143.   0000:0033 A15200          MOV     AX,[0052]
  144.   0000:0036 99              CWD
  145.   0000:0037 8BC8            MOV     CX,AX
  146.   0000:0039 8BDA            MOV     BX,DX
  147.   0000:003B A15600          MOV     AX,[0056]
  148.   0000:003E 8B165800        MOV     DX,[0058]
  149.   0000:0042 9AD6040B00      CALL    FAR 000B:04D6
  150.   0000:0047 A35000          MOV     [0050],AX
  151.  
  152. LONGINT.PAS#33:    Z := L mod 25;
  153.   0000:004A A15600          MOV     AX,[0056]
  154.   0000:004D 8B165800        MOV     DX,[0058]
  155.   0000:0051 B91900          MOV     CX,0019
  156.   0000:0054 31DB            XOR     BX,BX
  157.   0000:0056 9AD6040B00      CALL    FAR 000B:04D6
  158.   0000:005B 89C8            MOV     AX,CX
  159.   0000:005D 89DA            MOV     DX,BX
  160.   0000:005F A35400          MOV     [0054],AX
  161.  
  162. LONGINT.PAS#34:    L := LongMul(X,Y);
  163.   0000:0062 FF365000        PUSH    [0050]
  164.   0000:0066 FF365200        PUSH    [0052]
  165.   0000:006A 5A              POP     DX
  166.   0000:006B 58              POP     AX
  167.   0000:006C F7EA            IMUL    DX
  168.   0000:006E A35600          MOV     [0056],AX
  169.   0000:0071 89165800        MOV     [0058],DX
  170.  
  171. LONGINT.PAS#35:    X := LongDiv(L,Y);
  172.   0000:0075 FF365800        PUSH    [0058]
  173.   0000:0079 FF365600        PUSH    [0056]
  174.   0000:007D FF365200        PUSH    [0052]
  175.   0000:0081 59              POP     CX
  176.   0000:0082 58              POP     AX
  177.   0000:0083 5A              POP     DX
  178.   0000:0084 F7F9            IDIV    CX
  179.   0000:0086 A35000          MOV     [0050],AX
  180.  
  181. LONGINT.PAS#36:    Z := LongMod(L,25);
  182.   0000:0089 FF365800        PUSH    [0058]
  183.   0000:008D FF365600        PUSH    [0056]
  184.   0000:0091 B81900          MOV     AX,0019
  185.   0000:0094 50              PUSH    AX
  186.   0000:0095 59              POP     CX
  187.   0000:0096 58              POP     AX
  188.   0000:0097 5A              POP     DX
  189.   0000:0098 F7F9            IDIV    CX
  190.   0000:009A 89D0            MOV     AX,DX
  191.   0000:009C A35400          MOV     [0054],AX
  192.