Created
March 26, 2018 06:46
-
-
Save yunsu3042/7316a07ec8398ecfd120097debc28ea3 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); | |
function Bit #(w) barrel_shift_right(Int #(k) n, Bit #(w) arg, Bit#(1) shiftValue); | |
Bit #(w) ans = 0; | |
for(Integer j = 0; j < (valueOf(w) - n); j = j + 1) | |
ans[j + n] = arg[j]; | |
for(Integer i = 0; i < n ; i = i + 1) | |
ans[i] = shiftValue; | |
return ans; | |
endfunction | |
method ActionValue#(Bit#(64)) rightShift(Bit#(64) val, Bit#(6) shiftAmt, Bit#(1) shiftValue); | |
/* TODO: Implement right barrel shifter using six multiplexer */ | |
let shiftedVal = val; | |
for(Integer i = 0; i < 6; i = i + 1) | |
Int#(32) shiftNum = fromInteger(2 ** i); | |
shiftedVal = barrel_shift_right(shiftNum, val, shiftValue); | |
val = multiplexer_n(shiftAmt[i], shiftedVal, val); | |
let result <- val; | |
return result; | |
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 result <- ?; | |
return 0; | |
endmethod | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment