Date: Mon, 28 Mar 2005 19:48:53 +0200
From: Phillip Helbig <[log in to unmask]>
> Our hardware
> returns 0 for false compares and 1 for true. The reason in simple. C
> defines false and true this way,
Isn't 0 false and anything else true, though 1 is often used?
Canonical value and testing methods. According to the C language, 0
and 1 are the values generated if you capture the value of a boolean
operation, e.g.,
int value = (a < b);
or int same = ((a < b) == (c < d));
When testing, 0 is considered false and non-0 is considered true:
if (any_old_int) ...
Compilers may be able to optimize
if (a < b) ...
if the machine has compare_and_branch instructions rather than doing
the compare and test separately. PDP-11 would compare (not generating
a value) to the condition bits and then do a conditional branch. IA64
compares sending the results to the predicate registers; conditional
branches are just predicated normal branches, and if you want 0/1 as
values you'll need to do predicated moves. I'm sure CPU architects
have a field day with these tradeoffs.
|