From: rick.c.hodgin@nospicedham.gmail.com   
      
   On 7/18/2018 1:05 PM, Rick C. Hodgin wrote:   
   > I'll post an updated version of this later. I've thought of some   
   > additional optimizations to my algorithm.   
      
   Here's the latest version:   
      
   #include    
   #include    
   #include    
      
   void fizz(int num) { printf("fizz\n"); }   
   void buzz(int num) { printf("buzz\n"); }   
   void fizzbuzz(int num) { printf("fizzbuzz\n"); }   
   void other(int num) { printf("%d\n", num); }   
      
   void (*funcs[4])(int num) = { other, fizz, buzz, fizzbuzz };   
      
   int main(int argc, char* argv[])   
   {   
    _asm   
    {   
    xor esi,esi ; Count (1..100)   
    mov edx,1 << 2 ; 3-bit cycler   
    mov edi,1 << 5 ; 5-bit cycler   
      
    top_loop:   
    inc esi ; Increase our count   
    mov eax,edx ; Load 3-bit value   
    mov ebx,edi ; Load 5-bit value   
    and eax,1 ; Lower-bit of 3-bit value   
    and ebx,2 ; 2nd bit of 5-bit value   
    add eax,ebx ; Add and get function offset   
    lea ebx,[offset funcs + eax*4]   
      
    ; Print algorithm can be modified to something simpler   
    pushad   
    push esi   
    call [ebx]   
    add esp,4   
    popad   
      
    ; Rotate lower 3-bits   
    mov eax,edx   
    and eax,1   
    shr edx,1   
    shl eax,2   
    or edx,eax   
      
    ; Rotate bits 6..1 (ignores lower bit after shifting)   
    shr edi,1   
    mov ebx,edi   
    and ebx,1   
    shl ebx,5   
    or edi,ebx   
      
    ; Are we done?   
    cmp esi,100   
    jb top_loop   
    }   
    return(0);   
   }   
      
   I still see some possible optimizations. Will work on it when I   
   get time. :-)   
      
   Oh Terje ... please school us on how to better optimize.   
      
   --   
   Rick C. Hodgin   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|