Definition of boolean type
Joe English
jeenglis at nunki.usc.edu
Thu Mar 2 08:40:28 AEST 1989
gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <6849 at pogo.GPID.TEK.COM> rickc at pogo.GPID.TEK.COM (Rick Clements) writes:
>>With the compiler I am currently using, I use "if (x == FALSE)" or
>>"if (x != FALSE). ... The compiler I am using generates LESS code
>>this way. ("if (x)" causes it to go to the work of converting it to
>>a 1 or 0 with some less than efficient code.
>
>That's pretty strange -- "if(x)" means no more and no less than
>"if x is nonzero", which nearly all instruction sets support directly.
>It's easy to imagine a dumb compiler that produces MORE code for
>"if(x!=0)" but not one that produces LESS code.
I once had to work with a compiler that was broken in a
similar way: boolean expressions would calculate either a 0
or a 1, then test that result and branch accordingly. This
generated *three unnecessary instructions* for every
relational expression. (And the fourth pass of the compiler
was called the "optimizer!" I don't think it did a very
good job of optimizing...)
If I recall correctly, it generated the same amount of code
for "if(x)" and "if(x!=0)," but it went something like:
Compare x and zero;
move 1 into AX;
if test yielded equal, skip next instruction;
move 0 into AX;
Then it would do an "OR AX,AX" and branch accordingly.
Shocking, but true.
Before you ask (so you can avoid purchasing it :-), the
compiler in question is an old (c. 1984) version of Computer
Innovation's C86, I think somewhere around version 1.2.
--Joe English
jeenglis at nunki.usc.edu
More information about the Comp.lang.c
mailing list