[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (1 << -1) ?
On Sat, 14 Sep 2002, Hans-Peter Nilsson wrote:
> > Date: Sat, 14 Sep 2002 16:36:04 +0200
> > From: Sebastian Andersson <firstname.lastname@example.org>
> > I've noticed a difference in the semantics between gcc-2.95 and gcc-3.0
> > on i386 and the cris-1.15 version of gcc-2.96.
> > This lines:
> > printf("%u\n", 1<<(-1));
> > gives 0 the cris and 2147483648 on i386.
> > Since gcc gives a warning about this, I assume the result
> > is undefined in the ISO C standard, is that correct
If I remember correctly, the shift operation in ISO C is defined for
shifts from 0 up to and including the number of bits in the shifted
operand. Am I right ?
The CRIS instruction set is designed to simplify the implementation of
"shift the number of bits in the shifted operand", by using a 6-bit
shift value instead of just 5 bits. If bit 5 is set, the result will be 0
(or all 1's if it is a negative number shifted right with ASR).