Skip to content

Instantly share code, notes, and snippets.

@houmei
Created May 5, 2013 22:13
  • Star 0 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 BarrelShifter comparison
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 */
sllp #(63) SLL(source,value,sftout);
// 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 sll16(indata,val,outdata);
input [15:0] indata;
input [15:0] val;
output [15:0] outdata;
function [15:0] shifterL;
input [15:0] in;
input [15:0] sv;
begin
case (sv)
16'b0000: shifterL=in[15:0];
16'b0001: shifterL={in[15:1],1'b0};
16'b0010: shifterL={in[15:2],2'b00};
16'b0011: shifterL={in[15:3],3'b000};
16'b0100: shifterL={in[15:4],4'b0000};
16'b0101: shifterL={in[15:5],5'b00000};
16'b0110: shifterL={in[15:6],6'b000000};
16'b0111: shifterL={in[15:7],7'b0000000};
16'b1000: shifterL={in[15:8],8'b00000000};
16'b1001: shifterL={in[15:9],9'b000000000};
16'b1010: shifterL={in[15:10],10'b0000000000};
16'b1011: shifterL={in[15:11],11'b00000000000};
16'b1100: shifterL={in[15:12],12'b000000000000};
16'b1101: shifterL={in[15:13],13'b0000000000000};
16'b1110: shifterL={in[15:14],14'b00000000000000};
16'b1111: shifterL={in[15:15],15'b000000000000000};
default : shifterL=16'b0000000000000000;
endcase
end
endfunction
assign outdata=shifterL(indata,val);
endmodule
module sll16lt(indata,val,outdata);
input [15:0] indata;
input [15:0] val;
output [15:0] outdata;
assign outdata=indata<<val;
endmodule
module sll24(indata,val,outdata);
input [23:0] indata;
input [23:0] val;
output [23:0] outdata;
function [23:0] shifterL;
input [23:0] in;
input [23:0] sv;
begin
case (sv)
24'b000000: shifterL=in[23:0];
24'b000001: shifterL={in[23:1],1'b0};
24'b000010: shifterL={in[23:2],2'b00};
24'b000011: shifterL={in[23:3],3'b000};
24'b000100: shifterL={in[23:4],4'b0000};
24'b000101: shifterL={in[23:5],5'b00000};
24'b000110: shifterL={in[23:6],6'b000000};
24'b000111: shifterL={in[23:7],7'b0000000};
24'b001000: shifterL={in[23:8],8'b00000000};
24'b001001: shifterL={in[23:9],9'b000000000};
24'b001010: shifterL={in[23:10],10'b0000000000};
24'b001011: shifterL={in[23:11],11'b00000000000};
24'b001100: shifterL={in[23:12],12'b000000000000};
24'b001101: shifterL={in[23:13],13'b0000000000000};
24'b001110: shifterL={in[23:14],14'b00000000000000};
24'b001111: shifterL={in[23:15],15'b000000000000000};
24'b010000: shifterL={in[23:16],16'b0000000000000000};
24'b010001: shifterL={in[23:17],17'b00000000000000000};
24'b010010: shifterL={in[23:18],18'b000000000000000000};
24'b010011: shifterL={in[23:19],19'b0000000000000000000};
24'b010100: shifterL={in[23:20],20'b00000000000000000000};
24'b010101: shifterL={in[23:21],21'b000000000000000000000};
24'b010110: shifterL={in[23:22],22'b0000000000000000000000};
24'b010111: shifterL={in[23:23],23'b00000000000000000000000};
default : shifterL= 23'b000000000000000000000000000000000000000000000000;
endcase
end
endfunction
assign outdata=shifterL(indata,val);
endmodule
module sll24lt(indata,val,outdata);
input [23:0] indata;
input [23:0] val;
output [23:0] outdata;
assign outdata=indata<<val;
endmodule
module sll32(indata,val,outdata);
input [31:0] indata;
input [31:0] val;
output [31:0] outdata;
function [31:0] shifterL;
input [31:0] in;
input [31:0] sv;
begin
case (sv)
32'b00000: shifterL=in[31:0];
32'b00001: shifterL={in[31:1],1'b0};
32'b00010: shifterL={in[31:2],2'b00};
32'b00011: shifterL={in[31:3],3'b000};
32'b00100: shifterL={in[31:4],4'b0000};
32'b00101: shifterL={in[31:5],5'b00000};
32'b00110: shifterL={in[31:6],6'b000000};
32'b00111: shifterL={in[31:7],7'b0000000};
32'b01000: shifterL={in[31:8],8'b00000000};
32'b01001: shifterL={in[31:9],9'b000000000};
32'b01010: shifterL={in[31:10],10'b0000000000};
32'b01011: shifterL={in[31:11],11'b00000000000};
32'b01100: shifterL={in[31:12],12'b000000000000};
32'b01101: shifterL={in[31:13],13'b0000000000000};
32'b01110: shifterL={in[31:14],14'b00000000000000};
32'b01111: shifterL={in[31:15],15'b000000000000000};
32'b10000: shifterL={in[31:16],16'b0000000000000000};
32'b10001: shifterL={in[31:17],17'b00000000000000000};
32'b10010: shifterL={in[31:18],18'b000000000000000000};
32'b10011: shifterL={in[31:19],19'b0000000000000000000};
32'b10100: shifterL={in[31:20],20'b00000000000000000000};
32'b10101: shifterL={in[31:21],21'b000000000000000000000};
32'b10110: shifterL={in[31:22],22'b0000000000000000000000};
32'b10111: shifterL={in[31:23],23'b00000000000000000000000};
32'b11000: shifterL={in[31:24],24'b000000000000000000000000};
32'b11001: shifterL={in[31:25],25'b0000000000000000000000000};
32'b11010: shifterL={in[31:26],26'b00000000000000000000000000};
32'b11011: shifterL={in[31:27],27'b000000000000000000000000000};
32'b11100: shifterL={in[31:28],28'b0000000000000000000000000000};
32'b11101: shifterL={in[31:29],29'b00000000000000000000000000000};
32'b11110: shifterL={in[31:30],30'b000000000000000000000000000000};
32'b11111: shifterL={in[31:31],31'b0000000000000000000000000000000};
default : shifterL=32'b00000000000000000000000000000000;
endcase
end
endfunction
assign outdata=shifterL(indata,val);
endmodule
module sll32lt(indata,val,outdata);
input [31:0] indata;
input [31:0] val;
output [31:0] outdata;
assign outdata=indata<<val;
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 sll48(indata,val,outdata);
input [47:0] indata;
input [47:0] val;
output [47:0] outdata;
function [47:0] shifterL;
input [47:0] in;
input [47:0] sv;
begin
case (sv)
48'b000000: shifterL=in[47:0];
48'b000001: shifterL={in[47:1],1'b0};
48'b000010: shifterL={in[47:2],2'b00};
48'b000011: shifterL={in[47:3],3'b000};
48'b000100: shifterL={in[47:4],4'b0000};
48'b000101: shifterL={in[47:5],5'b00000};
48'b000110: shifterL={in[47:6],6'b000000};
48'b000111: shifterL={in[47:7],7'b0000000};
48'b001000: shifterL={in[47:8],8'b00000000};
48'b001001: shifterL={in[47:9],9'b000000000};
48'b001010: shifterL={in[47:10],10'b0000000000};
48'b001011: shifterL={in[47:11],11'b00000000000};
48'b001100: shifterL={in[47:12],12'b000000000000};
48'b001101: shifterL={in[47:13],13'b0000000000000};
48'b001110: shifterL={in[47:14],14'b00000000000000};
48'b001111: shifterL={in[47:15],15'b000000000000000};
48'b010000: shifterL={in[47:16],16'b0000000000000000};
48'b010001: shifterL={in[47:17],17'b00000000000000000};
48'b010010: shifterL={in[47:18],18'b000000000000000000};
48'b010011: shifterL={in[47:19],19'b0000000000000000000};
48'b010100: shifterL={in[47:20],20'b00000000000000000000};
48'b010101: shifterL={in[47:21],21'b000000000000000000000};
48'b010110: shifterL={in[47:22],22'b0000000000000000000000};
48'b010111: shifterL={in[47:23],23'b00000000000000000000000};
48'b011000: shifterL={in[47:24],24'b000000000000000000000000};
48'b011001: shifterL={in[47:25],25'b0000000000000000000000000};
48'b011010: shifterL={in[47:26],26'b00000000000000000000000000};
48'b011011: shifterL={in[47:27],27'b000000000000000000000000000};
48'b011100: shifterL={in[47:28],28'b0000000000000000000000000000};
48'b011101: shifterL={in[47:29],29'b00000000000000000000000000000};
48'b011110: shifterL={in[47:30],30'b000000000000000000000000000000};
48'b011111: shifterL={in[47:31],31'b0000000000000000000000000000000};
48'b100000: shifterL={in[47:32],32'b00000000000000000000000000000000};
48'b100001: shifterL={in[47:33],33'b000000000000000000000000000000000};
48'b100010: shifterL={in[47:34],34'b0000000000000000000000000000000000};
48'b100011: shifterL={in[47:35],35'b00000000000000000000000000000000000};
48'b100100: shifterL={in[47:36],36'b000000000000000000000000000000000000};
48'b100101: shifterL={in[47:37],37'b0000000000000000000000000000000000000};
48'b100110: shifterL={in[47:38],38'b00000000000000000000000000000000000000};
48'b100111: shifterL={in[47:39],39'b000000000000000000000000000000000000000};
48'b101000: shifterL={in[47:40],40'b0000000000000000000000000000000000000000};
48'b101001: shifterL={in[47:41],41'b00000000000000000000000000000000000000000};
48'b101010: shifterL={in[47:42],42'b000000000000000000000000000000000000000000};
48'b101011: shifterL={in[47:43],43'b0000000000000000000000000000000000000000000};
48'b101100: shifterL={in[47:44],44'b00000000000000000000000000000000000000000000};
48'b101101: shifterL={in[47:45],45'b000000000000000000000000000000000000000000000};
48'b101110: shifterL={in[47:46],46'b0000000000000000000000000000000000000000000000};
48'b101111: shifterL={in[47:47],47'b00000000000000000000000000000000000000000000000};
default : shifterL= 48'b000000000000000000000000000000000000000000000000;
endcase
end
endfunction
assign outdata=shifterL(indata,val);
endmodule
module sll48lt(indata,val,outdata);
input [47:0] indata;
input [47:0] val;
output [47:0] outdata;
assign outdata=indata<<val;
endmodule
module sll4lt(indata,val,outdata);
input [3:0] indata;
input [3:0] val;
output [3:0] outdata;
assign outdata=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
module sll64lt(indata,val,outdata);
input [63:0] indata;
input [63:0] val;
output [63:0] outdata;
assign outdata=indata<<val;
endmodule
module sll8(indata,val,outdata);
input [7:0] indata;
input [7:0] val;
output [7:0] outdata;
function [7:0] shifterL;
input [7:0] in;
input [7:0] sv;
begin
case (sv)
8'b000: shifterL=in[7:0];
8'b001: shifterL={in[7:1],1'b0};
8'b010: shifterL={in[7:2],2'b00};
8'b011: shifterL={in[7:3],3'b000};
8'b100: shifterL={in[7:4],4'b0000};
8'b101: shifterL={in[7:5],5'b00000};
8'b110: shifterL={in[7:6],6'b000000};
8'b111: shifterL={in[7],7'b0000000};
default: shifterL=8'b00000000;
endcase
end
endfunction
assign outdata=shifterL(indata,val);
endmodule
module sll8lt(indata,val,outdata);
input [7:0] indata;
input [7:0] val;
output [7:0] outdata;
assign outdata=indata<<val;
endmodule
module sllp(indata,val,outdata);
parameter sllp_MAXSHIFT=63; // default [63:0]
input [sllp_MAXSHIFT:0] indata;
input [sllp_MAXSHIFT:0] val;
output [sllp_MAXSHIFT:0] outdata;
assign outdata=indata<<val;
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment