Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site nrcvax.UUCP Path: utzoo!linus!decvax!ittatc!dcdwest!sdcsvax!sdcrdcf!psivax!nrcvax!jj From: jj@nrcvax.UUCP (Utah) Newsgroups: net.lang.c Subject: Re: Right shift vs. divide Message-ID: <449@nrcvax.UUCP> Date: Tue, 24-Dec-85 12:37:21 EST Article-I.D.: nrcvax.449 Posted: Tue Dec 24 12:37:21 1985 Date-Received: Sat, 28-Dec-85 13:02:00 EST References: <974@brl-tgr.ARPA> Reply-To: jj@nrcvax.UUCP (Jeff Jennings - NRC-Utah) Organization: Network Research Research Corp. Oxnard,CA Lines: 23 In article <974@brl-tgr.ARPA> Schauble@mit-multics.arpa (Paul Schauble) writes: > >BTW, is >> defined to be a sign-extended shift or a zero extended shift >and under what circumstances. > > Paul > Schauble @ MIT-Multics The way that I interpreted this when generating machine code (68000) for a >> X was that if a was 'signed' (char, short, int, and long in our implementation) the compiler generated an arithmetic shift. If a was 'unsigned' (unsigned char, unsigned short, unsigned int, unsigned long), it generated a bitwise (logical?) shift. BTW, most C compilers I have seen do not fold the following constant expression correctly: ((unsigned long)0xFFFFFFFF) >> 1 /* or anything w/sign bit on */ Seems like the constant folding function in the compiler only does arithmetic shifts. ------------------------------------------------------------------------- Jeff Jennings Network Research Corp. ihnp4!nrcvax!nrcutah!jj 923 Executive Park Drive Suite C ucbvax!calma!nrcvax!nrcutah!jj Salt Lake City, Utah 84117, U.S.A. {sdcsvax,hplabs}!sdcrdcf!psivax!nrcvax!nrcutah!jj (801) 266-9194