Skip to main content

UVM Utility Field Macros

· loading · loading · ·
Education UVM Verification UVM Verification SystemVerilog Utility Macros
Education UVM Verification
Axolot Logic
Author
Axolot Logic
Digital Design Engineer
Table of Contents
UVM Series - This article is part of a series.
Part 5: This Article

🛠️ UVM Utility Field Macros
#

🚀 Introduction
#

UVM Utility Field Macros are powerful tools that automatically generate essential object methods like copy, compare, print, and pack/unpack. Instead of manually implementing each method, you can simply declare your fields and gain full object functionality effortlessly.


🗂️ Basic Macro Usage
#

Using Object Utils with Multiple Field Types
#

Below is a single, comprehensive example that combines different data types—integers, strings, dynamic arrays, queues, and enums—demonstrating how to use UVM Utility Field Macros efficiently:

typedef enum {IDLE, ACTIVE, ERROR} state_e;

class all_fields_example extends uvm_object;
  // Scalar fields
  int timeout;
  bit [7:0] data;
  
  // String fields
  string name;
  string description;
  
  // Dynamic array
  bit [15:0] payload[];
  
  // Queue
  int values[$];
  
  // Enum
  state_e current_state;

  `uvm_object_utils_begin(all_fields_example)
    // 🔹 Integer fields
    `uvm_field_int(timeout, UVM_ALL_ON | UVM_DEC)
    `uvm_field_int(data, UVM_ALL_ON | UVM_HEX)
    
    // 🔹 String fields
    `uvm_field_string(name, UVM_ALL_ON)
    `uvm_field_string(description, UVM_ALL_ON | UVM_NOCOMPARE)
    
    // 🔹 Dynamic array field
    `uvm_field_array_int(payload, UVM_ALL_ON | UVM_HEX)
    
    // 🔹 Queue field
    `uvm_field_queue_int(values, UVM_ALL_ON | UVM_DEC)
    
    // 🔹 Enum field
    `uvm_field_enum(state_e, current_state, UVM_ALL_ON)
  `uvm_object_utils_end

  function new(string name = "all_fields_example");
    super.new(name);
    current_state = IDLE;
  endfunction
endclass

🏷️ Field Automation Flags
#

Key Flag Categories
#

FlagDescription
UVM_ALL_ONEnables all operations (copy, compare, print, pack, record)
UVM_COPYIncludes in the copy() method
UVM_COMPAREIncludes in the compare() method
UVM_PRINTIncludes in the print() method
UVM_PACKIncludes in the pack() and unpack() methods
UVM_RECORDIncludes in the record() method
UVM_NOCOPYExcludes from copy()
UVM_NOCOMPAREExcludes from compare()
UVM_NOPRINTExcludes from print()
UVM_HEXPrints in hexadecimal format
UVM_BINPrints in binary format
UVM_NORANDExcludes from randomization

🚀 Summary
#

FeatureUtility MacroField Macro
PurposeAdds basic UVM functions to a class.Registers class variables for UVM automation.
Usageuvm_object_utils, uvm_component_utilsuvm_field_int, uvm_field_string
FunctionsAdds methods like print(), copy(), compare().Defines how these methods process specific fields.
PerformanceFaster (only adds basic functions).Slower (processes fields at runtime).
  • uvm_component_utils for component class and its child classes
  • uvm_object_utils for object class and its child classes

🔹 Using UVM Field Macros:
✅ Rapid object development
✅ One-line automation for methods (copy, compare, print, pack)
✅ Less manual code
✅ Fewer errors


UVM Series - This article is part of a series.
Part 5: This Article

Related

UVM Agent Usage and Adder Example
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_agent Testbench Structure
Education UVM Verification
UVM Base Classes
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Class Hierarchy
Education UVM Verification
UVM Driver Usage and Adder Example
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_driver Stimulus Driving
Education UVM Verification
UVM Environment Usage and adder_env Example
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_env Testbench Structure
Education UVM Verification
UVM Monitor Usage and Adder Example
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_monitor Coverage
Education UVM Verification
UVM Object Class
· loading · loading
Education UVM Verification UVM Verification SystemVerilog Uvm_object
Education UVM Verification