Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!brutus.cs.uiuc.edu!apple!vsi1!wyse!mips!rudy From: rudy@mips.COM (Rudy Wang) Newsgroups: comp.sys.mips Subject: Re: Redefinition of left shift operator Message-ID: <26035@gumby.mips.COM> Date: 23 Aug 89 01:45:25 GMT References: <4724@portia.Stanford.EDU> Reply-To: rudy@mips.COM (Rudy Wang) Distribution: usa Organization: MIPS Computer Systems, Sunnyvale, CA Lines: 40 In article <4724@portia.Stanford.EDU> edgar@Neon.Stanford.EDU (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) >This is evident when you shift by a quantity larger than or equal to the int >size (32). When j is a constant, the compiler issues a warning message (when >using the optimizer level 2 or 3). Now, I see that nobody should be shifting >by a constant larger than 32 but what about shifting by another variable when >creating a mask? Thus, a simple statement of the form > (1L << j) - 1 >or > ~(~0 << j) >now has to have a conditional to handle the case when j is 32. I have tried >this on an R3000 running Ultrix 3.1 with cc1.31. The same result is obtained >in an R2000. > >Is this considered a "feature" of the mips compiler or is it something that >will get changed in a new release? > >edgar Please read the definition of the "shift operators" on page 189 of the 1st edition "The C programming language" (page 206 of the 2nd edition, says the same thing). When the shift amount is greater than or equal to the length of the object in bits, the result is undefined! In Mips' case, it simply chooses to shift the amount modula 32 (or just to use the lower 5 bits). Please see page A-63 of the Mips R2000 RISC architecture, by Kane. -- UUCP: {ames,decwrl,prls,pyramid}!mips!rudy (or rudy@mips.com) DDD: 408-991-0247 Rudy Wang (or 408-720-1700, Ext. 247) USPS: MIPS Computer Systems, 930 Arques, Sunnyvale, CA 94086-3650 Quote: "Time sure is fun when you're having flies!" - Kermit the frog