Skip to content

Commit

Permalink
Add Shifter
Browse files Browse the repository at this point in the history
  • Loading branch information
t2shashwat committed Feb 27, 2024
1 parent eba7653 commit c89ab13
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion part_1_combinational/Shifter.bsv
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c89ab13

Please sign in to comment.