From 64eb8f29adcc3e6ee92e083ae0fee3aaf85dbbc4 Mon Sep 17 00:00:00 2001 From: Udi Finkelstein Date: Tue, 26 Sep 2017 06:25:42 +0300 Subject: Add $size() function. At the moment it works only on expressions, not on memories. --- tests/simple/functions01.sv | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/simple/functions01.sv (limited to 'tests/simple') diff --git a/tests/simple/functions01.sv b/tests/simple/functions01.sv new file mode 100644 index 000000000..0fa1da6bd --- /dev/null +++ b/tests/simple/functions01.sv @@ -0,0 +1,15 @@ +module functions01; +wire [3:0]x; +wire [$size(x)-1:0]x_size; +wire [$size({x, x})-1:0]xx_size; +wire [3:0]w[0:5]; + +// +// The following are not supported yet: +// + +//wire [$size(w)-1:0]w_s; +//wire [$bits(x)-1:0]x_bits; +//wire [$bits({x, x})-1:0]xx_bits; + +endmodule -- cgit v1.2.3 From 17f8b4160574d34c446782952f09f940cd66c290 Mon Sep 17 00:00:00 2001 From: Udi Finkelstein Date: Tue, 26 Sep 2017 08:36:45 +0300 Subject: $size() now works with memories as well! --- tests/simple/functions01.sv | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/simple') diff --git a/tests/simple/functions01.sv b/tests/simple/functions01.sv index 0fa1da6bd..cd87a49b7 100644 --- a/tests/simple/functions01.sv +++ b/tests/simple/functions01.sv @@ -2,13 +2,15 @@ module functions01; wire [3:0]x; wire [$size(x)-1:0]x_size; wire [$size({x, x})-1:0]xx_size; -wire [3:0]w[0:5]; +wire [3:0]y[0:5]; +wire [$size(y)-1:0]y_size; +wire [3:0]z[0:5][0:7]; +wire [$size(z)-1:0]z_size; // // The following are not supported yet: // -//wire [$size(w)-1:0]w_s; //wire [$bits(x)-1:0]x_bits; //wire [$bits({x, x})-1:0]xx_bits; -- cgit v1.2.3 From 2dea42e9039cdf47ca4927f62c69c6ae7ac2e399 Mon Sep 17 00:00:00 2001 From: Udi Finkelstein Date: Tue, 26 Sep 2017 09:11:25 +0300 Subject: Added $bits() for memories as well. --- tests/simple/functions01.sv | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'tests/simple') diff --git a/tests/simple/functions01.sv b/tests/simple/functions01.sv index cd87a49b7..d6cd53e07 100644 --- a/tests/simple/functions01.sv +++ b/tests/simple/functions01.sv @@ -1,4 +1,5 @@ module functions01; + wire [3:0]x; wire [$size(x)-1:0]x_size; wire [$size({x, x})-1:0]xx_size; @@ -7,11 +8,9 @@ wire [$size(y)-1:0]y_size; wire [3:0]z[0:5][0:7]; wire [$size(z)-1:0]z_size; -// -// The following are not supported yet: -// - -//wire [$bits(x)-1:0]x_bits; -//wire [$bits({x, x})-1:0]xx_bits; +wire [$bits(x)-1:0]x_bits; +wire [$bits({x, x})-1:0]xx_bits; +wire [$bits(y)-1:0]y_bits; +wire [$bits(z)-1:0]z_bits; endmodule -- cgit v1.2.3 From 6ddc6a7af42d371aa7c08505d82b30628372a16c Mon Sep 17 00:00:00 2001 From: Udi Finkelstein Date: Tue, 26 Sep 2017 19:18:25 +0300 Subject: $size() seems to work now with or without the optional parameter. Multidimensional arrays still don't work. I suspect the problem is that the array is flattened into a 1D array before $size() is evaluated. --- tests/simple/functions01.sv | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'tests/simple') diff --git a/tests/simple/functions01.sv b/tests/simple/functions01.sv index d6cd53e07..e36d6a764 100644 --- a/tests/simple/functions01.sv +++ b/tests/simple/functions01.sv @@ -1,16 +1,26 @@ module functions01; wire [3:0]x; -wire [$size(x)-1:0]x_size; -wire [$size({x, x})-1:0]xx_size; wire [3:0]y[0:5]; -wire [$size(y)-1:0]y_size; wire [3:0]z[0:5][0:7]; -wire [$size(z)-1:0]z_size; -wire [$bits(x)-1:0]x_bits; -wire [$bits({x, x})-1:0]xx_bits; -wire [$bits(y)-1:0]y_bits; -wire [$bits(z)-1:0]z_bits; +//wire [$size(x)-1:0]x_size; +//wire [$size({x, x})-1:0]xx_size; +//wire [$size(y)-1:0]y_size; +//wire [$size(z)-1:0]z_size; + +assert property ($size(x) == 4); +assert property ($size({3{x}}) == 3*4); +assert property ($size(y) == 6); +assert property ($size(y, 1) == 6); +assert property ($size(y, 2) == 4); + +//wire [$bits(x)-1:0]x_bits; +//wire [$bits({x, x})-1:0]xx_bits; + +assert property ($bits(x) == 4); +assert property ($bits(y) == 4*6); +assert property ($bits(z) == 4*6*8); + endmodule -- cgit v1.2.3 From e951ac0dfba554a86331b0863f7bda81effef10d Mon Sep 17 00:00:00 2001 From: Udi Finkelstein Date: Tue, 26 Sep 2017 20:34:24 +0300 Subject: $size() now works correctly for all cases! It seems the issues was that AST_MULTIRANGE is converted into a multirange_dimensions[] array on the AST_MEMORY node directly. --- tests/simple/functions01.sv | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'tests/simple') diff --git a/tests/simple/functions01.sv b/tests/simple/functions01.sv index e36d6a764..d7ce2326e 100644 --- a/tests/simple/functions01.sv +++ b/tests/simple/functions01.sv @@ -1,8 +1,8 @@ module functions01; -wire [3:0]x; -wire [3:0]y[0:5]; -wire [3:0]z[0:5][0:7]; +wire [5:2]x; +wire [3:0]y[2:7]; +wire [3:0]z[7:2][2:9]; //wire [$size(x)-1:0]x_size; //wire [$size({x, x})-1:0]xx_size; @@ -13,7 +13,14 @@ assert property ($size(x) == 4); assert property ($size({3{x}}) == 3*4); assert property ($size(y) == 6); assert property ($size(y, 1) == 6); -assert property ($size(y, 2) == 4); +assert property ($size(y, (1+1)) == 4); + +assert property ($size(z) == 6); +assert property ($size(z, 1) == 6); +assert property ($size(z, 2) == 8); +assert property ($size(z, 3) == 4); +// This should trigger an error if enabled (it does). +//assert property ($size(z, 4) == 4); //wire [$bits(x)-1:0]x_bits; //wire [$bits({x, x})-1:0]xx_bits; @@ -22,5 +29,4 @@ assert property ($bits(x) == 4); assert property ($bits(y) == 4*6); assert property ($bits(z) == 4*6*8); - endmodule -- cgit v1.2.3