Menu

and ax,ax

2012-10-07
2013-04-20
  • Hjort Nidudsson

    Hjort Nidudsson - 2012-10-07

    Some strange test results: (.if ax)

    _test1: ; 54 Clock ticks
        test ax,ax
        test ax,ax
        test ax,ax
        test ax,ax
        dec cx
        jnz _test1
        ret
    _test2: ; 108
        and ax,ax
        and ax,ax
        and ax,ax
        and ax,ax
        dec cx
        jnz _test2
        ret
    _test3: ; 108
        or ax,ax
        or ax,ax
        or ax,ax
        or ax,ax
        dec cx
        jnz _test3
        ret
    _test:
        xor dx,dx
          @@:
        xor cx,cx
        call _test3
        dec dx
        jnz @B
        ret
    
     
  • japheth

    japheth - 2012-10-09

    The result doesn't look strange to me. However, it's not a realistic usage of these instructions. Usually a "test ax,ax", "and ax,ax" or "or ax,ax" is followed by a conditional jump. I guess with the jump there's almost no difference in timings.

     
  • Hjort Nidudsson

    Hjort Nidudsson - 2012-10-09

    I did some of these test a long time ago, and I think the result was that "or" was slightly faster than "and" for some reason.

    I write most code using pascal (or stdcall) to avoid the "add (e)sp,args" which destroyes the flags on return.

        invoke  func(strcmp,s1,s2) 
        jz  is_equal
    

    Most of the conditional jumps are from these function calls; so returning flag in all library (and local) functions reduces code size and time. If not done in this way, the test must be repeated on all calls.

    From the (old) 8086/80486 - Intel 8086 Family Architecture:

                                     Clocks                 Size
            Operands         808x  286   386   486          Bytes
    test    reg,reg           3     2     1     1             2
    or  reg,reg           3     2     2     1             2
    and reg,reg           3     2     2     1             2
    

    Same byte size, so why is "or" and "and" preferred?

     
  • japheth

    japheth - 2012-10-11

    > so why is "or" and "and" preferred?

    jwasm does it because Masm does it.

     

Log in to post a comment.