Created
March 26, 2018 10:55
-
-
Save yunsu3042/f348d7a548521696b5ba06cb01449e3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Multiplexer::*; | |
interface BarrelShifterRight; | |
method ActionValue#(Bit#(64)) rightShift(Bit#(64) val, Bit#(6) shiftAmt, Bit#(1) shiftValue); | |
endinterface | |
module mkBarrelShifterRight(BarrelShifterRight); | |
method ActionValue#(Bit#(64)) rightShift(Bit#(64) val, Bit#(6) shiftAmt, Bit#(1) shiftValue); | |
/* TODO: Implement right barrel shifter using six multiplexer */ | |
Bit#(64) shiftedVal; | |
for(Integer i = 0; i < 6; i = i + 1) | |
begin | |
for(Integer j = 0; j < 64 - 2 ** i; j = j + 1) | |
begin | |
shiftedVal[j] = val[j + 2 ** i]; | |
end | |
for(Integer j = 0; j < 2 ** i; j = j + 1) | |
begin | |
shiftedVal[63 - j] = shiftValue; | |
end | |
val = multiplexer_n(shiftAmt[i], val, shiftedVal); | |
end | |
return val; | |
endmethod | |
endmodule | |
interface BarrelShifterRightLogical; | |
method ActionValue#(Bit#(64)) rightShift(Bit#(64) val, Bit#(6) shiftAmt); | |
endinterface | |
module mkBarrelShifterRightLogical(BarrelShifterRightLogical); | |
let bsr <- mkBarrelShifterRight; | |
method ActionValue#(Bit#(64)) rightShift(Bit#(64) val, Bit#(6) shiftAmt); | |
/* TODO: Implement logical right shifter using the right shifter */ | |
let ans = bsr.rightShift(val, shiftAmt, 0); | |
let result <- ans; | |
return result; | |
endmethod | |
endmodule | |
typedef BarrelShifterRightLogical BarrelShifterRightArithmetic; | |
module mkBarrelShifterRightArithmetic(BarrelShifterRightArithmetic); | |
let bsr <- mkBarrelShifterRight; | |
method ActionValue#(Bit#(64)) rightShift(Bit#(64) val, Bit#(6) shiftAmt); | |
/* TODO: Implement arithmetic right shifter using the right shifter */ | |
let ans = bsr.rightShift(val, shiftAmt, val[63]); | |
let result <- ans; | |
return result; | |
endmethod | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment