2022-07-20 13:01:36 +00:00
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2019 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
`define stop $stop
`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
2024-07-20 10:51:50 +00:00
`define checkp(gotv,expv_s) do begin string gotv_s; gotv_s = $sformatf("%p", gotv); if ((gotv_s) !== (expv_s)) begin $write("%%Error: %s:%0d: got='%s' exp='%s'\n", `__FILE__,`__LINE__, (gotv_s), (expv_s)); `stop; end end while(0);
2022-07-20 13:01:36 +00:00
module t ( /*AUTOARG*/ ) ;
2024-10-18 23:51:44 +00:00
typedef struct { int x , y ; } point ;
function automatic int vec_len_squared ( point p ) ;
return p . x * p . x + p . y * p . y ;
endfunction
2022-07-20 13:01:36 +00:00
initial begin
int q [ * ] ;
2022-10-15 17:59:07 +00:00
int qe [ * ] ; // Empty - Note spaces around [*] for parsing coverage
2024-10-18 23:51:44 +00:00
point points_q [ * ] = ' { " a " : point ' { 1 , 2 } , " b " : point ' { 2 , 4 } , " c " : point ' { 1 , 4 } } ;
2022-07-20 13:01:36 +00:00
int qv [ $ ] ; // Value returns
int qi [ $ ] ; // Index returns
int i ;
2024-10-18 23:51:44 +00:00
bit b ;
2022-07-20 13:01:36 +00:00
string v ;
q = ' { " a " : 1 , " b " : 2 , " c " : 2 , " d " : 4 , " e " : 3 } ;
2024-07-20 10:51:50 +00:00
`checkp ( q , " '{ \" a \" :'h1, \" b \" :'h2, \" c \" :'h2, \" d \" :'h4, \" e \" :'h3} " ) ;
2022-07-20 13:01:36 +00:00
// NOT tested: with ... selectors
//q.sort; // Not legal on assoc - see t_assoc_meth_bad
//q.rsort; // Not legal on assoc - see t_assoc_meth_bad
//q.reverse; // Not legal on assoc - see t_assoc_meth_bad
//q.shuffle; // Not legal on assoc - see t_assoc_meth_bad
2024-07-20 10:51:50 +00:00
`checkp ( qe , " '{} " ) ;
2022-07-20 13:01:36 +00:00
qv = q . unique ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{'h1, 'h2, 'h4, 'h3} " ) ;
2022-07-20 13:01:36 +00:00
qv = qe . unique ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{} " ) ;
2022-07-20 13:01:36 +00:00
//q.unique_index; // Not legal on wildcard assoc - see t_assoc_wildcard_bad
// These require an with clause or are illegal
qv = q . find with ( item = = 2 ) ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{'h2, 'h2} " ) ;
2022-07-20 13:01:36 +00:00
qv = q . find_first with ( item = = 2 ) ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{'h2} " ) ;
2022-07-20 13:01:36 +00:00
qv = q . find_last with ( item = = 2 ) ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{'h2} " ) ;
2022-07-20 13:01:36 +00:00
qv = q . find with ( item = = 20 ) ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{} " ) ;
2022-07-20 13:01:36 +00:00
qv = q . find_first with ( item = = 20 ) ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{} " ) ;
2022-07-20 13:01:36 +00:00
qv = q . find_last with ( item = = 20 ) ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{} " ) ;
2022-07-20 13:01:36 +00:00
//q.find_index; // Not legal on wildcard assoc - see t_assoc_wildcard_bad
//q.find_first_index; // Not legal on wildcard assoc - see t_assoc_wildcard_bad
//q.find_last_index; // Not legal on wildcard assoc - see t_assoc_wildcard_bad
qv = q . min ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{'h1} " ) ;
2022-07-20 13:01:36 +00:00
qv = q . max ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{'h4} " ) ;
2022-07-20 13:01:36 +00:00
qv = qe . min ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{} " ) ;
2022-07-20 13:01:36 +00:00
qv = qe . max ;
2024-07-20 10:51:50 +00:00
`checkp ( qv , " '{} " ) ;
2022-07-20 13:01:36 +00:00
// Reduction methods
i = q . sum ;
`checkh ( i , 32 'hc ) ;
i = q . sum with ( item + 1 ) ;
`checkh ( i , 32 'h11 ) ;
i = q . product ;
`checkh ( i , 32 'h30 ) ;
i = q . product with ( item + 1 ) ;
`checkh ( i , 32 'h168 ) ;
i = qe . sum ;
`checkh ( i , 32 'h0 ) ;
i = qe . product ;
`checkh ( i , 32 'h0 ) ;
q = ' { 10 : 32 'b1100 , 11 : 32 'b1010 } ;
i = q . and ;
`checkh ( i , 32 'b1000 ) ;
i = q . and with ( item + 1 ) ;
`checkh ( i , 32 'b1001 ) ;
i = q . or ;
`checkh ( i , 32 'b1110 ) ;
i = q . or with ( item + 1 ) ;
`checkh ( i , 32 'b1111 ) ;
i = q . xor ;
`checkh ( i , 32 'b0110 ) ;
i = q . xor with ( item + 1 ) ;
`checkh ( i , 32 'b0110 ) ;
i = qe . and ;
2024-10-18 23:51:44 +00:00
`checkh ( i , 32 'h0 ) ;
i = qe . and with ( item + 1 ) ;
`checkh ( i , 32 'h0 ) ;
2022-07-20 13:01:36 +00:00
i = qe . or ;
`checkh ( i , 32 'b0 ) ;
2024-10-18 23:51:44 +00:00
i = qe . or with ( item + 1 ) ;
`checkh ( i , 32 'b0 ) ;
2022-07-20 13:01:36 +00:00
i = qe . xor ;
`checkh ( i , 32 'b0 ) ;
2024-10-18 23:51:44 +00:00
i = qe . xor with ( item + 1 ) ;
`checkh ( i , 32 'b0 ) ;
2022-07-20 13:01:36 +00:00
i = q . and ( ) ;
`checkh ( i , 32 'b1000 ) ;
i = q . and ( ) with ( item + 1 ) ;
`checkh ( i , 32 'b1001 ) ;
i = q . or ( ) ;
`checkh ( i , 32 'b1110 ) ;
i = q . or ( ) with ( item + 1 ) ;
`checkh ( i , 32 'b1111 ) ;
i = q . xor ( ) ;
`checkh ( i , 32 'b0110 ) ;
i = q . xor ( ) with ( item + 1 ) ;
`checkh ( i , 32 'b0110 ) ;
i = qe . and ( ) ;
`checkh ( i , 32 'b0 ) ;
i = qe . or ( ) ;
`checkh ( i , 32 'b0 ) ;
i = qe . xor ( ) ;
`checkh ( i , 32 'b0 ) ;
2024-10-18 23:51:44 +00:00
i = points_q . sum with ( vec_len_squared ( item ) ) ;
`checkh ( i , 32 'h2a ) ;
i = points_q . product with ( vec_len_squared ( item ) ) ;
`checkh ( i , 32 'h6a4 ) ;
b = points_q . sum with ( vec_len_squared ( item ) = = 5 ) ;
`checkh ( b , 1 'b1 ) ;
b = points_q . sum with ( vec_len_squared ( item ) = = 0 ) ;
`checkh ( b , 1 'b0 ) ;
b = points_q . product with ( vec_len_squared ( item ) inside { 5 , 17 } ) ;
`checkh ( b , 1 'b0 ) ;
b = points_q . sum with ( vec_len_squared ( item ) inside { 5 , 17 , 20 } ) ;
`checkh ( b , 1 'b1 ) ;
2022-07-20 13:01:36 +00:00
$write ( " *-* All Finished *-* \n " ) ;
$finish ;
end
endmodule