module univ_barrel8(
input [7:0]x,
input [2:0]sh,mode,
output reg [7:0]y
);
always@(*)begin
case(mode)
3'b000 : y <= x; //passing value
3'b001 : y <= x << sh; //Logical left
3'b010 : y <= x >> sh; //Logical right
3'b011 : y <= $signed(x) >>> sh; //arithmetic right,sign-extend
3'b100 : y <= ({x,x}<<sh) >> 8; //Rotate left
3'b101 : y <= ({x,x}>>sh) & 8'hFF; //Rotate right
3'b110,3'b111: y = x; //Reserved
default: y = x;
endcase
end
endmodule