Skip to content

Instantly share code, notes, and snippets.

@houmei
Last active January 9, 2022 07:32
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
QuartusII 12.1 barrel shifter Example
module SHFTER(clk,GPIO1,GPIO2,GPIO3);
input clk;
input [63:0] GPIO1;
input [63:0] GPIO2;
output [63:0] GPIO3;
wire [63:0] indata;
wire [63:0] val;
wire [63:0] sftout;
reg [63:0] source;
reg [63:0] value;
reg [63:0] result;
assign indata=GPIO1;
assign val= GPIO2;
assign GPIO3=result;
/* BEGIN combinational */
// assign GPIO3=outdata;
// sll64 SLL(indata,val,outdata);
// sll32 SLL(indata,val,outdata);
// sll16 SLL(indata,val,outdata);
// sll8 SLL(indata,val,outdata);
// sll4 SLL(indata,val,outdata);
/* END combinational */
// sll64lt SLL(source,value,sftout);
// sll48lt SLL(source,value,sftout);
// sll32lt SLL(source,value,sftout);
// sll24lt SLL(source,value,sftout);
// sll16lt SLL(source,value,sftout);
// sll8lt SLL(source,value,sftout);
// sll4lt SLL(source,value,sftout);
// sll64 SLL(source,value,sftout);
// sll48 SLL(source,value,sftout);
// sll32 SLL(source,value,sftout);
// sll24 SLL(source,value,sftout);
// sll16 SLL(source,value,sftout);
// sll8 SLL(source,value,sftout);
sll4 SLL(source,value,sftout);
always @(posedge clk) begin
source<=indata;
value<=val;
result<=sftout;
end
// sll64(indata,val,outdata);
// sll32(indata,val,outdata);
// sll16(indata,val,outdata);
// sll8(indata,val,outdata);
// sll4(indata,val,outdata);
endmodule
module sll4(indata,val,outdata);
input [3:0] indata;
input [3:0] val;
output [3:0] outdata;
function [3:0] shifterL;
input [3:0] in;
input [3:0] sv;
begin
case (sv)
4'b000: shifterL=in[3:0];
4'b001: shifterL={in[3:1],1'b0};
4'b010: shifterL={in[3:2],2'b00};
4'b011: shifterL={in[3:3],3'b000};
default: shifterL=4'b0000;
endcase
end
endfunction
assign outdata=shifterL(indata,val);
endmodule
module sll64(indata,val,outdata);
input [63:0] indata;
input [63:0] val;
output [63:0] outdata;
function [63:0] shifterL;
input [63:0] in;
input [63:0] sv;
begin
case (sv)
64'b000000: shifterL=in[63:0];
64'b000001: shifterL={in[63:1],1'b0};
64'b000010: shifterL={in[63:2],2'b00};
64'b000011: shifterL={in[63:3],3'b000};
64'b000100: shifterL={in[63:4],4'b0000};
64'b000101: shifterL={in[63:5],5'b00000};
64'b000110: shifterL={in[63:6],6'b000000};
64'b000111: shifterL={in[63:7],7'b0000000};
64'b001000: shifterL={in[63:8],8'b00000000};
64'b001001: shifterL={in[63:9],9'b000000000};
64'b001010: shifterL={in[63:10],10'b0000000000};
64'b001011: shifterL={in[63:11],11'b00000000000};
64'b001100: shifterL={in[63:12],12'b000000000000};
64'b001101: shifterL={in[63:13],13'b0000000000000};
64'b001110: shifterL={in[63:14],14'b00000000000000};
64'b001111: shifterL={in[63:15],15'b000000000000000};
64'b010000: shifterL={in[63:16],16'b0000000000000000};
64'b010001: shifterL={in[63:17],17'b00000000000000000};
64'b010010: shifterL={in[63:18],18'b000000000000000000};
64'b010011: shifterL={in[63:19],19'b0000000000000000000};
64'b010100: shifterL={in[63:20],20'b00000000000000000000};
64'b010101: shifterL={in[63:21],21'b000000000000000000000};
64'b010110: shifterL={in[63:22],22'b0000000000000000000000};
64'b010111: shifterL={in[63:23],23'b00000000000000000000000};
64'b011000: shifterL={in[63:24],24'b000000000000000000000000};
64'b011001: shifterL={in[63:25],25'b0000000000000000000000000};
64'b011010: shifterL={in[63:26],26'b00000000000000000000000000};
64'b011011: shifterL={in[63:27],27'b000000000000000000000000000};
64'b011100: shifterL={in[63:28],28'b0000000000000000000000000000};
64'b011101: shifterL={in[63:29],29'b00000000000000000000000000000};
64'b011110: shifterL={in[63:30],30'b000000000000000000000000000000};
64'b011111: shifterL={in[63:31],31'b0000000000000000000000000000000};
64'b100000: shifterL={in[63:32],32'b00000000000000000000000000000000};
64'b100001: shifterL={in[63:33],33'b000000000000000000000000000000000};
64'b100010: shifterL={in[63:34],34'b0000000000000000000000000000000000};
64'b100011: shifterL={in[63:35],35'b00000000000000000000000000000000000};
64'b100100: shifterL={in[63:36],36'b000000000000000000000000000000000000};
64'b100101: shifterL={in[63:37],37'b0000000000000000000000000000000000000};
64'b100110: shifterL={in[63:38],38'b00000000000000000000000000000000000000};
64'b100111: shifterL={in[63:39],39'b000000000000000000000000000000000000000};
64'b101000: shifterL={in[63:40],40'b0000000000000000000000000000000000000000};
64'b101001: shifterL={in[63:41],41'b00000000000000000000000000000000000000000};
64'b101010: shifterL={in[63:42],42'b000000000000000000000000000000000000000000};
64'b101011: shifterL={in[63:43],43'b0000000000000000000000000000000000000000000};
64'b101100: shifterL={in[63:44],44'b00000000000000000000000000000000000000000000};
64'b101101: shifterL={in[63:45],45'b000000000000000000000000000000000000000000000};
64'b101110: shifterL={in[63:46],46'b0000000000000000000000000000000000000000000000};
64'b101111: shifterL={in[63:47],47'b00000000000000000000000000000000000000000000000};
64'b110000: shifterL={in[63:48],48'b000000000000000000000000000000000000000000000000};
64'b110001: shifterL={in[63:49],49'b0000000000000000000000000000000000000000000000000};
64'b110010: shifterL={in[63:50],50'b00000000000000000000000000000000000000000000000000};
64'b110011: shifterL={in[63:51],51'b000000000000000000000000000000000000000000000000000};
64'b110100: shifterL={in[63:52],52'b0000000000000000000000000000000000000000000000000000};
64'b110101: shifterL={in[63:53],53'b00000000000000000000000000000000000000000000000000000};
64'b110110: shifterL={in[63:54],54'b000000000000000000000000000000000000000000000000000000};
64'b110111: shifterL={in[63:55],55'b0000000000000000000000000000000000000000000000000000000};
64'b111000: shifterL={in[63:56],56'b00000000000000000000000000000000000000000000000000000000};
64'b111001: shifterL={in[63:57],57'b000000000000000000000000000000000000000000000000000000000};
64'b111010: shifterL={in[63:58],58'b0000000000000000000000000000000000000000000000000000000000};
64'b111011: shifterL={in[63:59],59'b00000000000000000000000000000000000000000000000000000000000};
64'b111100: shifterL={in[63:60],60'b000000000000000000000000000000000000000000000000000000000000};
64'b111101: shifterL={in[63:61],61'b0000000000000000000000000000000000000000000000000000000000000};
64'b111110: shifterL={in[63:62],62'b00000000000000000000000000000000000000000000000000000000000000};
64'b111111: shifterL={in[63:63],63'b0000000000000000000000000000000000000000000000000000000000000000};
default : shifterL= 64'b0000000000000000000000000000000000000000000000000000000000000000;
endcase
end
endfunction
assign outdata=shifterL(indata,val);
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment