Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 May 1996 23:08:25 +0200 (SAT)
From:      Robert Nordier <rnordier@iafrica.com>
To:        terry@lambert.org (Terry Lambert)
Cc:        chat@freebsd.org
Subject:   Re: strcpy, strcat: not the same look & feel.
Message-ID:  <199605282108.XAA00428@eac.iafrica.com>
In-Reply-To: <199605281805.LAA11436@phaeton.artisoft.com> from "Terry Lambert" at May 28, 96 11:05:39 am

next in thread | previous in thread | raw e-mail | index | archive | help
Terry Lambert wrote:

> There is also some conventional wisdom on pre vs. post-incrementing,
> which I wasn't going to mention because I was under the impresson
> that all modern compilers dealt with it.
> 
> Post-increment is generally faster if you have the instruction set for
> it; not all systems have the instruction set.

This is interesting, and made me recall some old x86 stuff which makes
the opposite claim.  The context is different, of course, so it doesn't
really contradict Terry.

     Pre-increment/decrement operators are often more efficient than
     the post-increment/decrement version.  This is valid mostly when
     these operators are combined in the expressions using compares
     (like ++i), and has no effect if the simple ++i; or i; is done
     (without a compare).  The reason for this is that the processor
     flags are changed by ++ or, thus the (i++ N) must generate an
     extra code (usually a JMP) to prevent ++ from destroying the
     result of the compare.

          -- RT

This is a great piece of technical explanation, and anyone who wants
to score points in -hackers can learn a lot from it:  Keep your
examples inline, limited to 4 characters or less, and get them mostly
wrong. :)

RT "designed and coded the world's first MS-DOS based multi-user,
multi-processor operating system."  (Though, to be fair, RT probably
just had a lousy copy editor.)

Any guesses what extra code the statement

   i++ N

would generate, if not a JMP?

-- 
Robert Nordier



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605282108.XAA00428>