home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 2,646 of 2,978   
   Dr J R Stockton to All   
   Re: Possible to inline this code?   
   04 Jun 08 21:22:13   
   
   From: jrs@merlyn.demon.co.uk   
      
   In comp.lang.pascal.borland message <4846c1ae.1190050@news.individual.ne   
   t>, Wed, 4 Jun 2008 16:27:04, Wolfgang Ehrhardt  posted:   
   >On Sat, 31 May 2008 10:33:25 -0700 (PDT), Jim Leonard   
   > wrote:   
   >   
   >>I have a function that I am using in several places in an inner loop.   
   >>The function converts an input nybble to it's ascii equivalent:   
   >>   
   >>Function HexNybble(b:byte):char; assembler;   
   >>{thanks to Norbert Juffa}   
   >>asm   
   >>  mov al,b   
   >>  cmp al,10       {if x<10, set CF=1}   
   >>  sbb al,69h      {0-9: 96h..9Fh, A-F: A1h..A6h}   
   >>  das             {0-9: subtr. 66h -> 30h-39h;   
   >>                   A-F: subtr. 60h -> 41h-46h}   
   >>end;   
   >>   
   >>The problem is, this code is (obviously) being CALL'd every time it is   
   >>used, and each CALL (28 cycles) and RET (26 cycles) are adding 54   
   >>unnecessary cycles to this code.   
   >   
   >If you want real speed, setup a (global) lookup table   
   >   
   >const Nibbles: array[byte] of char =  '012345...'   
      
   That will reduce the source code, at each point of use, to the same size   
   as the function non-call originally hoped for.   
      
   As the input is a nibble, only the first 16 elements of the array will   
   be used.   
      
   For speed, there should be no range-checking there.  OTOH, I consider it   
   unwise to have range-checking off globally.  If the array is indeed   
   byte-sized, and the indexes used are all byte-sized, then ISTM that the   
   compiler should feel no need to check their range.   
      
   --   
    (c) John Stockton, nr London UK.  ?@merlyn.demon.co.uk  Turnpike v6.05  MIME.   
      TP/BP/Delphi/&c., FAQqy topics & links;   
        RAH Prins : c.l.p.b mFAQ;   
      Timo Salmi's Turbo Pascal FAQ.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca