diff --git a/ivtest/gold/recursive_func_const.gold b/ivtest/gold/recursive_func_const.gold new file mode 100644 index 000000000..08e15931c --- /dev/null +++ b/ivtest/gold/recursive_func_const.gold @@ -0,0 +1,3 @@ +factorial 3 = 6 +factorial 4 = 24 +factorial 5 = 120 diff --git a/ivtest/ivltests/recursive_func_const1.v b/ivtest/ivltests/recursive_func_const1.v new file mode 100644 index 000000000..b45adebf3 --- /dev/null +++ b/ivtest/ivltests/recursive_func_const1.v @@ -0,0 +1,25 @@ +// Check that constant recursive functions are supported. + +module recursive_func(); + +function automatic [15:0] factorial; + +input [15:0] n; + +begin + factorial = (n > 1) ? factorial(n - 1) * n : n; +end + +endfunction + +localparam F3 = factorial(3); +localparam F4 = factorial(4); +localparam F5 = factorial(5); + +initial begin + $display("factorial 3 = %0d", F3); + $display("factorial 4 = %0d", F4); + $display("factorial 5 = %0d", F5); +end + +endmodule diff --git a/ivtest/ivltests/recursive_func_const2.v b/ivtest/ivltests/recursive_func_const2.v new file mode 100644 index 000000000..a7c3b92b9 --- /dev/null +++ b/ivtest/ivltests/recursive_func_const2.v @@ -0,0 +1,23 @@ +// Check that constant recursive functions are supported when the `return` +// statement is used. + +module recursive_func(); + +function automatic [15:0] factorial(input [15:0] n); + if (n > 1) begin + return factorial(n - 1) * n; + end + return n; +endfunction + +localparam F3 = factorial(3); +localparam F4 = factorial(4); +localparam F5 = factorial(5); + +initial begin + $display("factorial 3 = %0d", F3); + $display("factorial 4 = %0d", F4); + $display("factorial 5 = %0d", F5); +end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index ef58758eb..15ea67e72 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -403,6 +403,7 @@ program5b CE,-g2009 ivltests program_hello normal,-g2009 ivltests program_hello2 CE,-g2009 ivltests recursive_func2 normal,-g2005-sv ivltests gold=recursive_func.gold +recursive_func_const2 normal,-g2005-sv ivltests gold=recursive_func_const.gold sbyte_test normal,-g2005-sv ivltests scalar_vector normal,-g2005-sv ivltests sf_countbits normal,-g2012 ivltests diff --git a/ivtest/regress-vlg.list b/ivtest/regress-vlg.list index cfa4b3b1a..5f32b39d2 100644 --- a/ivtest/regress-vlg.list +++ b/ivtest/regress-vlg.list @@ -1470,6 +1470,7 @@ real_invalid_ops CE ivltests gold=real_invalid_ops.gold real_logical normal ivltests real_reg_force_rel normal ivltests recursive_func1 normal ivltests gold=recursive_func.gold +recursive_func_const1 normal ivltests gold=recursive_func_const.gold recursive_task normal ivltests gold=recursive_task.gold redef_net_error CE ivltests redef_reg_error CE ivltests diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index 8e5fcf2be..b70b1bd66 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -92,6 +92,8 @@ pr2929913 CE ivltests real_events CE ivltests recursive_func1 CE ivltests recursive_func2 CE ivltests +recursive_func_const1 CE ivltests +recursive_func_const2 CE ivltests recursive_task CE ivltests task_init_var1 CE,-pallowsigned=1 ivltests task_init_var2 CE,-pallowsigned=1 ivltests