home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / 554 / JUIN / UPPER2.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-07  |  4KB  |  79 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 22 of 91
  3. From : Bob Swart                           2:281/256.12         11 Jun 93  21:00 
  4. To   : Sean Palmer                         1:104/123.0                           
  5. Subj : uppercase contest                                                      
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  > Also to Bob Swart
  8. Also to Wilbert ;-)
  9.  
  10.  > Just thought I'd improve what little I can on the uppercase routine so
  11.  > far. This should be faster than Bob's inline macro...
  12. I couldn't resist, you here's an InLine macro that's about 10-50% faster than
  13. your routine.
  14.  
  15.  > this changes a compare/jump into a subtract...
  16. It looks a bit like the SBB code Wilbert posted earlier, only your routine
  17. doesn't eliminate the jump if no change is made to the character.
  18.  
  19.  > To Wilbert: clearing the prefetch queue takes less time than an extra
  20.  > explicit memory reference each time through the loop.
  21. On what machines have you tested this? On a 386 you seem correct, but I don't
  22. know about a 486 (or Pentium for that matter).
  23.  
  24.  >  mov bx,$1961  {'z'-'a', 'a'}{
  25.  > :
  26.  >  sub al,bl
  27.  >  cmp al,bh
  28.  >  ja @S;
  29.  >  sub byte ptr[si-1],32
  30. I used some parts of your routine, unrolled the loop to uppercase two
  31. characters at the same time, start with the first character if the number of
  32. characters in the string is odd, and eliminated some extra jumps and the loop
  33. (although I use a modified loop-like construct, of course). I came up with the
  34. following 52-byte InLine macro, which is the fastest I have seen so far:}
  35.  
  36.   procedure Upper11(var Str: String);
  37.   { 52 Bytes by Bob Swart, 11-6-1993 }
  38.   InLine(
  39.     $8C/$DA/               {       mov   DX,DS                }
  40.     $BB/Ord('a')/
  41.         Ord('z')-Ord('a')/ {       mov   BX,'z'-'a'/'a'        }
  42.     $5E/                   {       pop   SI                    }
  43.     $1F/                   {       pop   DS                    }
  44.     $FC/                   {       cld                         }
  45.     $AC/                   {       lodsb                       }
  46.     $88/$C1/               {       mov   CL,AL                 }
  47.     $30/$ED/               {       xor   CH,CH                 }
  48.     $D1/$E9/               {       shr   CX,1                  }
  49.     $73/$0B/               {       jnc   @Part1                }
  50.     $AC/                   {       lodsb                       }
  51.     $28/$D8/               {       sub   AL,BL                 }
  52.     $38/$F8/               {       cmp   AL,BH                 }
  53.     $77/$04/               {       ja    @Part1                }
  54.     $80/$6C/$FF/
  55.         Ord('a')-Ord('A')/ {@Loop: sub   Byte Ptr[SI-1],'a'-'A'}
  56.     $E3/$14/               {@Part1:jcxz  @Exit                 }
  57.     $AD/                   {       lodsw                       }
  58.     $28/$D8/               {       sub   AL,BL                 }
  59.     $38/$F8/               {       cmp   AL,BH                 }
  60.     $77/$04/               {       ja    @Part2                }
  61.     $80/$6C/$FE/
  62.         Ord('a')-Ord('A')/ {       sub   Byte Ptr[SI-2],'a'-'A'}
  63.     $49/                   {@Part2:dec   CX                    }
  64.     $28/$DC/               {       sub   AH,BL                 }
  65.     $38/$FC/               {       cmp   AH,BH                 }
  66.     $77/$EC/               {       ja    @Part1                }
  67.     $EB/$E6/               {       jmp   @Loop                 }
  68.     $8E/$DA);              {@Exit: mov   DS,DX                 }
  69.  
  70.  > inline macros are great and all but they really bloat your code...
  71. Oh well, even when written as a 'genuine' BASM routine it still is faster than
  72. your routine (It is slower when the string has only one character, but faster
  73. on all other cases, relatively gaining speed (compared to your routine) when
  74. the length of the string increases.
  75.  
  76. But remember:
  77. {$BOLD ON}
  78. There Ain't No Such Thing As The Fastest Code!
  79. {$BOLD OFF}