system-verilog

Difference of SystemVerilog data types (reg, logic, bit)

女生的网名这么多〃 提交于 2019-11-28 06:54:35
There are different data types in systemverilog that can be used like the following: reg [31:0] data; logic [31:0] data; bit [31:0] data; How does the three of them differ? reg and wire were the original types. Wires are constantly assigned and regs are evaluated at particular points, the advantage here is for the simulator to make optimisations. wire w_data; assign w_data = y; // Same function as above using reg reg r_data; always @* r_data = y ; A common mistake when learning Verilog is to assume the a reg type implies a register in hardware. The earlier optimisation for the simulator can be

System Verilog parameters in generate block

不打扰是莪最后的温柔 提交于 2019-11-28 06:09:38
问题 I'd like to set a parameter based on a parameter which is set when the module is instantiated. I have the following. module foo #(WORDS = 8); parameter P00 = 33; logic [7:0] tmp; generate case (WORDS) 4: begin : A assign tmp = 8'haa; parameter P00 = 4; end 8: begin : B assign tmp = 8'hbb; parameter P00 = 8; end 16: begin : C assign tmp = 8'hcc; parameter P00 = 16; end default: begin : D assign tmp = 8'hdd; parameter P00 = 8; end endcase endgenerate initial begin $display ("WORDS = %d", WORDS)

packed vs unpacked vectors in system verilog

随声附和 提交于 2019-11-27 19:21:36
Looking at some code I'm maintaining in System Verilog I see some signals that are defined like this: node [range_hi:range_lo]x; and others that are defined like this: node y[range_hi:range_lo]; I understand that x is defined as packed, while y is defined as unpacked. However, I have no idea what that means. What is the difference between packed and unpacked vectors in System Verilog? Edit: Responding to @Empi's answer, why should a hardware designer who's writing in SV care about the internal representation of the array? Are there any times when I shouldn't or can't use packed signals? This

Incrementing Multiple Genvars in Verilog Generate Statement

徘徊边缘 提交于 2019-11-27 18:03:54
问题 I'm trying to create a multi-stage comparator in verilog and I can't figure out how to increment multiple genvars in a single generate loop. I'm trying the following: genvar i,j; //Level 1 generate j=0; for (i=0;i<128;i=i+1) begin: level1Comp assign ci1[i] = minw(tc[j],tc[j+1]); j = j+2; end endgenerate And getting the following error: Error-[SE] Syntax error Following verilog source has syntax error : "encoder.v", 322: token is '=' j=0; Anyone know how to increment multiple genvars in the

$size, $bits, verilog

て烟熏妆下的殇ゞ 提交于 2019-11-27 16:01:34
问题 What is the difference between $size and $bits operator in verilog.? if I've variables, [9:0]a , [6:0]b , [31:0]c . c <= [($size(a)+$size(b)-1]-:$bits(b)]; What will be the output at 'c' from the above expression? 回答1: $size shall return the number of elements in the dimension, which is equivalent to $high - $low + 1 . It is relative to the dimension, not only bit counts. If the type is 1D packed array or integral type, it is equal to $bits . $bits system function returns the number of bits

Difference of SystemVerilog data types (reg, logic, bit)

柔情痞子 提交于 2019-11-27 05:40:17
问题 There are different data types in systemverilog that can be used like the following: reg [31:0] data; logic [31:0] data; bit [31:0] data; How does the three of them differ? 回答1: reg and wire were the original types. Wires are constantly assigned and regs are evaluated at particular points, the advantage here is for the simulator to make optimisations. wire w_data; assign w_data = y; // Same function as above using reg reg r_data; always @* r_data = y ; A common mistake when learning Verilog

Verilog: How to instantiate a module

跟風遠走 提交于 2019-11-26 16:33:30
If I have a Verilog module 'top' and a verilog module 'subcomponent' how do I instantiate subcomponent in top? top: module top( input clk, input rst_n, input enable, input [9:0] data_rx_1, input [9:0] data_rx_2, output [9:0] data_tx_2 ); subcomponent: module subcomponent( input clk, input rst_n, input [9:0] data_rx, output [9:0] data_tx ); Note This was written as a generic question that keeps cropping up now and again, it is following the self-answer format. Addition answers and updates are encouraged. This is all generally covered by Section 23.3.2 of SystemVerilog IEEE Std 1800-2012 . The

What is `+:` and `-:`?

故事扮演 提交于 2019-11-26 12:30:06
I've recently saw this operator in a verilog/systemverilog code. logic [15:0] down_vect; logic [0:15] up_vect; down_vect[lsb_base_expr +: width_expr] up_vect [msb_base_expr +: width_expr] down_vect[msb_base_expr -: width_expr] up_vect [lsb_base_expr -: width_expr] I've rarely seen this so, I'd like to ask What is this, When and How do you use it? That particular syntax is called an indexed part select . It's very useful when you need to select a fixed number of bits from a variable offset within a multi-bit register. Here's an example of the syntax: reg [31:0] dword; reg [7:0] byte0; reg [7:0]

Verilog: How to instantiate a module

时间秒杀一切 提交于 2019-11-26 12:15:49
问题 If I have a Verilog module \'top\' and a verilog module \'subcomponent\' how do I instantiate subcomponent in top? top: module top( input clk, input rst_n, input enable, input [9:0] data_rx_1, input [9:0] data_rx_2, output [9:0] data_tx_2 ); subcomponent: module subcomponent( input clk, input rst_n, input [9:0] data_rx, output [9:0] data_tx ); Note This was written as a generic question that keeps cropping up now and again, it is following the self-answer format. Addition answers and updates

How to interpret blocking vs non blocking assignments in Verilog?

北城以北 提交于 2019-11-26 10:31:52
I am a little confused about how blocking and non blocking assignments are interpreted when it comes to drawing a hardware diagram. Do we have to infer that a non blocking assignment gives us a register? Then according to this statement c <= a+b , c would be a register right, but not a and b? module add (input logic clock, output logic[7:0] f); logic[7:0] a, b, c; always_ff @(posedge clock) begin a = b + c; b = c + a; c <= a + b; end assign f = c; endmodule Marty It's definitely a bit tricky to get your head around the differences between blocking and nonblocking assignments initially. But no