home bbs files messages ]

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

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

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

   Message 2,862 of 4,675   
   Rod Pemberton to Melzzzzz   
   Re: Branching two check increment pays o   
   19 Jul 17 16:19:58   
   
   From: NeedNotReplyHere@nospicedham.xrsevnneqk.cem   
      
   On Wed, 19 Jul 2017 17:13:54 +0000 (UTC)   
   Melzzzzz  wrote:   
      
   > I have following code snippet:   
   >   
   >     cmp r9,1   
   >     je .one   
   >     add rdi,r9   
   >     sub rdx,r9   
   >     jmp .L0   
   > .one:   
   >     inc rdi   
   >     dec rdx   
   >     jmp .L0   
   >   
      
   Eh, where is "cmp r9,0" check?   
   What about a .two section? .three? .four?   
      
   > For some reason I did it like that and it seems that doesn't hurt, but   
   > gives significant boost in some cases?   
      
   Does the "significant boost" imply r9 is more frequently '1' than other   
   values for r9?  Could that be why you optimized r9 for '1' but not   
   '0' or '2' etc?  ...   
      
   > Am I doing it wrong or is this good practice?   
      
   Doing what wrong?   
      
   Are you asking about branching?   
   If so, it's easy for you to reorder and test:   
      
        cmp r9,1   
        jne .most   
        inc rdi   
        dec rdx   
        jmp .L0   
     .most   
        add rdi,r9   
        sub rdx,r9   
        jmp .L0   
      
   In fact, you can easily add a case for 0, 2, 3, 4, ...   
      
   Or, were you asking about speed?   
   That depends not just on the branch order, but also the values r9   
   commonly has.  How many different values can r9 be?   
      
   Or, were you asking about not using the tail optimization?   
   Clearly, you think it's faster sometimes with the optimization.   
      
   Why are you both incrementing and decrementing?  I.e., can you make   
   your code better, faster, etc by using only one register, and   
   subtracting rdi where you're using rdx?   
      
      
   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)   

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


(c) 1994,  bbs@darkrealms.ca