Close Menu
VLSI Web
  • Home
    • About Us
    • Contact Us
    • Privacy Policy
  • Digital Design
    • Digital Circuits
    • Verilog
    • VHDL
    • System Verilog
    • UVM
  • VLSI Roles
    • RTL Design
    • Design Verification
    • Physical Design
    • DFT
    • STA
  • Interviews
  • Informative
  • VLSI Forge
Instagram LinkedIn WhatsApp Telegram
Instagram LinkedIn WhatsApp Telegram
VLSI Web
  • Home
    • About Us
    • Contact Us
    • Privacy Policy
  • Digital Design
    • Digital Circuits
    • Verilog
    • VHDL
    • System Verilog
    • UVM
  • VLSI Roles
    • RTL Design
    • Design Verification
    • Physical Design
    • DFT
    • STA
  • Interviews
  • Informative
  • VLSI Forge
VLSI Web
System Verilog

Tasks and Functions in SystemVerilog: ref, void, Defaults and More

Raju GorlaBy Raju Gorla7 July 2026Updated:11 October 2026No Comments3 Mins Read
Tasks and functions in SystemVerilog
Share
Facebook Twitter LinkedIn Email Telegram WhatsApp

The short answer: SystemVerilog keeps Verilog’s rule that functions run in zero time and tasks may consume time, and adds the return statement, void functions, default and named arguments, pass-by-reference with ref and const ref, ANSI-style typed arguments (including structs, arrays and classes) and automatic storage by default in classes. Use ref when a task must see a variable change while it’s running, or to avoid copying large arrays.

The basics of tasks and functions are covered in my Verilog tasks and functions post. Here I focus on what SystemVerilog adds, because those additions are exactly what testbench code relies on.

  1. What’s new
  2. return and void functions
  3. Default and named arguments
  4. Pass by reference: ref and const ref
  5. Static vs automatic
  6. Tasks and functions in RTL

Table of Contents

  • Part 1: What’s new
  • Part 2: return and void functions
  • Part 3: Default and named arguments
  • Part 4: Pass by reference: ref and const ref
  • Part 5: Static vs automatic
  • Part 6: Tasks and functions in RTL
  • FAQ
    • What is a void function in SystemVerilog?
    • What does ref mean in a SystemVerilog argument?
    • Why must ref arguments be in automatic subroutines?
    • Can I pass a class object to a function?

Part 1: What’s new

SystemVerilog task and function improvements: return, void functions, default and named arguments, ref arguments, ANSI-style typed arguments and automatic
Six improvements over Verilog.

Part 2: return and void functions

function automatic int max3(int a, int b, int c);
  if (a >= b && a >= c) return a;
  return (b >= c) ? b : c;
endfunction

function void print_pkt(packet p);   // no return value
  $display("len=%0d", p.len);
endfunction

void'(some_function());               // discard a return value explicitly

Part 3: Default and named arguments

task automatic send(input logic [7:0] data,
                    input int delay = 0,
                    input bit last  = 1'b1);
  ...
endtask

send(8'hA5);                       // delay = 0, last = 1
send(.data(8'h3C), .last(1'b0));   // named, any order

Part 4: Pass by reference: ref and const ref

// waits until a flag set by another thread becomes true
task automatic wait_flag(ref bit flag);
  wait (flag);
endtask

// no copy of a large array, and the callee can't modify it
function automatic int sum(const ref int data[]);
  foreach (data[i]) sum += data[i];
endfunction
  • With input, the argument is copied at the call, so later changes aren’t seen. With ref, the task sees every change immediately.
  • ref arguments are only allowed in automatic tasks and functions.
  • const ref is the efficient way to pass big arrays or queues read-only.

Part 5: Static vs automatic

Module-level tasks and functions are still static by default, as in Verilog. Methods inside classes are automatic by default. My habit: write automatic on every module-level task and function in testbenches, so parallel calls don’t share variables by accident.

Part 6: Tasks and functions in RTL

Functions remain synthesisable when their body is: they’re useful in always_comb blocks and packages for things like parity, encoding and saturating arithmetic. Tasks in RTL are rare. Keep testbench tasks (with @, # or wait) in testbench files or classes.

Practise this on VLSI Forge

I built VLSI Forge so you can write RTL in your browser, run it on a real simulator and check every signal in the waveform. Free, nothing to install.

Design Verification problems · RTL Design problems

Previous in my SystemVerilog series: SystemVerilog for RTL design. Next: Interfaces, modports and clocking blocks.

FAQ

What is a void function in SystemVerilog?

A function that returns nothing. It still executes in zero time, so it can be called from other functions, unlike a task.

What does ref mean in a SystemVerilog argument?

Pass by reference: the subroutine works on the caller’s variable directly, so changes are visible both ways immediately.

Why must ref arguments be in automatic subroutines?

Because each call needs its own reference; static subroutines share a single set of variables between calls.

Can I pass a class object to a function?

Yes. Class handles are passed by value, but the handle points to the same object, so the function can change the object’s properties.

System Verilog functions System Verilog programming System Verilog tasks Verilog design methodologies Verilog functions Verilog programming techniques Verilog tasks
Share. Facebook Twitter LinkedIn Email Telegram WhatsApp
Previous ArticleSystemVerilog for RTL Design: always_ff, always_comb, Packages and More
Next Article SystemVerilog Interfaces, Modports and Clocking Blocks
Raju Gorla
  • Website

Related Posts

Verilog

Tasks and Functions in Verilog: Differences, Arguments and Examples

31 July 2026
System Verilog

Design Patterns in SystemVerilog Testbenches: Factory, Callbacks and More

16 July 2026
System Verilog

DPI in SystemVerilog: Calling C from Your Testbench (and Back)

15 July 2026
Add A Comment
Leave A Reply Cancel Reply

Topics
  • Digital Circuits
  • Informative
  • Interview Questions
  • Physical Design
  • RTL Design
  • STA
  • System Verilog
  • UVM
  • Verilog
Instagram LinkedIn WhatsApp Telegram
  • About
  • Contact
  • Privacy Policy
  • VLSI Forge
  • Courses
  • Feedback
© 2026 VLSI Web

Type above and press Enter to search. Press Esc to cancel.