Xref: utzoo comp.lang.fortran:430 comp.bugs.4bsd:697 Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!lll-tis!ames!nrl-cmf!cmcl2!rutgers!ucla-cs!pmontgom From: pmontgom@MATH.UCLA.EDU Newsgroups: comp.lang.fortran,comp.bugs.4bsd Subject: RSHIFT doesn't always sign extend Message-ID: <11219@shemp.UCLA.EDU> Date: 9 Feb 88 02:16:07 GMT Sender: root@CS.UCLA.EDU Reply-To: pmontgom@MATH.UCLA.EDU (Peter Montgomery) Organization: UCLA Mathematics Department Lines: 28 C The manual page BIT(3F) states "Rshift, or lshift C with a negative nbits, is an arithmetic right shift with C sign extension." Accordingly, both LSHIFT(-4, -2) and C RSHIFT(-4, 2) should return -1. Both do return -1 C when used with constant arguments. But when the C arguments to RSHIFT are variables, it does not do sign C extension (instead, it generates an extxv instruction). C C The following output was obtained on a VAX 750. C The "-v" option to f77 produces "Berkeley F77, C version 2.0 (4.3 bsd, SCCS level 6)." * Constant LSHIFT(-4, -2) = -1 * Variable LSHIFT(-4, -2) = -1 * Constant RSHIFT(-4, +2) = -1 * Variable RSHIFT(-4, +2) = 1073741823 program SHIFTS integer two, four data two/2/, four/4/ print * , 'Constant LSHIFT(-4, -2) = ', LSHIFT(-4, -2) print * , 'Variable LSHIFT(-4, -2) = ', LSHIFT(-four, -two) print * , 'Constant RSHIFT(-4, +2) = ', RSHIFT(-4, +2) print * , 'Variable RSHIFT(-4, +2) = ', RSHIFT(-four, +two) end -------- pmontgom@sdcrdcf.UUCP pmontgom@julia.MATH.UCLA.EDU