Subject: Re: Libraries in standalone programs (pmax/ELF specific?)
To: Curt Sampson <firstname.lastname@example.org>
From: Chris G. Demetriou <email@example.com>
Date: 03/31/1999 08:08:58
Curt Sampson <firstname.lastname@example.org> writes:
> On Wed, 31 Mar 1999, Simon Burge wrote:
> > On the pmax, this generates slightly smaller code.
> > ...
> > - while (n-- > 0)
> > + while (n--)
> Well, I suppose that doesn't actually change what the test does,
> since n is unsigned (at least I believe size_t is unsigned on all
> machines), but it does change the op (from > to !=), which may
> actually go and change the number of instructions on other platforms
> as well, potentially the other way....
probably not, really. i'm acrually surprised that the pmax compiler
generates the extra instruction. for an unsigned number, (n > 0) is
always simply (n != 0).
does the mips compiler do the 'wrong thing' still with (n-- != 0)?
I'm not particularly keen on using 'counting' integers as booleans,
which is why i wrote the code that way. I think the "!= 0" or "> 0"
test is easier to understand, it it has the same logical
effect... (and it should be a simple optimization to do the right
Anyway, if you're going to make a change like this, you should also
change at least bcopy.c, bzero.c and memset.c.
Chris Demetriou - email@example.com - http://www.netbsd.org/People/Pages/cgd.html
Disclaimer: Not speaking for NetBSD, just expressing my own opinion.