From c89ab134fb0cbe3dc8da76b4744bf18c3a181f1c Mon Sep 17 00:00:00 2001 From: Shashwat Shrivastava Date: Tue, 27 Feb 2024 20:10:42 +0100 Subject: [PATCH] Add Shifter --- part_1_combinational/Shifter.bsv | 39 +++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/part_1_combinational/Shifter.bsv b/part_1_combinational/Shifter.bsv index b14cd38..e385869 100644 --- a/part_1_combinational/Shifter.bsv +++ b/part_1_combinational/Shifter.bsv @@ -13,6 +13,43 @@ endfunction function Vector#(16, Word) barrelLeft(Vector#(16, Word) in, Bit#(4) shftAmnt); - return unpack(0); + + Vector#(16, Word) resultVector = case (shftAmnt) matches + /*'b0000: in; + 'b0001: (unpack(pack(in) >> 1)); + 'b0010: (unpack(pack(in) >> 2*16)); + 'b0011: (unpack(pack(in) << 3)); + 'b0100: (unpack(pack(in) << 4)); + 'b0101: (unpack(pack(in) << 5)); + 'b0110: (unpack(pack(in) << 6)); + 'b0111: (unpack(pack(in) << 7)); + 'b1000: (unpack(pack(in) << 8)); + 'b1001: (unpack(pack(in) << 9)); + 'b1010: (unpack(pack(in) << 10)); + 'b1011: (unpack(pack(in) << 11)); + 'b1100: (unpack(pack(in) << 12)); + 'b1101: (unpack(pack(in) << 13)); + 'b1110: (unpack(pack(in) << 14)); + 'b1111: (unpack(pack(in) << 15));*/ + + 'b0000: in; + 'b0001: naiveShfl(in, 1); + 'b0010: naiveShfl(in, 2); + 'b0011: naiveShfl(in, 3); + 'b0100: naiveShfl(in, 4); + 'b0101: naiveShfl(in, 5); + 'b0110: naiveShfl(in, 6); + 'b0111: naiveShfl(in, 7); + 'b1000: naiveShfl(in, 8); + 'b1001: naiveShfl(in, 9); + 'b1010: naiveShfl(in, 10); + 'b1011: naiveShfl(in, 11); + 'b1100: naiveShfl(in, 12); + 'b1101: naiveShfl(in, 13); + 'b1110: naiveShfl(in, 14); + 'b1111: naiveShfl(in, 15); + + endcase; + return resultVector; // Implementation of a left barrel shifter endfunction