0% found this document useful (0 votes)
7 views11 pages

10 Advancedverilog PDF

The document describes various Verilog synthesis optimizations including: 1) Using a generate statement to implement an adder with multiple fullAdder modules. 2) Implementing if/else and case statements to synthesize complex logic functions. 3) Using always_ff blocks with posedge clocks to implement sequential logic like counters and state machines.

Uploaded by

ramsampath78
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

10 Advancedverilog PDF

The document describes various Verilog synthesis optimizations including: 1) Using a generate statement to implement an adder with multiple fullAdder modules. 2) Implementing if/else and case statements to synthesize complex logic functions. 3) Using always_ff blocks with posedge clocks to implement sequential logic like counters and state machines.

Uploaded by

ramsampath78
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Advanced Verilog – Synthesis Optimizations

module incrementer(out, in);


output logic [2:0] out;
input logic [2:0] in;

adder #(.WIDTH(3)) a
(.sum(out), .overflow( ), .a(in), .b(3'b000), .cin(1'b1));

endmodule

a[2] a[1] a[0]

b[2] b[1] b[0]

sum[2] sum[1] sum[0]


cin

overflow

205
Advanced Verilog – Generate Statements
module adder #(parameter WIDTH=1) (sum, overflow, a, b, cin);
output logic [WIDTH-1:0] sum;
output logic overflow;
input logic [WIDTH-1:0] a, b;
input logic cin;

logic [WIDTH:0] carries;

genvar i;
generate
for(i=0; i<WIDTH; i++) begin : subAdders
fullAdder fa(.sum(sum[i]), .cout(carries[i+1]),
.cin(carries[i]), .a(a[i]), .b(b[i]));
end
endgenerate

assign carries[0] = cin;


assign overflow = carries[WIDTH] ^ carries[WIDTH-1];
endmodule
206
Advanced Verilog – “If” Synthesis
logic [1:0] a, b, c;

always_comb begin
if (a == 2'b01)
b = c;
else
b = a;
end

207
Advanced Verilog – Complex “If” Synthesis
logic [1:0] a, b, c;

always_comb begin
if (a == 2'b01)
b = c;
else
c = a + b;
end

208
Advanced Verilog – “Case” Synthesis
input w;

parameter [1:0] A = 2'b00, B = 2'b01, C = 2'b10;


logic [1:0] ns, ps;

// Next State Logic


always_comb begin
case (ps)

A: if (w) ns = B;
else ns = A;
B: if (w) ns = C;
else ns = A;
C: if (w) ns = C;
else ns = A;

endcase
end

209
Advanced Verilog – “Posedge” Statements
logic [1:0] ps, ns;
parameter [1:0] Start = 2'b01;

always_ff @(posedge clk) begin


if (reset)
ps <= Start;
else
ps <= ns;
end

210
Advanced Verilog - Counters
logic [3:0] out;

always_ff @(posedge clk) begin


if (reset)
out <= 4'b0000;
else if (incr)
out <= out + 4'b0001;
end

211
Advanced Verilog – Histogram
logic [1:0] inVal;
logic [3:0] count00, count01, count10, count11;

always_ff @(posedge clk) begin


case (inVal)
2'b00: count00 <= count00 + 4'b0001;
2'b01: count01 <= count01 + 4'b0001;
2'b10: count10 <= count10 + 4'b0001;
2'b11: count11 <= count11 + 4'b0001;
endcase
end

212
Advanced Verilog – Less Than
logic [3:0] a, b;

always_comb begin
lessThan = (a<b);
end

213
Advanced Verilog – Sequential Statements
input logic [2:0] i0, i1;
output logic [2:0] o0, o1;

always_comb begin
o0 = i0;
o1 = i1;
if (o1 < o0) begin
o1 = i0;
o0 = i1;
end
end

214
Advanced Verilog – For Loops
output logic [1:0] result;
input logic [1:0] vals [3:0];
integer i;

always_comb begin
result = vals[0];
for(i=1; i<4; i++)
if (vals[i] != 2'b00)
result = vals[i];
end

215

You might also like