verilator/test_regress/t/t_interface_arraymux.v

142 lines
2.8 KiB
Systemverilog
Raw Normal View History

// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain.
// SPDX-FileCopyrightText: 2017 John Stevenson
// SPDX-License-Identifier: CC0-1.0
package pkg;
2026-03-08 23:26:40 +01:00
typedef logic [31:0] unique_id_t;
typedef struct packed {unique_id_t foo;} inner_thing_t;
typedef struct packed {
inner_thing_t bar;
inner_thing_t baz;
} outer_thing_t;
endpackage
import pkg::*;
2026-03-08 23:26:40 +01:00
interface the_intf #(
parameter M = 5
);
outer_thing_t [M-1:0] things;
logic valid;
modport i(output things, output valid);
modport t(input things, input valid);
endinterface
2026-03-08 23:26:40 +01:00
module ThingMuxOH #(
parameter NTHINGS = 1,
2026-03-08 23:26:40 +01:00
parameter M = 5
) (
input logic [NTHINGS-1:0] select_oh,
2026-03-08 23:26:40 +01:00
the_intf.t things_in[NTHINGS-1:0],
the_intf.i thing_out
2026-03-08 23:26:40 +01:00
);
assign thing_out.valid = things_in[0].valid;
2020-07-15 23:58:59 +02:00
endmodule
2026-03-08 23:26:40 +01:00
module ThingMuxShort #(
2020-07-15 23:58:59 +02:00
parameter NTHINGS = 1,
2026-03-08 23:26:40 +01:00
parameter M = 5
) (
2020-07-15 23:58:59 +02:00
input logic [NTHINGS-1:0] select_oh,
2026-03-08 23:26:40 +01:00
the_intf.t things_in[NTHINGS],
2020-07-15 23:58:59 +02:00
the_intf.i thing_out
2026-03-08 23:26:40 +01:00
);
assign thing_out.valid = things_in[0].valid;
endmodule
2026-03-08 23:26:40 +01:00
module Thinker #(
parameter M = 5,
2026-03-08 23:26:40 +01:00
parameter N = 2
) (
input logic clk,
input logic reset,
2026-03-08 23:26:40 +01:00
input unique_id_t uids[0:N-1],
the_intf.t thing_inp,
the_intf.i thing_out
2026-03-08 23:26:40 +01:00
);
the_intf #(.M(M)) curr_things[N-1:0] ();
the_intf #(.M(M)) prev_things[N-1:0] ();
the_intf #(.M(M)) s_things[N] ();
the_intf #(.M(M)) curr_thing ();
the_intf #(.M(M)) prev_thing ();
the_intf #(.M(M)) s_thing ();
logic [N-1:0] select_oh;
// 1st mux:
ThingMuxOH #(
.NTHINGS(N),
.M(M)
) curr_thing_mux (
.select_oh(select_oh),
.things_in(curr_things),
.thing_out(curr_thing)
);
// 2nd mux, comment this out and no problem:
ThingMuxOH #(
.NTHINGS(N),
.M(M)
) prev_thing_mux (
.select_oh(select_oh),
.things_in(prev_things),
.thing_out(prev_thing)
);
// 3rd mux, using short array nomenclature:
ThingMuxShort #(
.NTHINGS(N),
.M(M)
) s_thing_mux (
.select_oh(select_oh),
.things_in(s_things),
.thing_out(s_thing)
);
2020-07-15 23:58:59 +02:00
endmodule
2026-03-08 23:26:40 +01:00
module t (
input logic clk,
input logic reset
);
localparam M = 5;
localparam N = 2;
unique_id_t uids[0:N-1];
the_intf #(.M(M)) thing_inp ();
the_intf #(.M(M)) thing_out ();
Thinker #(
.M(M),
.N(N)
) thinker (
.clk(clk),
.reset(reset),
.uids(uids),
.thing_inp(thing_inp),
.thing_out(thing_out)
);
// Previously there was a problem in V3Inst if non-default parameters was used
localparam K = 2;
the_intf #(.M(K)) thing_inp2 ();
the_intf #(.M(K)) thing_out2 ();
Thinker #(
.M(K),
.N(N)
) thinker2 (
.clk(clk),
.reset(reset),
.uids(uids),
.thing_inp(thing_inp2),
.thing_out(thing_out2)
);
endmodule