RSHIFT doesn't always sign extend
pmontgom at MATH.UCLA.EDU
pmontgom at MATH.UCLA.EDU
Tue Feb 9 12:16:07 AEST 1988
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 at sdcrdcf.UUCP
pmontgom at julia.MATH.UCLA.EDU
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list