From: NeedNotReplyHere@nospicedham.xrsevnneqk.cem   
      
   On Thu, 3 Aug 2017 23:00:16 +0000   
   Robert Prins wrote:   
      
   > I've recently come across some really clever/very nasty PL/I code,   
   > that would, theoretically, save CPU by eliminating a conditional   
   > jump. It relies on initializing a BCD-encoded ***integer*** variable   
   > ("sum") with -0.1, which results, on IBM mainframes, the last nibble   
   > of the BCD encoded value to contain 0xD (rather than the normal 0xC).   
   > The author uses this to avoid a costly (Phuleeze, pass me a bucket!)   
   > test, so rather than coding:   
   >   
   > sum = -1;   
   >   
   > do i = 1 to whatever;   
   > if a(i) >= 0 then   
   > if sum <> -1 then   
   > sum = sum + a(i);   
   > else   
   > sum = a(i);   
   > end;   
   >   
   > if sum <> -1 then "print sum";   
   >   
   > the code can be simplified to   
      
      
   Do you need to print the result when the sum is zero? Why? ...   
      
   In other words, can you change "a(i)>=0" to "a(i)>0"? If you can, then   
   you should be able to use:   
      
   sum = 0;   
   do i = 1 to whatever;   
    if a(i) > 0 then   
    sum = sum + a(i);   
   end;   
      
   if sum <> 0 then "print sum";   
      
      
   If not, I would probably add a flag to separate out the check as to not   
   use any special tricks:   
      
   sum = 0;   
   set = 0;   
   do i = 1 to whatever;   
    if a(i) >= 0 then do;   
    sum = sum + a(i);   
    set = 1;   
    end;   
   end;   
      
   if set = 1 then "print sum";   
      
      
   Rod Pemberton   
   --   
   Liberals love to point out that vehicles contribute to climate change.   
   Conservatives should point out that living in skyscrapers does so too.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|