P
Phil Carmody
Tim Rentsch said:Phil Carmody said:Tim Rentsch said:On Sat, 26 Sep 2009 10:47:58 +0300, Phil Carmody wrote:
[UNSNIP - "At the CPU level ... "]
With two's complement, addition, subtraction and multiplication (but not
division) behave identically for signed or unsigned values.
Full- (or double-, depending on your PoV) width multiplies are different
too. ff*ff = 0001 or fe01.
My PoV is "double-".
In C
Nah, doesn't wash. We were at the CPU level, if you remember.
, int * int -> int, long * long -> long, and so on.
Once the types have been promoted, it makes no difference as to their
signedness. OTOH, the promotion is affected by the signedness.
Apart from division, the only common instruction which has signed and
unsigned variants is a right shift.
And multiply.
True for x86's double-width multiply, but how many architectures have that
feature?
Well, the first processor I used that had a multiply instruction had both
signed and unsigned. The architecture I've used the most since then also
had this pair. The two other architectures I've used extensively in that
time also have them. Of the two other architectures I've used but not
extensively programmed for, one didn't have a muliply at all, the other
had both types. Only one architecture I've used that has a multiply
instruction at all fails to have the pair. [snip summary]
The point is that to supply C semantics the architecture
needs to provide only one multiply instruction (if 2's
complement representation is used). Presumably the
architectures you mentioned either weren't using
2's complement, or had separate instructions to
set overflow/carry flags differently (or for some
other multiple-precision arithmetic capability).
Close. Your presumptions are true for 4 of the 5 archs.
I thought it was implied that I wasn't including the
case where the processor had no multiply instructions
at all.
Jeebus. I never thought that _you_ would be >this< close to being
stuffed in my killfile. Please learn to count before posting to
usenet again.
Phil