3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-07-29 15:37:59 +00:00

Merge pull request #3551 from daglem/struct-array-swapped-range

Support for arrays with swapped ranges within structs
This commit is contained in:
Jannis Harder 2022-12-01 00:58:32 +01:00 committed by GitHub
commit 4a2b7287ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 192 additions and 21 deletions

View file

@ -39,4 +39,135 @@ module top;
always_comb assert(s2==80'hFC00_4200_0012_3400_FFFC);
// Same as s2, but with little endian addressing
struct packed {
bit [0:7] [7:0] a; // 8 element packed array of bytes
bit [0:15] b; // filler for non-zero offset
} s3;
initial begin
s3 = '0;
s3.a[5:6] = 16'h1234;
s3.a[2] = 8'h42;
s3.a[0] = '1;
s3.a[0][1:0] = '0;
s3.b = '1;
s3.b[14:15] = '0;
end
always_comb assert(s3==80'hFC00_4200_0012_3400_FFFC);
// Same as s3, but with little endian bit addressing
struct packed {
bit [0:7] [0:7] a; // 8 element packed array of bytes
bit [0:15] b; // filler for non-zero offset
} s3_b;
initial begin
s3_b = '0;
s3_b.a[5:6] = 16'h1234;
s3_b.a[2] = 8'h42;
s3_b.a[0] = '1;
s3_b.a[0][6:7] = '0;
s3_b.b = '1;
s3_b.b[14:15] = '0;
end
always_comb assert(s3_b==80'hFC00_4200_0012_3400_FFFC);
`ifndef VERIFIC
// Note that the tests below for unpacked arrays in structs rely on the
// fact that they are actually packed in Yosys.
// Same as s2, but using unpacked array syntax
struct packed {
bit [7:0] a [7:0]; // 8 element unpacked array of bytes
bit [15:0] b; // filler for non-zero offset
} s4;
initial begin
s4 = '0;
s4.a[2:1] = 16'h1234;
s4.a[5] = 8'h42;
s4.a[7] = '1;
s4.a[7][1:0] = '0;
s4.b = '1;
s4.b[1:0] = '0;
end
always_comb assert(s4==80'hFC00_4200_0012_3400_FFFC);
// Same as s3, but using unpacked array syntax
struct packed {
bit [7:0] a [0:7]; // 8 element unpacked array of bytes
bit [0:15] b; // filler for non-zero offset
} s5;
initial begin
s5 = '0;
s5.a[5:6] = 16'h1234;
s5.a[2] = 8'h42;
s5.a[0] = '1;
s5.a[0][1:0] = '0;
s5.b = '1;
s5.b[14:15] = '0;
end
always_comb assert(s5==80'hFC00_4200_0012_3400_FFFC);
// Same as s5, but with little endian bit addressing
struct packed {
bit [0:7] a [0:7]; // 8 element unpacked array of bytes
bit [0:15] b; // filler for non-zero offset
} s5_b;
initial begin
s5_b = '0;
s5_b.a[5:6] = 16'h1234;
s5_b.a[2] = 8'h42;
s5_b.a[0] = '1;
s5_b.a[0][6:7] = '0;
s5_b.b = '1;
s5_b.b[14:15] = '0;
end
always_comb assert(s5_b==80'hFC00_4200_0012_3400_FFFC);
// Same as s5, but using C-type unpacked array syntax
struct packed {
bit [7:0] a [8]; // 8 element unpacked array of bytes
bit [0:15] b; // filler for non-zero offset
} s6;
initial begin
s6 = '0;
s6.a[5:6] = 16'h1234;
s6.a[2] = 8'h42;
s6.a[0] = '1;
s6.a[0][1:0] = '0;
s6.b = '1;
s6.b[14:15] = '0;
end
always_comb assert(s6==80'hFC00_4200_0012_3400_FFFC);
`endif
endmodule