[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*To*: Hans-Peter Nilsson <hp@xxxxxxx.com>*Subject*: Re: (1 << -1) ?*From*: Per Zander <perz@xxxxxxx.com>*Date*: Mon, 16 Sep 2002 09:31:15 +0200 (MET DST)*Cc*: sa@xxxxxxx.net, dev-etrax@xxxxxxx.com*In-reply-to*: <200209141810.UAA15533@xxxxxxx.se>*Sender*: owner-dev-etrax@xxxxxxx.com

On Sat, 14 Sep 2002, Hans-Peter Nilsson wrote: > > Date: Sat, 14 Sep 2002 16:36:04 +0200 > > From: Sebastian Andersson <sa@xxxxxxx.net> > > > 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 > > Yes. > 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). Per Z.

**Follow-Ups**:**Re: (1 << -1) ?***From:*Hans-Peter Nilsson <hp@xxxxxxx.com>

**References**:**Re: (1 << -1) ?***From:*Hans-Peter Nilsson <hp@xxxxxxx.com>

- Prev by Date:
**Re: (1 << -1) ?** - Next by Date:
**Re: (1 << -1) ?** - Previous by thread:
**Re: (1 << -1) ?** - Next by thread:
**Re: (1 << -1) ?** - Index(es):