In article <45***************@yahoo.com>
CBFalconer <cb********@maineline.netwrote:
>[OT] At the machine level, by giving meaning to negative shift
counts, you can implement a complete set of shifts with only two
instructions: ArithShift and LogicalShift. Two more are needed to
implement rotations. Double the count if you also need to
implement "through carry". One actual shift instruction with a 3
bit detail field will do it all.
[/OT]
There is a much better way to do the whole thing, using an
extra argument. Consider the following ASCII-art diagram of
an 8-bit "shifter" (larger variants are obvious, but harder to
draw :-) ):
val1 val2
ABCDEFGH ijklmnop
\\\ /////
\\\ /////
||||||||
FGHijklm
result
If val1==0, bits A-H are all-zeros, and this computes val2 >3,
with val2 unsigned ("logical" shift).
If val1==-1, bits A-H are all-ones, and this computes val2 >3,
with val2 signed and its sign bit set ("arithmetic" shift).
If val2==0, bits i-p are all-zeros, and this computes val1 << 5.
If val1==val2, bits F-H are the same as bits n-p, and this computes
(val1 rotateleft 5) or, equivalently, (val2 rotateright 3).
If neither val1 nor val2 is all-zeros or all-ones, and not equal to
each other, this extracts an 8-bit sub-field from two 8-bit values.
The diagram above is of a "funnel shifter", which has three inputs
and one output. The inputs are two values (of some bit-size), and
a bit-index in the range [0..N-1], where N is the number of bits
in the values. (The instruction-set designer must decide whether
the "count" above is 3 or 5; either is OK.)
Note that a single 64-bit funnel shifter can implement 8, 16, or
32-bit shifts and rotates; you just have to arrange for the bits
to be shifted-or-rotated to be in the uppermost and lowermost bits
of the two "value" inputs, then choose the shift count correctly.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.