Commit d95a5628 by Zachary Snow

split out basic suite tests with refs to new core suite

parent bb938f1e
module top;
wire [2:0] test;
assign test = 3'd0;
initial $display(test);
endmodule
package foo_pkg;
typedef enum logic [2:0] {
AccessAck = 3'd0,
AccessAckData = 3'd1
} inp_t;
endpackage
module top;
import foo_pkg::*;
wire [2:0] test;
always_comb begin
case (test)
AccessAck: $display("Ack");
default : $display("default");
endcase
end
endmodule
package P;
localparam X = 1;
endpackage
package Q;
import P::X;
export P::*;
localparam Y = 2;
endpackage
package R;
import Q::X;
export Q::*;
localparam Z = 3;
endpackage
package S;
import P::X;
import Q::Y;
import R::Z;
export *::*;
endpackage
module top;
import S::*;
initial $display(X, Y, Z);
endmodule
package P;
function automatic logic [7:0] f(input logic [2:0] p);
logic [7:0] r;
localparam T = $bits(r[7:0]);
r = T'(1'sb0);
r[p+:2] = $bits(r[p+:2])'(1'sb1);
return r;
endfunction
endpackage
module top;
logic [2:0] p;
logic [7:0] q;
assign q = P::f(p);
initial begin
$monitor("%0d, p=%b q=%b", $time, p, q);
#1 p = 0;
while (p != 7)
#1 p = p + 1;
end
endmodule
module top;
function automatic [7:0] f;
input [2:0] p;
begin
f = 7'b0;
f[p+:2] = 2'b11;
end
endfunction
reg [2:0] p;
wire [7:0] q;
assign q = f(p);
initial begin
$monitor("%0d, p=%b q=%b", $time, p, q);
#1 p = 0;
while (p != 7)
#1 p = p + 1;
end
endmodule
package PkgA;
localparam X = 1;
localparam Y = 2;
endpackage
package PkgB;
localparam X = 3;
localparam Z = 4;
endpackage
import PkgA::*;
import PkgB::*;
localparam X = 5;
module top;
initial $display(X, Y, Z);
endmodule
module top;
localparam X = 5;
localparam Y = 2;
localparam Z = 4;
initial $display(X, Y, Z);
endmodule
module top;
localparam P_X = 10;
localparam Y = P_X;
initial $display(Y);
endmodule
package evil_pkg;
localparam Z = 1;
localparam A = Z;
localparam B = Z;
function logic evil_fun;
return A;
endfunction
endpackage
module evil_mdl (
output logic [evil_pkg::B-1:0] foo
);
initial foo = evil_pkg::evil_fun();
endmodule
module top;
logic [evil_pkg::B-1:0] foo;
evil_mdl x(foo);
initial $monitor(foo);
endmodule
module evil_mdl (
output reg [evil_pkg_B-1:0] foo
);
localparam evil_pkg_Z = 1;
localparam evil_pkg_A = evil_pkg_Z;
localparam evil_pkg_B = evil_pkg_Z;
initial foo = evil_pkg_A;
endmodule
module top;
localparam evil_pkg_Z = 1;
localparam evil_pkg_A = evil_pkg_Z;
localparam evil_pkg_B = evil_pkg_Z;
wire [evil_pkg_B-1:0] foo;
evil_mdl x(foo);
initial $monitor(foo);
endmodule
module top;
Example e1();
Example #(8) e2();
Example #(9) e3();
endmodule
package PKG;
typedef struct packed {
logic f;
} foo_t;
endpackage
module top;
typedef struct packed {
PKG::foo_t f;
} local_t;
local_t w[0:1];
initial begin
w <= '{default: 0};
$display("%b", w);
end
endmodule
module top;
initial begin
$display("A 3");
$display("B 3");
$display("C 1");
$display("D 2");
$display("E 2");
$display("F 2");
// G doesn't print
$display("H 1");
$display("I 1");
$display("J 1");
$display("K1 1");
$display("K2 2");
$display("K3 3");
$display("K4 2");
$display("K0 1");
$display("L 1");
$display("M1 1");
$display("M2 1");
$display("M3 1");
$display("M4 1");
$display("W::help() 1");
$display("W::help() 1");
$display("N1 1");
$display("N2 2");
$display("O1 1");
$display("O2 2");
end
endmodule
module top;
localparam Foo = 1;
initial $display(Foo);
endmodule
module top;
localparam Foo = 1;
initial $display(Foo);
endmodule
package P;
localparam Bar = 1;
function automatic integer func;
localparam Bar = 2;
func = Bar + P::Bar;
endfunction
endpackage
module top;
import P::*;
initial $display(func());
endmodule
module top;
localparam Foo = 1;
localparam Bar = 2;
initial $display(Foo + Bar);
endmodule
package P;
localparam X = 10;
localparam Y = X + 1;
function integer flip;
input integer X;
return ~X;
endfunction
endpackage
package Q;
import P::*;
localparam Y = X + 1000;
endpackage
package R;
import Q::*;
export Q::Y;
endpackage
package S;
typedef enum logic { A, B } enum_t;
function enum_t flop;
input enum_t X;
if (X == A) return B;
else return A;
endfunction
endpackage
module top;
import P::*;
localparam X = 20;
localparam Z = Y + 1;
import S::flop;
typedef enum logic [3:0] { T = 3, U } enum_t;
initial begin
$display("X %0d", X);
$display("P::Y %0d", P::Y);
$display("Z %0d", Z);
$display("R::Y %0d", R::Y);
$display("flip(0) %0d", flip(0));
$display("T %b", T);
$display("U %b", U);
$display("flop(0) %b", flop(0));
$display("flop(1) %b", flop(1));
end
endmodule
module top;
localparam P_X = 10;
localparam P_Y = P_X + 1;
localparam X = 20;
localparam Z = P_Y + 1;
localparam R_Y = P_X + 1000;
localparam Q_Y = R_Y;
localparam [3:0] T = 3;
localparam [3:0] U = 4;
function integer flip;
input integer inp;
flip = ~inp;
endfunction
function flop;
input inp;
flop = ~inp;
endfunction
initial begin
$display("X %0d", X);
$display("P::Y %0d", P_Y);
$display("Z %0d", Z);
$display("R::Y %0d", Q_Y);
$display("flip(0) %0d", flip(0));
$display("T %b", T);
$display("U %b", U);
$display("flop(0) %b", flop(0));
$display("flop(1) %b", flop(1));
end
endmodule
package top_pkg;
localparam AW = 16;
endpackage
package foo_pkg;
typedef struct packed {
logic valid;
logic value;
} mask_t;
typedef struct packed {
logic valid;
logic [top_pkg::AW-1:0] user;
mask_t mask;
} boo_t;
endpackage
module top;
foo_pkg::boo_t foo;
assign foo = 19'b110_01001000_01110100;
wire [7:0] bar;
parameter FLAG = 1;
assign bar = FLAG ? foo.user[0+:8] : '1;
endmodule
module top;
localparam AW = 16;
wire [AW+2:0] foo;
assign foo = 19'b110_01001000_01110100;
wire [7:0] bar;
parameter FLAG = 1;
assign bar = FLAG ? foo[2+:8] : 8'hFF;
endmodule
package foo_pkg;
typedef struct packed {
logic [7:0] rsvd;
logic [7:0] parity;
} user_t;
typedef struct packed {
logic valid;
user_t user;
} inp_t;
typedef struct packed {
logic valid;
logic opcode;
} out_t;
endpackage
module top (
input foo_pkg::inp_t dat_i,
output foo_pkg::out_t dat_o
);
endmodule
module top (dat_i, dat_o);
input wire [16:0] dat_i;
output wire [1:0] dat_o;
endmodule
module top;
logic [2:0][3:0] arr [1:0];
initial begin
for (int i = 0; i <= 1; i++) begin
for (int j = 0; j <= 2; j++) begin
for (int k = 0; k <= 3; k++) begin
$display("%b", arr[i][j][k]);
arr[i][j][k] = 1'(i+j+k);
$display("%b", arr[i][j][k]);
end
end
end
end
endmodule
module top;
reg arr [1:0][2:0][3:0];
initial begin : block_name
integer i, j, k;
for (i = 0; i <= 1; i++) begin
for (j = 0; j <= 2; j++) begin
for (k = 0; k <= 3; k++) begin
$display("%b", arr[i][j][k]);
arr[i][j][k] = i+j+k;
$display("%b", arr[i][j][k]);
end
end
end
end
endmodule
module top #(FOO = 10);
initial $display(FOO);
endmodule
module top2 #(FOO = 10, BAR = 11);
initial $display(FOO, BAR);
endmodule
module top3 #(FOO = 10, BAR = 11, parameter BAZ = 12);
initial $display(FOO, BAR, BAZ);
endmodule
module top #(parameter FOO = 10);
initial $display(FOO);
endmodule
module top2 #(parameter FOO = 10, parameter BAR = 11);
initial $display(FOO, BAR);
endmodule
module top3 #(parameter FOO = 10, parameter BAR = 11, parameter BAZ = 12);
initial $display(FOO, BAR, BAZ);
endmodule
class P #(
parameter WIDTH = 1,
parameter type BASE = logic
);
typedef BASE [WIDTH - 1:0] Unit;
endclass
`define DUMP \
begin \
a = '1; \
b = '1; \
c = '1; \
d = '1; \
e = '1; \
$display("%b %b %b %b %b", a, b, c, d, e); \
end
module top;
localparam X = 2;
localparam type T = logic [31:0];
P#()::Unit a;
P#(X)::Unit b;
P#(X, T)::Unit c;
P#(.WIDTH(X))::Unit d;
P#(.BASE(T))::Unit e;
initial `DUMP
if (1) begin : blk
localparam X = 3;
localparam type T = logic [7:0];
P#()::Unit a;
P#(X)::Unit b;
P#(X, T)::Unit c;
P#(.WIDTH(X))::Unit d;
P#(.BASE(T))::Unit e;
initial `DUMP
end
if (1) begin : route
localparam X = 3;
localparam type T = logic [7:0];
initial begin
begin
P#()::Unit a;
P#(X)::Unit b;
P#(X, T)::Unit c;
P#(.WIDTH(X))::Unit d;
P#(.BASE(T))::Unit e;
`DUMP
end
begin
P#()::Unit a;
P#(X)::Unit b;
P#(X, T)::Unit c;
P#(.WIDTH(X))::Unit d;
P#(.BASE(T))::Unit e;
`DUMP
end
begin
P#()::Unit a;
P#(X)::Unit b;
P#(X, T)::Unit c;
P#(.WIDTH(X))::Unit d;
P#(.BASE(T))::Unit e;
`DUMP
end
end
end
endmodule
`define DUMP \
begin \
a = 1'sb1; \
b = 1'sb1; \
c = 1'sb1; \
d = 1'sb1; \
e = 1'sb1; \
$display("%b %b %b %b %b", a, b, c, d, e); \
end
module top;
reg [0:0] a;
reg [1:0] b;
reg [63:0] c;
reg [1:0] d;
reg [31:0] e;
initial `DUMP
generate
if (1) begin : blk
reg [0:0] a;
reg [2:0] b;
reg [23:0] c;
reg [2:0] d;
reg [7:0] e;
initial
repeat (4)
`DUMP
end
endgenerate
endmodule
module Module(out);
parameter type T = logic;
output T out;
assign out = '1;
endmodule
module top;
logic w;
logic [$bits(w)-1:0] b;
logic o0, o1;
logic [1:0] o2;
Module m0(o0);
Module #(logic[$bits(w)-1:0]) m1(o1);
Module #(logic[$bits(b)*2-1:0]) m2(o2);
endmodule
module Module_Size1(out);
output wire out;
assign out = 1'b1;
endmodule
module Module_Size2(out);
output wire [1:0] out;
assign out = 2'b11;
endmodule
module top;
wire w;
wire [0:0] b;
wire o0, o1;
wire [1:0] o2;
Module_Size1 m0(o0);
Module_Size1 m1(o1);
Module_Size2 m2(o2);
endmodule
module mod #(
parameter STR = "",
parameter type T = logic,
parameter WIDTH = 32,
parameter type WIDTH_T = logic [WIDTH-1:0],
parameter T INDIRECT = 0,
parameter type OTHER_T = struct packed { type(INDIRECT) x, y; }
);
initial begin
$display("%s $bits(T) = %0d", STR, $bits(T));
$display("%s WIDTH = %0d", STR, WIDTH);
$display("%s $bits(WIDTH_T) = %0d", STR, $bits(WIDTH_T));
$display("%s $bits(OTHER_T) = %0d", STR, $bits(OTHER_T));
end
endmodule
module top;
parameter type BASE = byte;
typedef struct packed { BASE y; } W;
W w;
typedef struct packed { type(w) x, y; } V;
V v;
typedef logic [$bits(v)*2-1:0] U;
U u;
`define TEST(x) \
assign x = 0; \
mod #(`"x`", type(x)) m``x();
`TEST(w)
`TEST(v)
`TEST(u)
mod #("t") mt();
endmodule
module mod #(
parameter STR = "",
parameter T = 1
);
initial begin
$display("%s $bits(T) = %0d", STR, T);
$display("%s WIDTH = %0d", STR, 32);
$display("%s $bits(WIDTH_T) = %0d", STR, 32);
$display("%s $bits(OTHER_T) = %0d", STR, 2 * T);
end
endmodule
module top;
`define TEST(x, w) \
wire [w-1:0] x; \
assign x = 0; \
mod #(`"x`", w) m``x();
`TEST(w, 8)
`TEST(v, 16)
`TEST(u, 32)
mod #("t") mt();
endmodule
module mod #(
parameter type T = logic
);
initial $display("$bits(T) = %0d", $bits(T));
endmodule
module top;
parameter SIZE = 8;
mod #(logic [SIZE-1:0]) m();
endmodule
module mod #(
parameter S = 1
);
initial $display("$bits(T) = %0d", S);
endmodule
module top;
parameter SIZE = 8;
mod #(SIZE) m();
endmodule
module Module #(
parameter int S,
parameter type T
);
T x;
if (S) begin : a
if (S) begin : b
assign Module.x = '1;
logic [$bits(Module.x):0] y = 'z;
end
end
initial $display("Module %0d: %b %0d %b %0d", S, Module.x, $bits(T), Module.a.b.y, $bits(Module.a.b.y));
endmodule
module top;
parameter ONE = 1;
logic [ONE*7:ONE*0] x;
if (1) begin : blk
localparam W = ONE * 3;
typedef logic [W-1:$bits(x)] T;
T x;
end
Module #(1, logic [$bits(x)-1:0]) m1();
Module #(2, logic [$bits(blk.x)-1:0]) m2();
Module #(3, logic [top.blk.W-1:0]) m3();
endmodule
module Module;
parameter S = 0;
parameter T = 0;
wire [T-1:0] x;
generate
if (S) begin : a
if (S) begin : b
assign Module.x = 1'sb1;
wire [T:0] y = 1'sbz;
end
end
endgenerate
initial $display("Module %0d: %b %0d %b %0d", S, Module.x, T, Module.a.b.y, T + 1);
endmodule
module top;
parameter ONE = 1;
wire [ONE*7:ONE*0] x;
if (1) begin : blk
localparam W = ONE * 3;
wire [W-1:$bits(x)] x;
end
Module #(1, 8) m1();
Module #(2, 7) m2();
Module #(3, 3) m3();
endmodule
package PKG;
typedef struct packed {
int W;
} F_t;
localparam F_t F_v = '{
W: 64
};
endpackage
module M0 #(
parameter type T,
parameter ID = "NONE"
);
T v;
initial $display("%s %0d %0d", ID, $bits(T), $bits(v));
endmodule
module M1 #(parameter PKG::F_t F = PKG::F_v) ();
typedef struct packed {
logic [F.W-1:0] field;
} local_t;
local_t v;
M0 #(.ID("A"), .T(local_t)) a();
M0 #(.ID("B"), .T(PKG::F_t)) b();
endmodule
module top;
typedef struct packed {
byte W;
} F_t;
localparam F_t F = '{
W: 16
};
typedef struct packed {
logic [F.W-1:0] field;
} local_t;
local_t v;
M1 m1();
M0 #(.ID("C"), .T(local_t)) c();
M0 #(.ID("D"), .T(PKG::F_t)) d();
M0 #(.ID("E"), .T(F_t)) e();
endmodule
module top;
localparam FORMAT = "%s %0d %0d";
initial begin
$display(FORMAT, "A", 64, 64);
$display(FORMAT, "B", 32, 32);
$display(FORMAT, "C", 16, 16);
$display(FORMAT, "D", 32, 32);
$display(FORMAT, "E", 8, 8);
end
endmodule
module M #(
parameter ID = "Z",
parameter K = 2,
parameter type T = logic [K-1:0]
);
initial $display("%s %0d %0d", ID, K, $bits(T));
endmodule
module top;
M z();
M #(.ID("A")) a();
M #(.ID("B"), .K(3)) b();
M #(.ID("C"), .K(4)) c();
parameter K = 4;
localparam type T = logic [2*K-1:0];
M #(.ID("D"), .K(4), .T(T)) d();
endmodule
module M #(
parameter ID = "Z",
parameter K = 2,
parameter T = K
);
initial $display("%s %0d %0d", ID, K, T);
endmodule
module top;
M z();
M #(.ID("A")) a();
M #(.ID("B"), .K(3)) b();
M #(.ID("C"), .K(4)) c();
M #(.ID("D"), .K(4), .T(8)) d();
endmodule
module foo #(
parameter type T = logic,
parameter size = 0
);
generate
if (size != 0) begin : foo
bar #(T, size - 1) x();
end
endgenerate
initial $display("foo %d %d", $bits(T), size);
endmodule
module bar #(
parameter type U = logic,
parameter size = 0
);
generate
if (size != 0) begin : bar
foo #(U, size - 1) x();
end
endgenerate
initial $display("bar %d %d", $bits(U), size);
endmodule
module top_1; foo #(byte, 2) x(); endmodule
module top_2; bar #(byte, 3) x(); endmodule
module top_3; foo #(bit, 4) x(); endmodule
module top_4; bar #(bit, 5) x(); endmodule
module top; foo x(); endmodule
module foo_byte #(
parameter size = 0
);
generate
if (size != 0) begin : foo
bar_byte #(size - 1) x();
end
endgenerate
initial $display("foo %d %d", 8, size);
endmodule
module bar_byte #(
parameter size = 0
);
generate
if (size != 0) begin : bar
foo_byte #(size - 1) x();
end
endgenerate
initial $display("bar %d %d", 8, size);
endmodule
module foo_bit #(
parameter size = 0
);
generate
if (size != 0) begin : foo
bar_bit #(size - 1) x();
end
endgenerate
initial $display("foo %d %d", 1, size);
endmodule
module bar_bit #(
parameter size = 0
);
generate
if (size != 0) begin : bar
foo_bit #(size - 1) x();
end
endgenerate
initial $display("bar %d %d", 1, size);
endmodule
module top_1; foo_byte #(2) x(); endmodule
module top_2; bar_byte #(3) x(); endmodule
module top_3; foo_bit #(4) x(); endmodule
module top_4; bar_bit #(5) x(); endmodule
module top; foo_bit #(0) x(); endmodule
module example(inp, data, valid);
parameter W = 16;
typedef struct packed {
logic [W-1:0] data;
logic valid;
} line_t;
parameter type local_line_t = line_t;
input local_line_t inp;
output logic [W-1:0] data;
assign data = inp.data;
output logic valid;
assign valid = inp.valid;
endmodule
module top;
reg [16:0] inp;
wire [15:0] data;
wire valid;
example e(.*);
initial inp = 17'b1_01100011_11001111;
endmodule
module top;
reg [16:0] inp;
wire [15:0] data;
wire valid;
assign data = inp[16:1];
assign valid = inp[0];
initial inp = 17'b1_01100011_11001111;
endmodule
module top;
wire [31:0] a;
wire [0:31] b;
assign a = 'h64ded943, b = 'hb7151d17;
initial begin
$display(a[0+:8]);
$display(a[15-:8]);
$display(b[0+:8]);
$display(b[15-:8]);
end
endmodule
module top;
wire [31:0] a;
wire [0:31] b;
assign a = 'h64ded943, b = 'hb7151d17;
initial begin
$display(a[7:0]);
$display(a[15:8]);
$display(b[0:7]);
$display(b[8:15]);
end
endmodule
module top;
parameter A = 3;
parameter B = 4;
logic [A*B-1:0] arr;
initial begin
arr = 0;
for (integer i = 0; i < A; ++i) begin
// yes this is silly but it captures an interesting edge case
arr[i * B +: B] = $bits(arr[i * B +: B])'(i);
end
$display("%b", arr);
end
endmodule
module top;
parameter A = 3;
parameter B = 4;
reg [A*B-1:0] arr;
initial begin : foo
integer i;
arr = 0;
for (i = 0; i < A; ++i) begin
arr[i * B +: B] = i;
end
$display("%b", arr);
end
endmodule
module test;
typedef struct packed {
int w, x;
byte y;
logic z;
} struct_a;
struct_a a;
initial begin
$monitor("%2d: %b %b %b %b %b", $time, a, a.w, a.x, a.y, a.z);
#1 a.w = 0;
#1 a.x = 0;
#1 a.y = 0;
#1 a.z = 0;
#1 a = '{default: 1};
#1 a = '{default: 2};
#1 a = '{default: 3};
#1 a = '{default: 0};
#1 a = '{default: -1};
#1 a = '{default: -2};
#1 a = '{int: 0, default: 1};
#1 a = '{byte: 0, default: 1};
#1 a = '{logic: 0, default: 1};
#1 a = '{logic: 1, int: 2, byte: 3};
#1 a = '{logic: 1, int: 2, byte: 3, default: -1};
#1 a = '{int: 3, byte: 2, default: 0};
#1 a = '{w: 8, int: 0, default: 1};
#1 a = '{w: 8, byte: 0, default: 1};
#1 a = '{w: 8, logic: 0, default: 1};
#1 a = '{w: 8, logic: 1, int: 2, byte: 3};
#1 a = '{w: 8, logic: 1, int: 2, byte: 3, default: -1};
#1 a = '{w: 8, int: 3, byte: 2, default: 0};
end
typedef struct packed {
int x;
struct_a y;
logic z;
} struct_b;
struct_b b;
initial begin
#100;
$monitor("%2d: %b %b %b %b", $time, b, b.x, b.y, b.z);
#1 b.x = 0;
#1 b.y = 0;
#1 b.z = 0;
#1 b = '{default: 1};
#1 b = '{default: 2};
#1 b = '{default: 3};
#1 b = '{default: 0};
#1 b = '{default: -1};
#1 b = '{default: -2};
#1 b = '{int: 0, default: 1};
#1 b = '{byte: 0, default: 1};
#1 b = '{logic: 0, default: 1};
#1 b = '{logic: 1, int: 2, byte: 3};
#1 b = '{logic: 1, int: 2, byte: 3, default: -1};
#1 b = '{int: 3, byte: 2, default: 0};
end
endmodule
module top; endmodule
module top;
parameter PARAM = 1;
`define BASE(expr, full, x, y, z) \
$display(`"%b %0d %0d %0d expr`", \
full, x, y, z)
`ifndef TEST
typedef byte T;
typedef struct packed {
byte x;
T y;
integer z;
} S;
`define TEST(a, b, c, expr) \
if (PARAM) begin \
S s; \
assign s = expr; \
initial `BASE(expr, s, s.x, s.y, s.z); \
end
`endif
`TEST(1, 2, 3, '{ x: 1, y: 2, z: 3 })
`TEST(2, 2, 3, '{ byte: 2, integer: 3 })
`TEST(3, 3, 2, '{ integer: 2, byte: 3 })
`TEST(4, 4, 2, '{ integer: 2, T: 4 })
`TEST(5, 5, 2, '{ integer: 2, T: 4, byte: 5 })
`TEST(5, 5, 2, '{ 2: 2, byte: 5 })
`TEST(7, 8, 9, '{ 1: 8, 2: 9, 0: 7 })
endmodule
`define TEST(aVal, bVal, cVal, expr) \
if (PARAM) begin \
wire [7:0] a, b; \
wire [31:0] c; \
assign a = aVal; \
assign b = bVal; \
assign c = cVal; \
initial `BASE(expr, {a, b, c}, a, b, c); \
end
`include "pattern_revised.sv"
typedef wire b_t;
module top(
input a [1:0],
input b_t b
);
initial $display("%d %d %1d %1d", a, b, $bits(a), $bits(b));
endmodule
module top(
input [1:0] a,
input wire b
);
initial $display("%d %d %1d %1d", a, b, $bits(a), $bits(b));
endmodule
module top;
assign arr[0][0] = 1;
logic [1:0][2:0] arr;
initial $display("%b", arr);
parameter YES = 1;
if (YES) begin : blk
assign brr[0][0] = 1;
logic [2:0][3:0] brr;
initial $display("%b", brr);
if (YES) begin : blk2
assign crr[0][0] = 1;
logic [3:0][4:0] crr;
initial $display("%b", crr);
end
end
endmodule
module top;
wire [5:0] arr;
assign arr[0] = 1;
initial $display("%b", arr);
parameter YES = 1;
generate
if (YES) begin : blk
wire [11:0] brr;
assign brr[0] = 1;
initial $display("%b", brr);
if (YES) begin : blk2
assign crr[0] = 1;
wire [19:0] crr;
initial $display("%b", crr);
end
end
endgenerate
endmodule
module top;
initial begin
logic x;
$display($bits(x));
begin
logic [0:$bits(x)] x;
$display($bits(x));
begin
logic [0:$bits(x)] x;
$display($bits(x));
end
end
end
initial begin
logic x;
$display($bits(type(x)));
begin
logic [0:$bits(type(x))] x;
$display($bits(type(x)));
begin
logic [0:$bits(type(x))] x;
$display($bits(type(x)));
end
end
end
initial begin
logic x;
$display($bits(x));
begin
logic [0:$bits(type(x))] x;
$display($bits(x));
begin
logic [0:$bits(type(x))] x;
$display($bits(x));
end
end
end
initial begin
logic x;
$display($bits(type(x)));
begin
logic [0:$bits(x)] x;
$display($bits(type(x)));
begin
logic [0:$bits(x)] x;
$display($bits(type(x)));
end
end
end
endmodule
module top;
initial begin
$display(1);
$display(2);
$display(3);
end
initial begin
$display(1);
$display(2);
$display(3);
end
initial begin
$display(1);
$display(2);
$display(3);
end
initial begin
$display(1);
$display(2);
$display(3);
end
endmodule
module top;
initial begin
$display(signed'(4294967295));
$display(unsigned'(4294967295));
$display(signed'(-1));
$display(unsigned'(-1));
end
endmodule
module top;
initial begin
$display($signed(4294967295));
$display($unsigned(4294967295));
$display($signed(-1));
$display($unsigned(-1));
end
endmodule
module top;
function automatic integer f;
input integer inp;
f = 1;
for (integer idx = 0; idx < inp; idx = idx + 1) begin
if (f == 32)
break;
f = f * 2;
end
endfunction
function automatic integer g;
input integer inp;
integer idx;
g = 1;
for (idx = 0; idx < inp; idx = idx + 1) begin
if (g == 32)
break;
g = g * 2;
end
g += idx;
endfunction
function automatic integer h;
input integer inp;
integer idx;
h = 1;
for (idx = 0; idx + 1 < 1 + inp; idx = idx + 1) begin
if (h == 32)
break;
h = h * 2;
end
h += idx + 1;
endfunction
function automatic integer j;
input integer inp;
for (j = 0; j < inp; j = j + 1)
if (j == 3)
return j;
j *= 2;
endfunction
function automatic integer k;
input integer inp;
for (k = 0; k + 1 < 1 + inp; k = k + 1)
if (k == 3)
return k * 3;
k = k * 2 + 1;
endfunction
integer i;
initial
for (i = 0; i < 10; i = i + 1) begin
$display("f(%0d) = %0d", i, f(i));
$display("g(%0d) = %0d", i, g(i));
$display("h(%0d) = %0d", i, h(i));
$display("j(%0d) = %0d", i, j(i));
$display("k(%0d) = %0d", i, k(i));
end
endmodule
module top;
function automatic integer f;
input integer inp;
if (inp > 5)
f = 32;
else
f = 2 ** inp;
endfunction
function automatic integer g;
input integer inp;
if (inp > 5)
g = 32 + 5;
else
g = 2 ** inp + inp;
endfunction
function automatic integer h;
input integer inp;
if (inp > 5)
h = 32 + 5 + 1;
else
h = 2 ** inp + inp + 1;
endfunction
function automatic integer j;
input integer inp;
if (inp > 3)
j = 3;
else
j = inp * 2;
endfunction
function automatic integer k;
input integer inp;
if (inp > 3)
k = 3 * 3;
else
k = inp * 2 + 1;
endfunction
integer i;
initial
for (i = 0; i < 10; i = i + 1) begin
$display("f(%0d) = %0d", i, f(i));
$display("g(%0d) = %0d", i, g(i));
$display("h(%0d) = %0d", i, h(i));
$display("j(%0d) = %0d", i, j(i));
$display("k(%0d) = %0d", i, k(i));
end
endmodule
package PKG;
typedef struct packed {
int F;
} S;
function automatic S f();
return '0;
endfunction
endpackage
module top;
localparam PKG::S L0 = PKG::f();
localparam int L1 = L0.F;
localparam int L2 = $clog2(L1);
initial $display("%b %b %b", L0, L1, L2);
endmodule
module top;
localparam L0 = 0;
localparam L1 = L0;
localparam L2 = $clog2(L1);
initial $display("%b %b %b", L0, L1, L2);
endmodule
module top;
localparam BW = 3;
logic [2:0] test;
logic [3:0] foo;
logic [3:0] bar;
integer x;
reg [7:0] y;
initial begin
test = BW'(0);
$display(test);
foo = 2'('1);
$display(foo);
bar = $bits(bar)'('1);
$display(bar);
x = 1'('1); $display("%b %0d", x, x);
y = 1'('1); $display("%b %0d", y, y);
x = 2'('0); $display("%b %0d", x, x);
y = 2'('0); $display("%b %0d", y, y);
x = 2'('1); $display("%b %0d", x, x);
y = 2'('1); $display("%b %0d", y, y);
x = 2'('x); $display("%b %0d", x, x);
y = 2'('x); $display("%b %0d", y, y);
x = 2'('z); $display("%b %0d", x, x);
y = 2'('z); $display("%b %0d", y, y);
end
endmodule
module top;
reg [2:0] test;
reg [3:0] foo;
reg [3:0] bar;
integer x;
reg [7:0] y;
initial begin
test = 0;
$display(test);
foo = 4'b0011;
$display(foo);
bar = 4'b1111;
$display(bar);
x = 1'b1; $display("%b %0d", x, x);
y = 1'b1; $display("%b %0d", y, y);
x = 2'b00; $display("%b %0d", x, x);
y = 2'b00; $display("%b %0d", y, y);
x = 2'b11; $display("%b %0d", x, x);
y = 2'b11; $display("%b %0d", y, y);
x = 2'bxx; $display("%b %0d", x, x);
y = 2'bxx; $display("%b %0d", y, y);
x = 2'bzz; $display("%b %0d", x, x);
y = 2'bzz; $display("%b %0d", y, y);
end
endmodule
module top;
// Derived from: https://www.amiq.com/consulting/2017/05/29/how-to-pack-data-using-systemverilog-streaming-operators/
typedef struct packed {
logic [3:0] addr;
logic [3:0] data;
} packet_t;
initial begin
logic [1:0] array[] = '{ 2'b10, 2'b01, 2'b11, 2'b00 };
packet_t packet = {<<4{ {<<2{array}} }};
$display("packet addr = %b", packet.addr);
$display("packet data = %b", packet.data);
end
initial begin
logic [23:0] temp;
temp = {>>byte{24'h060708}};
$display("%h", temp);
temp = {<<byte{24'h060708}};
$display("%h", temp);
temp = {>>bit{24'h060708}};
$display("%h", temp);
temp = {<<bit{24'h060708}};
$display("%h", temp);
temp = {>>7{24'h060708}};
$display("%h", temp);
temp = {<<7{24'h060708}};
$display("%h", temp);
temp = {>>7{20'h60708}};
$display("%h", temp);
temp = {<<7{20'h60708}};
$display("%h", temp);
temp = {>>7{16'h0708}};
$display("%h", temp);
temp = {<<7{16'h0708}};
$display("%h", temp);
end
task test_unpack;
input logic [23:0] in;
logic [0:0] i;
logic [1:0] j;
logic [2:0] k;
logic [5:0] l;
logic [11:0] m;
{>>byte{i, j, k, l, m}} = in;
$display("%b %b %b %b %b", i, j, k, l, m);
{<<byte{i, j, k, l, m}} = in;
$display("%b %b %b %b %b", i, j, k, l, m);
{>>bit{i, j, k, l, m}} = in;
$display("%b %b %b %b %b", i, j, k, l, m);
{<<bit{i, j, k, l, m}} = in;
$display("%b %b %b %b %b", i, j, k, l, m);
{>>7{i, j, k, l, m}} = in;
$display("%b %b %b %b %b", i, j, k, l, m);
{<<7{i, j, k, l, m}} = in;
$display("%b %b %b %b %b", i, j, k, l, m);
endtask
initial begin
test_unpack(24'h060708);
test_unpack(24'hC02375);
test_unpack(24'h12E3B8);
end
endmodule
module Streamer(i, l1, r1, l2, r2);
parameter IN_WIDTH = 0;
parameter OUT_WIDTH = 0;
parameter CHUNK_SIZE = 0;
input wire [IN_WIDTH-1:0] i;
output wire [OUT_WIDTH-1:0] l1;
output wire [OUT_WIDTH-1:0] r1;
output reg [OUT_WIDTH-1:0] l2;
output reg [OUT_WIDTH-1:0] r2;
if (IN_WIDTH <= OUT_WIDTH) begin
wire [OUT_WIDTH-1:0] lA = {<<CHUNK_SIZE{i}};
wire [OUT_WIDTH-1:0] rA = {>>CHUNK_SIZE{i}};
wire [OUT_WIDTH-1:0] lB;
wire [OUT_WIDTH-1:0] rB;
assign lB = {<<CHUNK_SIZE{i}};
assign rB = {>>CHUNK_SIZE{i}};
assign l1 = lA == lB ? lA : 'x;
assign r1 = rA == rB ? rA : 'x;
end
if (OUT_WIDTH <= IN_WIDTH) begin
always @* {<<CHUNK_SIZE{l2}} = i;
always @* {>>CHUNK_SIZE{r2}} = i;
end
endmodule
module Streamer(i, l1, r1, l2, r2);
parameter IN_WIDTH = 0;
parameter OUT_WIDTH = 0;
parameter CHUNK_SIZE = 0;
input wire [IN_WIDTH-1:0] i;
output wire [OUT_WIDTH-1:0] l1;
output wire [OUT_WIDTH-1:0] r1;
output reg [OUT_WIDTH-1:0] l2;
output reg [OUT_WIDTH-1:0] r2;
function [IN_WIDTH-1:0] stream_left;
input [IN_WIDTH-1:0] inp;
integer idx;
localparam remainder = IN_WIDTH % CHUNK_SIZE;
localparam remainder_fake = remainder ? remainder : 1;
begin
for (idx = 0; idx + CHUNK_SIZE <= IN_WIDTH; idx = idx + CHUNK_SIZE)
stream_left[IN_WIDTH - idx - 1 -: CHUNK_SIZE] = inp[idx+:CHUNK_SIZE];
if (remainder)
stream_left[0+:remainder_fake] = inp[idx+:remainder_fake];
end
endfunction
function [OUT_WIDTH-1:0] pad;
input [IN_WIDTH-1:0] inp;
pad = IN_WIDTH > OUT_WIDTH
? inp >> IN_WIDTH - OUT_WIDTH
: inp << OUT_WIDTH - IN_WIDTH
;
endfunction
generate
if (IN_WIDTH <= OUT_WIDTH) begin
assign l1 = pad(stream_left(i));
assign r1 = pad(i);
end
if (OUT_WIDTH <= IN_WIDTH) begin
always @* l2 = pad(stream_left(i));
always @* r2 = pad(i);
end
endgenerate
endmodule
module Tester;
parameter IN_WIDTH = 0;
parameter OUT_WIDTH = 0;
parameter CHUNK_SIZE = 0;
reg [IN_WIDTH-1:0] i;
wire [OUT_WIDTH-1:0] l1, l2;
wire [OUT_WIDTH-1:0] r1, r2;
Streamer #(IN_WIDTH, OUT_WIDTH, CHUNK_SIZE)
streamer(i, l1, r1, l2, r2);
localparam DELAY = 8 * (CHUNK_SIZE + 8 * (OUT_WIDTH + 8 * IN_WIDTH));
initial #DELAY;
integer idx;
initial begin
for (idx = 0; idx < IN_WIDTH; idx = idx + 1) begin
i = 1 << idx;
#1 $display("INW=%0d OUTW=%0d CS=%0d i=%b l1=%b r1=%b l2=%b r2=%b",
IN_WIDTH, OUT_WIDTH, CHUNK_SIZE, i, l1, r1, l2, r2);
end
end
endmodule
module top;
generate
genvar i, o, c;
for (i = 1; i <= 8; i = i + 1)
for (o = 1; o <= 8; o = o + 1)
for (c = 1; c <= i; c = c + 1)
Tester #(i, o, c) tester();
endgenerate
endmodule
module top;
localparam FOO = "some useful string";
localparam type T = type(FOO);
localparam T BAR = "some other useful string"; // clipped
initial $display("'%s' '%s'", FOO, BAR);
endmodule
module top;
localparam FOO = "some useful string";
localparam WIDTH = $bits("some useful string");
localparam [WIDTH-1:0] BAR = "some other useful string"; // clipped
initial $display("'%s' '%s'", FOO, BAR);
endmodule
`include "string_param.vh"
module Example(inp, out);
parameter PATTERN = "whatever";
parameter UNUSED = 0;
localparam IN_WIDTH = $bits(PATTERN);
localparam OUT_WIDTH = `COUNT_ONES(PATTERN);
input [IN_WIDTH - 1:0] inp;
output [OUT_WIDTH - 1:0] out;
if (PATTERN[0])
assign out[0] = inp[0];
for (genvar j = 1; j < IN_WIDTH; ++j)
if (PATTERN[j])
assign out[`COUNT_ONES(PATTERN[j - 1:0])] = inp[j];
endmodule
`include "string_param.vh"
module Example(inp, out);
parameter PATTERN = "whatever";
parameter IN_WIDTH = $bits(PATTERN);
localparam OUT_WIDTH = `COUNT_ONES(PATTERN);
input wire [IN_WIDTH - 1:0] inp;
output wire [OUT_WIDTH - 1:0] out;
if (PATTERN[0])
assign out[0] = inp[0];
genvar j;
for (j = 1; j < IN_WIDTH; j = j + 1)
if (PATTERN[j])
assign out[`COUNT_ONES(PATTERN[j - 1:0])] = inp[j];
endmodule
`define COUNT_ONES(expr) (0 \
+ ((expr) >> 0 & 1'b1) + ((expr) >> 1 & 1'b1) + ((expr) >> 2 & 1'b1) + ((expr) >> 3 & 1'b1) \
+ ((expr) >> 4 & 1'b1) + ((expr) >> 5 & 1'b1) + ((expr) >> 6 & 1'b1) + ((expr) >> 7 & 1'b1) \
+ ((expr) >> 8 & 1'b1) + ((expr) >> 9 & 1'b1) + ((expr) >> 10 & 1'b1) + ((expr) >> 11 & 1'b1) \
+ ((expr) >> 12 & 1'b1) + ((expr) >> 13 & 1'b1) + ((expr) >> 14 & 1'b1) + ((expr) >> 15 & 1'b1) \
+ ((expr) >> 16 & 1'b1) + ((expr) >> 17 & 1'b1) + ((expr) >> 18 & 1'b1) + ((expr) >> 19 & 1'b1) \
+ ((expr) >> 20 & 1'b1) + ((expr) >> 21 & 1'b1) + ((expr) >> 22 & 1'b1) + ((expr) >> 23 & 1'b1) \
+ ((expr) >> 24 & 1'b1) + ((expr) >> 25 & 1'b1) + ((expr) >> 26 & 1'b1) + ((expr) >> 27 & 1'b1) \
+ ((expr) >> 28 & 1'b1) + ((expr) >> 29 & 1'b1) + ((expr) >> 30 & 1'b1) + ((expr) >> 31 & 1'b1) \
)
module top;
reg [31:0] data;
`define TEST(idx, pattern, in_width, out_width) \
localparam p``idx = pattern; \
wire [in_width - 1:0] i``idx; \
wire [out_width - 1:0] o``idx; \
assign i``idx = data[0+:in_width]; \
Example #(p``idx, in_width) e``idx(i``idx, o``idx);
`TEST(1, 5'b10101, 5, 3)
`TEST(2, 10'b1110001111, 10, 7)
integer i;
initial begin
data = 0;
for (i = 0; i < 100; i = i + 1) begin
data = 1664525 * data + 1013904223;
#1 $display("%b %b %b", data, o1, o2);
end
end
endmodule
typedef struct packed {
logic x;
logic [3:0] y;
logic [1:0] z;
} Struct_t;
module Unpacker(in, select, a, b, c);
parameter WIDTH = 8;
input Struct_t [WIDTH-1:0] in;
input logic [$clog2(WIDTH)-1:0] select;
output logic a;
output logic [3:0] b;
output logic [1:0] c;
assign a = in[select].x;
assign b = in[select].y;
assign c = in[select].z;
endmodule
module Unpacker(in, select, a, b, c);
parameter WIDTH = 8;
input wire [WIDTH*7-1:0] in;
input wire [$clog2(WIDTH)-1:0] select;
output wire a;
output wire [3:0] b;
output wire [1:0] c;
wire [6:0] p;
assign p = in[select*7+:7];
assign a = p[6:6];
assign b = p[5:2];
assign c = p[1:0];
endmodule
module main;
typedef struct packed {
logic [1:0][2:0] x;
logic [0:2][1:0] y;
logic z;
} foo_t;
foo_t foo;
initial begin
$monitor($time, " %b %b %b %b %b %b %b %b",
foo, foo.x, foo.y, foo.z,
foo.x[0], foo.x[0][0], foo.y[0], foo.y[0][0]);
#1; foo.z = 0;
#1; foo.y = 0;
#1; foo.y[0] = '1;
#1; foo.y[1] = '1;
#1; foo.y[1][1] = 0;
#1; foo.y[0][0] = 1;
#1; foo.y[0][1] = 1;
#1; foo.x = 0;
#1; foo.x[0] = '1;
#1; foo.x[1] = '1;
#1; foo.x[1][1] = 0;
#1; foo.x[0][0] = 1;
#1; foo.x[0][1] = 1;
end
endmodule
module top;
endmodule
module main;
reg [2:0] foo_x_1;
reg [2:0] foo_x_0;
reg [1:0] foo_y_2;
reg [1:0] foo_y_1;
reg [1:0] foo_y_0;
wire [5:0] foo_x;
wire [5:0] foo_y;
assign foo_x = {foo_x_1, foo_x_0};
assign foo_y = {foo_y_0, foo_y_1, foo_y_2};
reg foo_z;
wire [12:0] foo;
assign foo = {foo_x, foo_y, foo_z};
initial begin
$monitor($time, " %b %b %b %b %b %b %b %b",
foo, foo_x, foo_y, foo_z,
foo_x_0, foo_x_0[0], foo_y_0, foo_y_0[0]);
#1; foo_z = 0;
#1; {foo_y_0, foo_y_1, foo_y_2} = 0;
#1; foo_y_0 = 1'sb1;
#1; foo_y_1 = 1'sb1;
#1; foo_y_1[1] = 0;
#1; foo_y_0[0] = 1;
#1; foo_y_0[1] = 1;
#1; {foo_x_1, foo_x_0} = 0;
#1; foo_x_0 = 1'sb1;
#1; foo_x_1 = 1'sb1;
#1; foo_x_1[1] = 0;
#1; foo_x_0[0] = 1;
#1; foo_x_0[1] = 1;
end
endmodule
module top;
endmodule
module top;
typedef struct packed {
bit a, b;
} T;
localparam T FOO [4] = '{
'{ 0, 0 },
'{ 0, 1 },
'{ 1, 0 },
'{ 1, 1 }
};
initial begin
$display(FOO[0].a);
$display(FOO[0].b);
$display(FOO[2].a);
$display(FOO[2].b);
end
endmodule
module top;
initial begin
$display(1'b0);
$display(1'b0);
$display(1'b1);
$display(1'b0);
end
endmodule
typedef struct packed {
logic [2:0] a;
logic [1:0] b;
logic [3:0] c;
} foo_s;
parameter foo_s [1:0] foo = {
'{ a: 2, b: 1, c: 0 },
'{ a: 1, b: 0, c: 2 }
};
module top;
initial begin
$display(foo[0]);
$display(foo[1]);
end
endmodule
module top;
parameter foo_1 = { 3'b010, 2'b01, 4'b0000 };
parameter foo_0 = { 3'b001, 2'b00, 4'b0010 };
initial begin
$display(foo_0);
$display(foo_1);
end
endmodule
module top;
reg [56-1:0] in;
reg [2:0] select;
wire a;
wire [3:0] b;
wire [1:0] c;
Unpacker unpacker(in, select, a, b, c);
initial begin
$monitor("%d: %01b %04b %02b", select, a, b, c);
in = 'b01111011011011101111100111110111001010001011100110101000;
select = 0; #1;
select = 1; #1;
select = 2; #1;
select = 3; #1;
select = 4; #1;
select = 5; #1;
select = 6; #1;
select = 7; #1;
$finish;
end
// 0 1010 00
// 1 1100 11
// 0 1000 10
// 0 1110 01
// 0 0111 11
// 1 0111 11
// 1 0110 11
// 0 1111 01
endmodule
typedef struct packed {
logic [3:0] a;
logic [3:0] b;
} pair;
typedef struct packed {
pair [1:0] x;
pair [1:0] y;
} pair_list_pair;
module Example(data, p1, p2, out_x, out_y);
input pair_list_pair data;
input logic p1;
input logic p2;
output logic [3:0] out_x;
output logic [3:0] out_y;
assign out_x = p2 ? data.x[p1].a : data.x[p1].b;
assign out_y = p2 ? data.y[p1].a : data.y[p1].b;
endmodule
module Example(data, p1, p2, out_x, out_y);
input wire [31:0] data;
input wire p1, p2;
output wire [3:0] out_x;
output wire [3:0] out_y;
assign out_x = p2 ? data[p1 * 8 + 20 +:4] : data[p1 * 8 + 16 +:4];
assign out_y = p2 ? data[p1 * 8 + 4 +:4] : data[p1 * 8 + 0 +:4];
endmodule
module top;
reg [31:0] data;
reg p1, p2;
wire [3:0] out_x;
wire [3:0] out_y;
Example example(data, p1, p2, out_x, out_y);
task exhaust;
begin
#1 p1 = 0;
#1 p2 = 0;
#1 p1 = 0;
#1 p2 = 1;
#1 p1 = 1;
#1 p2 = 0;
#1 p1 = 1;
#1 p2 = 1;
end
endtask
initial begin
$monitor("%2d %b %b %b %b %b", $time,
data, p1, p2, out_x, out_y);
#1 data = 32'ha7107338;
exhaust;
#1 data = 32'h8f8259e4;
exhaust;
#1 data = 32'h80ad046a;
exhaust;
#1 data = 32'hbf93017e;
exhaust;
#1 data = 32'he6458a2d;
exhaust;
end
endmodule
module top;
typedef struct packed {
logic a;
logic b;
} foo_t;
foo_t foo;
initial begin
foo = '{a: 1'b1, default: '0};
$display(foo, foo.a, foo.b);
end
endmodule
module top;
reg [1:0] foo = {1'b1, 1'b0};
initial $display(foo, foo[1], foo[0]);
endmodule
module top;
if (1) begin : blk
struct packed {
logic x, y;
} [1:0] s;
end
assign blk.s[0].x = 0;
assign top.blk.s[0].y = 1;
assign top.blk.s[1].x = 1;
assign blk.s[1].y = 0;
initial #1 $display("%b", blk.s);
endmodule
module top;
if (1) begin : blk
wire [3:0] s;
end
assign blk.s = 4'b1001;
initial #1 $display("%b", blk.s);
endmodule
`define DUMP(id) \
begin \
x = 1'sb1; \
$display(`"id: access a=%b b=%b`", x.a, x.b); \
x = '{ a: 1'sb1, b: 1'sbz }; \
$display(`"id: literal x=%b`", x); \
end
module top;
parameter A = 2;
parameter B = 3;
struct packed {
logic [A-1:0] a;
logic [B-1:0] b;
} x;
initial `DUMP(0)
if (1) begin : blk
localparam A = 10;
localparam B = 11;
initial `DUMP(1)
end
initial begin
localparam A = 10;
localparam B = 11;
`DUMP(2)
end
endmodule
`define DUMP(id) \
begin \
x = 1'sb1; \
$display(`"id: access a=%b b=%b`", x[0+:A], x[A+:B]); \
x = { {A {1'sb1}}, {B {1'sbz}} }; \
$display(`"id: literal x=%b`", x); \
end
module top;
parameter A = 2;
parameter B = 3;
reg [A+B-1:0] x;
initial `DUMP(0)
if (1) begin : blk
localparam _A = 10;
localparam _B = 11;
initial `DUMP(1)
end
initial begin : foo
localparam _A = 10;
localparam _B = 11;
`DUMP(2)
end
endmodule
module top;
typedef struct packed {
integer a, b, c;
} S;
S s = '{a: 1, b: 2, c: 3};
initial #1 $display("%b %b %b %b", s, s.a, s.b, s.c);
endmodule
module top;
wire [32*3-1:0] s = {32'd1, 32'd2, 32'd3};
initial #1 $display("%b %b %b %b", s, s[64+:32], s[32+:32], s[0+:32]);
endmodule
package PKG;
typedef struct packed {
logic f;
} foo_t;
endpackage
module top;
typedef struct packed {
PKG::foo_t f;
} local_t;
local_t w;
initial begin
w <= local_t'(1'sb1);
$display("%b", w);
end
endmodule
module top;
reg w;
initial begin
w <= 1'b1;
$display("%b", w);
end
endmodule
module Module #(parameter type T, parameter N);
T t;
type(t.a) x;
type(t.b) y;
initial begin
$display("$bits(T)=", $bits(T));
$display("$bits(t)=", $bits(t));
$display("$bits(t.a)=", $bits(t.a));
$display("$bits(t.b)=", $bits(t.b));
$display("$bits(x)=", $bits(x));
$display("$bits(y)=", $bits(y));
$display("$bits(N)=", $bits(N));
$display("N=", N);
end
endmodule
module top;
typedef struct packed {
logic a;
logic [2] b;
} Struct1;
typedef struct packed {
logic [5] a;
Struct1 b;
logic [2] c;
logic d;
} Struct2;
Module #(Struct1, $bits(Struct1)) m1();
Module #(Struct2, $bits(Struct2)) m2();
endmodule
module Module1 #(parameter N = 1);
initial begin
$display("$bits(T)=", 3);
$display("$bits(t)=", 3);
$display("$bits(t.a)=", 1);
$display("$bits(t.b)=", 2);
$display("$bits(x)=", 1);
$display("$bits(y)=", 2);
$display("$bits(N)=", 32);
$display("N=", N);
end
endmodule
module Module2 #(parameter N = 1);
initial begin
$display("$bits(T)=", 11);
$display("$bits(t)=", 11);
$display("$bits(t.a)=", 5);
$display("$bits(t.b)=", 3);
$display("$bits(x)=", 5);
$display("$bits(y)=", 3);
$display("$bits(N)=", 32);
$display("N=", N);
end
endmodule
module top;
Module1 #(3) m1();
Module2 #(11) m2();
endmodule
module Example;
typedef struct packed {
logic [10:4] a;
logic [1:3] bx;
logic [3:1] by;
logic [3:4][5:7] cw;
logic [4:3][5:7] cx;
logic [3:4][7:5] cy;
logic [4:3][7:5] cz;
} T;
T t;
initial begin
$monitor("%2d %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b %b", $time,
t, t.a, t.bx, t.by,
t.cw, t.cw[3], t.cw[4],
t.cx, t.cx[3], t.cx[4],
t.cy, t.cy[3], t.cy[4],
t.cz, t.cz[3], t.cz[4]
);
#1 t.a = 1;
#1 t.a[5+:2] = '1;
#1 t.a[8-:3] = '1;
#1 t.a[10] = 1;
#1 t.a[7] = 0;
#1 t.bx[1+:1] = 1;
#1 t.bx[1:2] = 1;
#1 t.bx[3] = 0;
#1 t.bx[3-:2] = 1;
#1 t.bx[2] = 0;
#1 t.by[1+:1] = 1;
#1 t.by[2:1] = 1;
#1 t.by[3] = 0;
#1 t.by[3-:2] = 1;
#1 t.by[2] = 0;
#1 t.cw[3][6+:1] = 1;
#1 t.cw[3][7-:2] = 1;
#1 t.cw[3][5+:2] = 0;
#1 t.cw[3][6:7] = 2'b10;
#1 t.cw[3][6:7] = 2'b01;
#1 t.cw[3:4] = '1;
#1 t.cw[4][5] = 0;
#1 t.cw[4][6:7] = 0;
#1 t.cw[3+:2] = 6'b010011;
#1 t.cw[4-:2] = 6'b101011;
#1 t.cx[3][6+:1] = 1;
#1 t.cx[3][7-:2] = 1;
#1 t.cx[3][5+:2] = 0;
#1 t.cx[3][6:7] = 2'b10;
#1 t.cx[3][6:7] = 2'b01;
#1 t.cx[4:3] = '1;
#1 t.cx[4][5] = 0;
#1 t.cx[4][6:7] = 0;
#1 t.cx[3+:2] = 6'b010011;
#1 t.cx[4-:2] = 6'b101011;
#1 t.cy[3][6+:1] = 1;
#1 t.cy[3][7-:2] = 1;
#1 t.cy[3][5+:2] = 0;
#1 t.cy[3][7:6] = 2'b10;
#1 t.cy[3][7:6] = 2'b01;
#1 t.cy[3:4] = '1;
#1 t.cy[4][5] = 0;
#1 t.cy[4][7:6] = 0;
#1 t.cy[3+:2] = 6'b010011;
#1 t.cy[4-:2] = 6'b101011;
#1 t.cz[3][6+:1] = 1;
#1 t.cz[3][7-:2] = 1;
#1 t.cz[3][5+:2] = 0;
#1 t.cz[3][7:6] = 2'b10;
#1 t.cz[3][7:6] = 2'b01;
#1 t.cz[4:3] = '1;
#1 t.cz[4][5] = 0;
#1 t.cz[4][7:6] = 0;
#1 t.cz[3+:2] = 6'b010011;
#1 t.cz[4-:2] = 6'b101011;
end
endmodule
module top;
endmodule
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment