Re: arm9e: how do I invert sign of a halfword?
- From: "Wilco Dijkstra" <Wilco.removethisDijkstra@xxxxxxxxxxxx>
- Date: Wed, 30 Jul 2008 21:39:47 +0100
"CBFalconer" <cbfalconer@xxxxxxxxx> wrote in message news:488F62DB.2B97BCCD@xxxxxxxxxxxx
Wilco Dijkstra wrote:
"CBFalconer" <cbfalconer@xxxxxxxxx> wrote:
Wilco Dijkstra wrote:
... snip ...
FYI The standard is actually incorrect here in making all negative
left shifts undefined. Positive leftshifts that overflow are
undefined too. However multiplies of positive and negative numbers
are defined if no overflow occurs, and only implementation defined
if they overflow...
There is no known error in the portion I quoted (and you snipped).
If you don't pay attention, you will sooner or later have to pay.
If you don't think it's an error, maybe you can explain why it is
correct?
Just consider the meaning and action on machines using ones
complement or sign-magnitude conventions. Also the fact that the
occurence of an overflow can cause implementation defined action.
I did consider that and this is exactly why the C standard is incorrect:
Arithmetic one-complement shifts shift the sign into either the MSB
(right shift) or LSB (left shift). Sign magnitude only shifts the magnitude
for both left and right shift. This gives the correct arithmetic results, ie.
-0 stays -0, -1 becomes -0 on a right shift, and -2 on a left shift etc.
So given arithmetic shifts are well defined in all 3 representations
why would anyone make left shifts undefined and right shifts
implementation defined? It doesn't make any sense.
That's why, for safe behaviour, you should restrict shifts to
operating on unsigned quantities.
No. There is no reason to restrict shifts at all as you get the same
results irrespectively of which representation is used.
Wilco
.
- Follow-Ups:
- Re: arm9e: how do I invert sign of a halfword?
- From: CBFalconer
- Re: arm9e: how do I invert sign of a halfword?
- References:
- Re: arm9e: how do I invert sign of a halfword?
- From: Everett M. Greene
- Re: arm9e: how do I invert sign of a halfword?
- From: CBFalconer
- Re: arm9e: how do I invert sign of a halfword?
- From: Wilco Dijkstra
- Re: arm9e: how do I invert sign of a halfword?
- From: CBFalconer
- Re: arm9e: how do I invert sign of a halfword?
- From: Wilco Dijkstra
- Re: arm9e: how do I invert sign of a halfword?
- From: CBFalconer
- Re: arm9e: how do I invert sign of a halfword?
- Prev by Date: Re: Affordable PCB Layout Software ???
- Next by Date: PIC 18F4550 - EUSART does not generate interrupts
- Previous by thread: Re: arm9e: how do I invert sign of a halfword?
- Next by thread: Re: arm9e: how do I invert sign of a halfword?
- Index(es):
Relevant Pages
|