Numeric comparisons
Frank Adams
franka at mmintl.UUCP
Tue Sep 24 10:12:41 AEST 1985
[Not food]
In article <726 at terak.UUCP> doug at terak.UUCP (Doug Pardee) writes:
>Fortunately, the more modern CPU chips are designed with a proper
>compare instruction which does bit-wise comparison instead of
>subtraction. All I ask is that the compiler writers *use* those
>instructions the way they were intended, instead of substituting a
>subtraction. <Fortunately, the NS32000 CPUs don't provide status bits
>(except carry) on subtraction, so the compiler writer is forced to use
>the bit-wise compare instruction>.
Many (most?) of those chips set the flags the same way after a subtract
as after a compare. For that class of chips, a compare is a subtract with
the correct flags set.
Architectures where a branch cannot be taken based on a comparison of two
signed numbers with two instructions (maybe three) are brain-damaged. It
doesn't matter (much) whether the first instruction is a subtract or a
compare.
Compilers should generate a correct branch even on brain-damaged machines.
Compilers for a machine where a compare and branch works, but a subtract
and branch doesn't, but which use a subtract and branch, are *really*
brain-damaged.
Frank Adams ihpn4!philabs!pwa-b!mmintl!franka
Multimate International 52 Oakland Ave North E. Hartford, CT 06108
More information about the Comp.lang.c
mailing list