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 3,805 of 4,675   
   Alex McDonald to Terje Mathisen   
   Re: Fast conversion to a boolean of 0 or   
   07 Mar 19 14:47:48   
   
   From: alex@nospicedham.rivadpm.com   
      
   On 07-Mar-19 06:35, Terje Mathisen wrote:   
   > On Wednesday, March 6, 2019 at 2:47:41 PM UTC-5, James Harris wrote:   
   >> A small programming challenge if you are interested, just for fun.   
   >   
   > What happens if you do:   
   >   
   >    neg eax   
   >    mov eax,0   
   >    adc eax,eax   
   >   
   > This does not use any extra regs, and the NEG and the MOV should still   
   > run in the same cycle even if they both use EAX as the target. This is   
   > because the MOV form is known to not depend on the previous value in   
   > EAX, so it can be started even before the NEG.   
   >   
   > Terje   
   >   
   >   
      
   If you're willing to accept 0 or -1 (all bits set if EAX <> 0) then   
      
          add     eax,-1   
          sbb     eax,eax   
      
   The opposite test (return all bits set if EAX == 0) is   
      
          sub     eax,1   
          sbb     eax,eax   
      
   Some other neat comparison operations are   
      
   Unsigned EAX < EDX (swap the regs in CMP for unsigned EAX > EDX)   
      
          cmp     edx,eax   
          sbb     eax,eax   
      
   The following are 3 instruction forms; I don't think there are 2   
   instruction forms of these tests.   
      
   EAX == EDX   
      
          sub     eax,edx   
          sub     eax,1   
          sbb     eax,eax   
      
   EAX <> EDX   
      
          sub     eax,edx   
          add     eax,-1   
          sbb     eax,eax   
      
      
   --   
   Alex   
      
   --- 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