SpinalHDL
1 / 1
Description
Barrel Shifter
Design a hardware module for the Barrel Shifter problem.
Given a 32-bit unsigned value data, shift or rotate it by shift_amount bits.
- if
direction = 1, operate to the left - if
direction = 0, operate to the right - if
rotate = 1, bits that leave one side wrap around to the other side - if
rotate = 0, emptied bit positions are filled with zeros
Hardware I/O Encoding
datais a scalar unsigned 32-bit integershift_amountis a scalar unsigned 5-bit integer in the range0..31directionis a scalar unsigned 1-bit integerrotateis a scalar unsigned 1-bit integer- the output is one unsigned 32-bit integer
Examples
Example 1
- input
data = 177,shift_amount = 3,direction = 1,rotate = 0 - output:
1416
This is a left shift by 3 bits.
Example 2
- input
data = 13,shift_amount = 1,direction = 0,rotate = 1 - output:
2147483654
This rotates 0b...1101 right by one bit.
Input
data
32-bit Unsigned IntegerData to shift.
shift_amount
5-bit Unsigned IntegerShift amount (0-31).
direction
1-bit Unsigned Integer0=right, 1=left.
rotate
1-bit Unsigned Integer0=shift, 1=rotate.
Output
32-bit Unsigned Integer
Shifted result.