Xref: utzoo comp.lang.c:11412 comp.std.c:193 Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ucbvax!decwrl!decvax!watmath!rbutterworth From: rbutterworth@watmath.waterloo.edu (Ray Butterworth) Newsgroups: comp.lang.c,comp.std.c Subject: Re: Shifting question Message-ID: <19962@watmath.waterloo.edu> Date: 19 Jul 88 14:53:15 GMT References: <705@bnr-rsc.UUCP> <11556@steinmetz.ge.com> <60290@sun.uucp> Followup-To: comp.std.c Organization: U of Waterloo, Ontario Lines: 36 In article <60290@sun.uucp>, guy@gorodish.Sun.COM (Guy Harris) writes: > > action of doing: > > x >>= 16; x>>= 16; > > better be the same as: > > x = x>>32; > > Perhaps they *should*; however, neither the K&R nor the January 11 ANSI C draft > specifications for the language require this. If you think that they should, I > suggest you lobby the ANSI C committee. I can see why the Committee should NOT require that (for n>0) "x >>= n;" be the same as "while (n--!=0) x>>=1;". Imagine a machine with 16 bit words and a logical right shift instruction that only looks at the lowest 4 bits of the shift size. "x >>= n;" could simply grab the 4 lower bits of "n" to determine the size of the shift. But if the Standard required the requested behaviour, the compiler would have to generate a lot of extra code for every shift to change it to a store-zero whenever "n" is greater than 15. e.g. LOAD n Put the shift size into the register. CMPI #15 Is it bigger than 15? TLTZ +3 LRS x No, shift x right by lower 4 bits of the register TRA +2 STZ x Yes, so store zero instead of simply LOAD n LRS x Shift x right by lower 4 bits of n No, I don't know of any such machine. Yes, I know it would be more efficient to change positions of the shift and store-zero cases.