This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC-generated code and i386 condition codes behavior


Andi Kleen wrote:
Robert Dewar <dewar@adacore.com> writes:

I must say I am a bit surprised that gcc never takes advantage
of the fact that inc and dec do not destroy the carry flag, this
is quite significant for some loops.


A lot of this old wisdom is no longer true.

inc and dec are to be generally avoided these days, because the
partial changing of EFLAGS causes too strict dependencies on Intel P4
cores and threefore slower execution. It's better to use add/sub
$1,... instead, except if you're optimizing for code size.

actually as Geert points out, probably LEA is the right choice when you don't want to affect the flags, though in this case I guess you need some otherway to test for loop termination. Not clear how you do that without destroying the carry flag. I will do some benchmarks in this area to see how the old wisdom holds :-)

-Andi



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]