#a randomize() with { ... } condition keeps its constraint block verbatim (ibex_mem_intf_response_seq_lib.sv:104) class c; task body(); if (!req.randomize() with { addr == item.addr; read_write == item.read_write; }) begin `uvm_fatal(`gfn, "Cannot randomize response request") end endtask endclass ---- class c; task body(); if (!req.randomize() with { addr == item.addr; read_write == item.read_write; }) begin `uvm_fatal(`gfn, "Cannot randomize response request") end endtask endclass ==== #std::randomize(x) with { ... } as an assignment right-hand side (cb_filter_tb.sv:272) module m; task automatic rand_wait(input int unsigned min, max); int unsigned rand_success, cycles; rand_success = std::randomize(cycles) with { cycles >= min; cycles <= max; }; endtask endmodule ---- module m; task automatic rand_wait(input int unsigned min, max); int unsigned rand_success, cycles; rand_success = std::randomize(cycles) with { cycles >= min; cycles <= max; }; endtask endmodule ==== #a dist { } inside the constraint block is part of the verbatim capture (ibex_mem_intf_response_driver.sv:94) class c; task body(); if (!std::randomize(gnt_delay) with { gnt_delay dist { cfg.gnt_delay_min :/ 10, [cfg.gnt_delay_min+1 : cfg.gnt_delay_max-1] :/ 5 }; }) begin `uvm_fatal(`gfn, "Cannot randomize grant") end endtask endclass ---- class c; task body(); if (!std::randomize(gnt_delay) with { gnt_delay dist { cfg.gnt_delay_min :/ 10, [cfg.gnt_delay_min+1 : cfg.gnt_delay_max-1] :/ 5 }; }) begin `uvm_fatal(`gfn, "Cannot randomize grant") end endtask endclass ==== #a constraint if inside the block is verbatim too (riscv_load_store_instr_lib.sv:79) class c; function void f(); if (!std::randomize(offset_, addr_) with { if (locality == NARROW) { soft offset_ inside {[-16:16]}; } else { soft offset_ inside {[-64:64]}; } addr_ == base + offset_; }) begin `uvm_fatal(`gfn, "Cannot randomize load/store offset") end endfunction endclass ---- class c; function void f(); if (!std::randomize(offset_, addr_) with { if (locality == NARROW) { soft offset_ inside {[-16:16]}; } else { soft offset_ inside {[-64:64]}; } addr_ == base + offset_; }) begin `uvm_fatal(`gfn, "Cannot randomize load/store offset") end endfunction endclass ==== #a string carrying a newline inside the constraint block survives byte for byte class c; function void f(); void'(std::randomize(x) with { msg == "line one line two"; x > 0; }); endfunction endclass ---- class c; function void f(); void'(std::randomize(x) with { msg == "line one line two"; x > 0; }); endfunction endclass ==== #a comment inside the constraint block stays inside it, and one after the block stays outside class c; function void f(); void'(std::randomize(x) with { // pick something small x < 4; }); // done endfunction endclass ---- class c; function void f(); void'(std::randomize(x) with { // pick something small x < 4; }); // done endfunction endclass ==== #a one-line constraint block stays on its line class c; function void f(); if (!req.randomize() with { addr == 0; }) $fatal(1, "no"); endfunction endclass ---- class c; function void f(); if (!req.randomize() with { addr == 0; }) $fatal(1, "no"); endfunction endclass ==== #array-method with (expr): sum, sort and find (riscv_reg.sv:79, dv_base_reg_block.sv:256) class c; function void f(); total_len = fld.sum() with (item.bit_width); mapped_addr_ranges.sort(m) with (m.start_addr); q = list.find() with (item > 3); n = list.find_index with (item.x == 1); endfunction endclass ---- class c; function void f(); total_len = fld.sum() with (item.bit_width); mapped_addr_ranges.sort(m) with (m.start_addr); q = list.find() with (item > 3); n = list.find_index with (item.x == 1); endfunction endclass ==== #foreach over a package-scoped array (riscv_instr.sv:156) class c; function void f(); foreach(riscv_instr_pkg::supported_isa[i]) begin basic_instr = {basic_instr, C_EBREAK}; end endfunction endclass ---- class c; function void f(); foreach (riscv_instr_pkg::supported_isa[i]) begin basic_instr = {basic_instr, C_EBREAK}; end endfunction endclass ==== #foreach over a hierarchical array with a select on the way (riscv_callstack_gen.sv:183, riscv_page_table_list.sv:130) class c; function void f(); foreach(program_h[id].sub_program_id[k]) begin program_h[id].sub_program_id[k] = sub_program_id_pool[idx]; end foreach(page_table[i].pte[j]) idx++; endfunction endclass ---- class c; function void f(); foreach (program_h[id].sub_program_id[k]) begin program_h[id].sub_program_id[k] = sub_program_id_pool[idx]; end foreach (page_table[i].pte[j]) idx++; endfunction endclass ==== #foreach over a literal index followed by a member select (csr_utils_pkg.sv:290) class c; function void f(); foreach (paths[0].slices[i]) str = $sformatf("%0s", paths[0].slices[i].path); endfunction endclass ---- class c; function void f(); foreach (paths[0].slices[i]) str = $sformatf("%0s", paths[0].slices[i].path); endfunction endclass ==== #a nested foreach whose inner array repeats the outer loop variable (core_ibex_test_lib.sv:483) class c; function void f(); foreach (data_valid[i]) begin foreach (data_valid[i][j]) data_valid[i][j] = 1'b0; end endfunction endclass ---- class c; function void f(); foreach (data_valid[i]) begin foreach (data_valid[i][j]) data_valid[i][j] = 1'b0; end endfunction endclass ==== #the multi-dimensional spelling puts every loop variable in one bracket group class c; function void f(); foreach (arr[i,j]) arr[i][j] = 0; endfunction endclass ---- class c; function void f(); foreach (arr[i, j]) arr[i][j] = 0; endfunction endclass ==== #randcase items are case items without a selector (uart_rx_oversample_vseq.sv:67) class c; task t(); randcase 1: pattern = (1 << num_bits) - 1; // all 1s 1: pattern = 0; endcase endtask endclass ---- class c; task t(); randcase 1: pattern = (1 << num_bits) - 1; // all 1s 1: pattern = 0; endcase endtask endclass ==== #a randcase item may be a begin/end block, and comments keep their place (uart_base_vseq.sv:236) class c; task t(); randcase // read one byte 1: begin csr_rd(.ptr(ral.fifo_status), .value(fifo_status)); end 5: drive_line_loopback(); // nothing left to read endcase endtask endclass ---- class c; task t(); randcase // read one byte 1: begin csr_rd(.ptr(ral.fifo_status), .value(fifo_status)); end 5: drive_line_loopback(); // nothing left to read endcase endtask endclass ==== #case-missing-default does not fire on a randcase: it has no default arm class c; task t(); randcase 1: a = 0; 1: a = 1; endcase endtask endclass ---- class c; task t(); randcase 1: a = 0; 1: a = 1; endcase endtask endclass ==== #wait fork; inside an isolation fork (dv_base_vseq.sv:96) class c; task t(); fork begin : isolation_fork fork apply_reset(); join_none wait fork; end : isolation_fork join endtask endclass ---- class c; task t(); fork begin : isolation_fork fork apply_reset(); join_none wait fork; end : isolation_fork join endtask endclass ==== #wait fork as the body of an if, and an ordinary wait (expr) beside it (csr_utils_pkg.sv:462) class c; task t(); if (blocking) wait fork; wait (done == 1); wait (ready) x = 1; endtask endclass ---- class c; task t(); if (blocking) wait fork; wait (done == 1); wait (ready) x = 1; endtask endclass ==== #a comment written before else stays on the else's left class c; task t(); if (blocking) wait fork; // Add #0 to ensure that this thread starts executing first else #0; endtask endclass ---- class c; task t(); if (blocking) wait fork; // Add #0 to ensure that this thread starts executing first else #0; endtask endclass ==== #import as the first statement of a function body (dv_base_reg_field.sv:97) class c; function uvm_reg_data_t mubi_or_hi(uvm_reg_data_t a); import prim_mubi_pkg::*; uvm_reg_data_t out; return out; endfunction endclass ---- class c; function uvm_reg_data_t mubi_or_hi(uvm_reg_data_t a); import prim_mubi_pkg::*; uvm_reg_data_t out; return out; endfunction endclass ==== #imports among a block's declarations (mem_bkdr_util.sv:154) class c; function void f(); if (`HAS_ECC) begin import prim_secded_pkg::prim_secded_e; import prim_secded_pkg::get_ecc_data_width, prim_secded_pkg::get_ecc_parity_width; prim_secded_e secded_eds; end endfunction endclass ---- class c; function void f(); if (`HAS_ECC) begin import prim_secded_pkg::prim_secded_e; import prim_secded_pkg::get_ecc_data_width, prim_secded_pkg::get_ecc_parity_width; prim_secded_e secded_eds; end endfunction endclass ==== #a let declaration at module scope (clk_int_div_tb.sv:53) module m; let max(a,b) = (a > b) ? a : b; let min(a,b) = (a < b) ? a : b; endmodule ---- module m; let max(a, b) = (a > b) ? a : b; let min(a, b) = (a < b) ? a : b; endmodule ==== #a let with typed ports, a default, and the port-less spelling module m; let f(int a, untyped b = 0) = a + b; let ready = valid && !stall; endmodule ---- module m; let f(int a, untyped b = 0) = a + b; let ready = valid && !stall; endmodule ==== #an omitted positional argument keeps its place in the list (riscv_instr_base_test.sv:88) class c; function void f(); asm_gen = riscv_asm_program_gen::type_id::create("asm_gen", , `gfn); endfunction endclass ---- class c; function void f(); asm_gen = riscv_asm_program_gen::type_id::create("asm_gen", , `gfn); endfunction endclass ==== #a labeled immediate assertion (addr_decode_tb.sv:98) module m; always @(addr) #0 begin : proc_check_decode check_decode: assert (idx == addr_map[0].idx) passed_checks++; else begin failed_checks++; $warning("Decoder did not decode correctly."); end end endmodule ---- module m; always @(addr) #0 begin : proc_check_decode check_decode: assert (idx == addr_map[0].idx) passed_checks++; else begin failed_checks++; $warning("Decoder did not decode correctly."); end end endmodule ==== #a label on an ordinary statement, and one on a block module m; initial begin step_one: x = 1; step_two: begin y = 2; end end endmodule ---- module m; initial begin step_one: x = 1; step_two: begin y = 2; end end endmodule ==== #a label in front of a concurrent assertion stays part of the verbatim capture module m; initial begin NoNMI: assert property (@(posedge clk) a |-> b) else $error("nmi"); end endmodule ---- module m; initial begin NoNMI: assert property (@(posedge clk) a |-> b) else $error("nmi"); end endmodule ==== #a case item label is not a statement label module m; initial begin case (x) FOO: begin y = 1; end default: y = 0; endcase end endmodule ---- module m; initial begin case (x) FOO: begin y = 1; end default: y = 0; endcase end endmodule ==== #a stray semicolon after an endtask label is printed where it was written (ibex_cosim_scoreboard.sv:307) class c; task run_cosim_imem_errors(); x = 1; endtask: run_cosim_imem_errors; function void f(); endfunction : f; endclass ---- class c; task run_cosim_imem_errors(); x = 1; endtask : run_cosim_imem_errors; function void f(); endfunction : f; endclass ==== #the whole cluster inside a format-off fence comes out byte-exact module m; // verilog_format: off let max(a,b) = (a>b)?a:b; initial begin foreach( pkg::arr[i] ) x=1; randcase 1: y=0; endcase if(!r.randomize() with { a==1; }) $fatal(1,"x"); end // verilog_format: on initial x = 1; endmodule ---- module m; // verilog_format: off let max(a,b) = (a>b)?a:b; initial begin foreach( pkg::arr[i] ) x=1; randcase 1: y=0; endcase if(!r.randomize() with { a==1; }) $fatal(1,"x"); end // verilog_format: on initial x = 1; endmodule ==== #a with-block condition whose tail still fits stays on the block's last line class c; task t; if (req.randomize() with { addr == 32'h1000; } && cfg.enable_the_long_named_feature_flag && other_condition_name_goes_right_here) begin z = 1; end endtask endclass ---- class c; task t; if (req.randomize() with { addr == 32'h1000; } && cfg.enable_the_long_named_feature_flag && other_condition_name_goes_right_here) begin z = 1; end endtask endclass ==== #a with-block condition whose tail overflows wraps (printer fits() past a multi-line Inline) class c; task t; if (req.randomize() with { addr == 32'h1000; } && cfg.enable_the_long_named_feature_flag && other_condition_name_goes_right_here_ok) begin z = 1; end endtask endclass ---- class c; task t; if ( req.randomize() with { addr == 32'h1000; } && cfg.enable_the_long_named_feature_flag && other_condition_name_goes_right_here_ok ) begin z = 1; end endtask endclass ==== # comments at every boundary of a `randomize() with { ... }` and of an # array-method `with (expr)`: before the `(`, inside the empty `()`, before # `with`, and between `with` and the block class c; task t; y = x.randomize /*c1*/ ( /*c2*/ ) /*c3*/ with /*c4*/ {a == 1;}; z = q.sum() /*c5*/ with /*c6*/ (item.w); endtask endclass ---- class c; task t; y = x.randomize /*c1*/ ( /*c2*/ ) /*c3*/ with /*c4*/ {a == 1;}; z = q.sum() /*c5*/ with /*c6*/ (item.w); endtask endclass ====