News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

What is more efficient? [Solved]

Started by lonewolff, March 07, 2009, 03:09:09 AM

Previous topic - Next topic

jj2007

Quote from: Mark Jones on March 06, 2009, 04:04:20 PM
Also, in a speed-critical application, you can give the conditional jumps a "branch hint prefix." Take a look at the macro being used here (not that that code itself was designed for speed):
http://www.masm32.com/board/index.php?topic=10919.msg80277#msg80277

I tested that, it makes absolutely no difference; the reason being that the default predictor is most of the time correct anyway. GCC and ICC have switched it off completely:

Branch hint prefixes
GCC has support for this feature, but it has turned out to not gain
anything and was disabled by default, since branch reordering streamlines
code well enough to match the default predictor behaviour.
Same conclusion was done by other compiler teams too, ICC is not
generating the hints either.

RuiLoureiro

Quote from: lonewolff on March 07, 2009, 04:37:40 AM
If you logical AND something against itself, wont you always get a result of true? I must be missing something  :red
Hi
        The logical AND of 2 bits: 0 AND 0 = 0   ; 0 AND 1 = 0  ; 1 AND 0 = 0; 1 AND 1 = 1

        If X is a variable with 2 bits: 00, 01, 10 or 11 then

                      X    |    X    |   X AND X | ZF is set according to the result
                      ----------------------------
                      00   |   00    |   00     => ZF=ZeroFlag= 1 means X is zero
                      01   |   01    |   01     => ZF         = 0 means X is not zero
                      10   |   10    |   10     => ZF         = 0          "  "    "
                      11   |   11    |   11     => ZF         = 0          "  "    "

        Note that the result is X:    X AND X = X

        Then, if we     test  X, X    then      if X=0 then ZF=1;
                                                 otherwise             ZF=0

        In this way,  «AND   eax, eax» doesnt change eax because eax AND eax = eax
        and           «TEST  ..., ...» doesnt change because the result are discarded
       
Rui

lonewolff

Some great information.

This has been very helpfull.

I am going to go with the asm style instead of using IF statements. So, over time I will be able to look at some pure assembly calls and understand what is going on.

Thanks again guys!  :U

NightWare

once you will be a bit more experienced, read agner fog's optimization pdf. you will see that, sometimes, it's possible to not jump at all (coz jumps have a price...).

lonewolff

Thanks for the reference. I have just downloaded it.

Looks pretty full on. Som light bedtime reading  :bg