Tests: t_foreach now checks that all foreach loops get unrolled and evaluated statically.

This commit is contained in:
John Coiner 2018-03-15 19:06:32 -04:00
parent f55040a38b
commit e897c862f2
2 changed files with 34 additions and 21 deletions

View File

@ -15,5 +15,14 @@ execute (
check_finished=>1, check_finished=>1,
); );
# We expect all loops should be unrolled by verilator,
# none of the loop variables should exist in the output:
file_grep_not ("$Self->{obj_dir}/$Self->{VM_PREFIX}.cpp", qr/index_/);
# Further, we expect that all logic within the loop should
# have been evaluated inside the compiler. So there should be
# no references to 'sum' in the .cpp.
file_grep_not ("$Self->{obj_dir}/$Self->{VM_PREFIX}.cpp", qr/sum/);
ok(1); ok(1);
1; 1;

View File

@ -21,64 +21,68 @@ module t (/*AUTOARG*/);
initial begin initial begin
sum = 0; sum = 0;
foreach (depth1_array[index]) begin // We use 'index_' as the prefix for all loop vars,
sum = crc(sum, index, 0, 0, 0); // this allows t_foreach.pl to confirm that all loops
// have been unrolled and flattened away and no loop vars
// remain in the generated .cpp
foreach (depth1_array[index_a]) begin
sum = crc(sum, index_a, 0, 0, 0);
// Ensure the index never goes out of bounds. // Ensure the index never goes out of bounds.
// We used to get this wrong for an array of depth 1. // We used to get this wrong for an array of depth 1.
assert (index != -1); assert (index_a != -1);
assert (index != 1); assert (index_a != 1);
end end
`checkh(sum, 64'h0); `checkh(sum, 64'h0);
sum = 0; sum = 0;
foreach (array[a]) begin foreach (array[index_a]) begin
sum = crc(sum, a, 0, 0, 0); sum = crc(sum, index_a, 0, 0, 0);
end end
`checkh(sum, 64'h000000c000000000); `checkh(sum, 64'h000000c000000000);
sum = 0; sum = 0;
foreach (array[a,b]) begin foreach (array[index_a,index_b]) begin
sum = crc(sum, a, b, 0, 0); sum = crc(sum, index_a, index_b, 0, 0);
end end
`checkh(sum, 64'h000003601e000000); `checkh(sum, 64'h000003601e000000);
sum = 0; sum = 0;
foreach (array[a,b,c]) begin foreach (array[index_a,index_b,index_c]) begin
sum = crc(sum, a, b, c, 0); sum = crc(sum, index_a, index_b, index_c, 0);
end end
`checkh(sum, 64'h00003123fc101000); `checkh(sum, 64'h00003123fc101000);
sum = 0; sum = 0;
foreach (array[a,b,c,d]) begin foreach (array[index_a,index_b,index_c,index_d]) begin
sum = crc(sum, a, b, c, d); sum = crc(sum, index_a, index_b, index_c, index_d);
end end
`checkh(sum, 64'h0030128ab2a8e557); `checkh(sum, 64'h0030128ab2a8e557);
// //
sum = 0; sum = 0;
foreach (larray[a]) begin foreach (larray[index_a]) begin
sum = crc(sum, a, 0, 0, 0); sum = crc(sum, index_a, 0, 0, 0);
end end
`checkh(sum, 64'h0000009000000000); `checkh(sum, 64'h0000009000000000);
sum = 0; sum = 0;
foreach (larray[a,b]) begin foreach (larray[index_a,index_b]) begin
sum = crc(sum, a, b, 0, 0); sum = crc(sum, index_a, index_b, 0, 0);
sum = sum + {4'b0,a[7:0], 4'h0,b[7:0]}; sum = sum + {4'b0,index_a[7:0], 4'h0,index_b[7:0]};
end end
`checkh(sum, 64'h000002704b057073); `checkh(sum, 64'h000002704b057073);
sum = 0; sum = 0;
foreach (larray[a,b,c]) begin foreach (larray[index_a,index_b,index_c]) begin
sum = crc(sum, a, b, c, 0); sum = crc(sum, index_a, index_b, index_c, 0);
end end
`checkh(sum, 64'h00002136f9000000); `checkh(sum, 64'h00002136f9000000);
sum = 0; sum = 0;
foreach (larray[a,b,c,d]) begin foreach (larray[index_a,index_b,index_c,index_d]) begin
sum = crc(sum, a, b, c, d); sum = crc(sum, index_a, index_b, index_c, index_d);
end end
`checkh(sum, 64'h0020179aa7aa0aaa); `checkh(sum, 64'h0020179aa7aa0aaa);