> Funny. Last time I looked there was no cmpl in this case.

That's because you are using predecrement in this example.  It changes
the test completely.  With predecrement you only iterate the loop 4
times, and iterate 5 times with post decrement. Since it is
postdecrement, it needs the compare the loop iterator against -1, not 0
or else it will miss the last loop iteration.

Change your more recent test case to i--, then look at the assembly.
There will be a cmpl $-1

> What version are you using?

gcc version 4.2.0 20060327 (experimental)

Previously I was using gcc 4.2, but for your sake here is your recent
test case with postdecrement and gcc 3.3 at -O3:

.L6:
        addl    %edx, %eax
        decl    %edx
        cmpl    $-1, %edx
        jne     .L6
        movl    %ebp, %esp
        popl    %ebp
        ret
        .size   main, .-main
        .section        .note.GNU-stack,"",@progbits
        .ident  "GCC: (GNU) 3.3.6 (Debian 1:3.3.6-7)"

> Aehm, wait. Did you use '--i' or 'i--'? You need the latter (both to be
> correct and to achieve the savings)

i-- which is what you originally suggested and what I said I had used.

> I tend not to do micro optimizations myself as well - unless I think I
> know what am doing.

Good luck. 

Regards,

Ryan Mansfield

_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to