[comp.bugs.4bsd] RSHIFT doesn't always sign extend

pmontgom@MATH.UCLA.EDU (02/09/88)

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