Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!brutus.cs.uiuc.edu!apple!vsi1!wyse!mips!earl@wright.mips.com From: earl@wright.mips.com (Earl Killian) Newsgroups: comp.sys.mips Subject: Re: Redefinition of left shift operator Message-ID: <26036@wright.mips.COM> Date: 23 Aug 89 02:00:02 GMT References: <4724@portia.Stanford.EDU> Sender: earl@mips.COM Reply-To: earl@wright.mips.com (Earl Killian) Distribution: usa Organization: MIPS Computer Systems Inc. Lines: 25 In-reply-to: edgar@portia.Stanford.EDU (Edgar Holmann) In article <4724@portia.Stanford.EDU>, edgar@portia (Edgar Holmann) writes: >Has the left shift operator been redefined in the MIPS systems from >the typical shift to a modulo type shift? By this I mean: > i << j >redefined to > i << (j % 32) The C language does not define shifts < 0 or >= the size of the type, so any program where the above statements differ is illegal. This allows compilers to generate a raw shift instruction, which is in line with C's efficiency goals. All instruction set architectures (ISAs) that I know take the shift count modulo some small power of two (e.g. 32-256). The MIPS ISA in particular takes the shift count modulo 32, which gives different results on illegal programs than say a 68000, which takes the shift count modulo 64. So the bottom line is that you need to use conditionals when your shift count is of larger range. If C shifts were defined for shifts >= size of the type, then all variable shifts would require the compiler to generate the conditional, on all architectures, and you probably wouldn't like the performance of that. -- UUCP: {ames,decwrl,prls,pyramid}!mips!earl USPS: MIPS Computer Systems, 930 Arques Ave, Sunnyvale CA, 94086