UPF in One Picture: Power Intent, Versions and the Tcl Subset

Write power intent in a file beside the RTL, name its edition, and let Tcl write the repetitive parts.

You Will Be Able To

  • Explain why power intent lives in a UPF file beside the RTL, and which tools read that file.
  • Declare the edition of a UPF file with upf_version, and say why the edition can change its meaning.
  • Read a refusal from OpenPA and fix the line it names.
  • Use Tcl variables, lists, foreach and proc to write repeated UPF commands once.
Lesson
W4.1
Time
25 min
Runs on
Your browser
Check
6 questions

The RTL of pmu_soc has no supply pins and no power logic. Yet three lines of UPF make the whole design go unknown when its supply drops.

The RTL: unchanged, power-unaware

// pmu_soc.sv, pmu.sv, core.sv
// no supply, no isolation,
// no retention in the RTL
module pmu_soc ( ... );
  pmu  u_pmu  ( ... );
  core u_core ( ... );
endmodule

Says what the logic does.

pmu_soc.upf: the power intent

upf_version 4.0
set_design_top pmu_soc
create_power_domain PD_TOP -include_scope

Says how the logic is powered.

Two files, one design. The UPF file names the edition, the design it was written for and one power domain.

In the lab, the accumulator reads 33 after three beats. When the bench turns the domain's supply off, it reads xx.

Power Intent Lives Beside the RTL

Power intent says which parts of a chip can switch off and what feeds them. It also says what protects the parts that stay on. UPF writes it in a separate file.

One UPF File, Read by Every Tool in the FlowArrows show which files each tool reads. The RTL and the UPF file stay separate all the way.
  • Design
  • File
  • Step
  • Structure
One UPF file, read by every tool in the flowArrows show which files each tool reads. The RTL and the UPF file stay separate all the way. design RTL power-unaware file pmu_soc.upf power intent step Simulation power-aware run step Synthesis inserts cells step Place and route builds the supply grid step Equivalence check RTL against netlist
  1. design RTLpower-unaware
    • Simulation
    • Synthesis
  2. file pmu_soc.upfpower intent
    • Simulation
    • Synthesis
    • Place and route
    • Equivalence check
  3. step Simulationpower-aware run
  4. step Synthesisinserts cells
  5. step Place and routebuilds the supply grid
  6. step Equivalence checkRTL against netlist
  1. Two inputs

    The RTL describes what the logic does. The UPF file describes how it is powered.

  2. Simulation

    A power-aware simulation corrupts the logic of a domain whose supply is off. On this site OpenPA does that.

  3. Implementation

    Synthesis and place and route read the same file. They insert the cells and build the supply network it describes.

  4. Sign-off

    An equivalence check compares the RTL with the netlist and needs the UPF to know which cells were added on purpose.

Read the diagram as text
  • RTL: power-unaware
  • pmu_soc.upf: power intent
  • Simulation: power-aware run
  • Synthesis: inserts cells
  • Place and route: builds the supply grid
  • Equivalence check: RTL against netlist
  • RTL → Simulation
  • pmu_soc.upf → Simulation
  • RTL → Synthesis
  • pmu_soc.upf → Synthesis
  • pmu_soc.upf → Place and route
  • pmu_soc.upf → Equivalence check

IEEE 1801 defines UPF so that one description serves verification and implementation. Si2 donated its CPF format to the same standard.

The first lines of a UPF file say what it is about:

LineWhat it doesStandard
upf_version 4.0Says which edition of UPF the commands below follow.IEEE 1801-2024 6.61
set_design_top pmu_socNames the module the file was written for. A tool may warn if it is applied elsewhere.6.45
create_power_domain PD_TOP -include_scopeMakes one power domain: the current scope and everything below it.6.21 (W4.3)

The three lines of pmu_soc.upf. W4.3 covers power domains in full.

Here is what OpenPA builds from those three lines. This is a recorded run of the lab's file:

OpenPA 0.3.0 report for the three-line file (recorded).
Power domains
  PD_TOP (pmu_soc.upf:3): pmu_soc, u_core, u_pmu
    primary supply PD_TOP.primary: power PD_TOP.primary.power, ground PD_TOP.primary.ground
    4 register(s): status, u_core.acc, u_core.beats, u_pmu.st; 1 memory(ies): u_core.rf[4x8]

Supply network
  PD_TOP.primary.power: root PD_TOP.primary.power  {fn:PD_TOP.primary.power}
  PD_TOP.primary.ground: root PD_TOP.primary.ground  {fn:PD_TOP.primary.ground}

One domain holds the top, u_pmu and u_core. Its supply has no source in the file, so the bench drives it by name. While that supply is off, every register in the domain is corrupted to X.

Editions of UPF and upf_version

UPF has had six editions and one amendment in about eighteen years. Each added commands, and some changed defaults.

Edition yearEditionVersion stringPlace in the sequence
2007Accellera UPF 1.01.0The first command set: domains, supply nets, isolation, retention, set_scope, load_upf
2009IEEE 1801-20092.0The first IEEE edition
2013IEEE 1801-20132.1A revision of the IEEE standard
2014IEEE 1801a-20142.2An amendment to the 2013 edition
2015IEEE 1801-20153.0A revision of the IEEE standard
2018IEEE 1801-20183.1A revision of the IEEE standard
2024IEEE 1801-20244.0Virtual supplies, refinable macros, better retention models. This site follows it.

Timeline from the DVCon paper that introduced 1801-2024 (paper 10002, slide 5). Si2 also donated its CPF 2.0 and 2.1 formats along the way. Edition years identify the standards; they need not be publication years.

The command upf_version names the edition a file follows. IEEE 1801-2024 defines one string for itself: "4.0" (6.61). A year is not a version:

OpenPA on upf_version 2009 (recorded).
pmu_soc.upf:1: upf_version 2009: OpenPA knows 1.0, 2.0, 2.1, 3.0, 3.1 and 4.0 (IEEE 1801-2024 6.61 defines "4.0")

Why the edition matters: some defaults changed between editions. Take an isolation strategy with no -applies_to option. IEEE 1801-2024 applies it to inputs and outputs (6.48). UPF 1.0 applied it to outputs only (6.25).

The same file, read asIsolated crossingsWhere the cells go
upf_version 4.012every output of PD_CORE and every input into it
upf_version 1.06the outputs of PD_CORE only

Recorded OpenPA runs of one file that differ only in the version line. The crossing lists are in the review notes of this page.

Reading a File Pasted from a Slide

UPF files are often built from slides and PDFs. Those turn ASCII characters into typographic ones that look alike. A Tcl reader then sees different words.

Three lines of a pasted file, with three defects.
set_design_top “pmu_soc”
create_power_domain PD_TOP –include_scope
set_isolation ISO_CORE -domain PD_CORE -clamp_value 0 -isolation_power_net VDD_N -isolation_ground_net VSS_N -isolation_signal u_pmu/iso_en -isolation_sence high -location parent

OpenPA stops at the first error and names the file and line. Fix that line, run again, and read the next message.

Four runs of the pasted file, one fix between each (recorded, OpenPA 0.3.0).
# run 1
pmu_soc.upf:2: character U+201C is a curly quote (write "); it usually comes from copying UPF out of a slide or PDF

# run 2: the quotes retyped
pmu_soc.upf:3: character U+2013 is an en dash (write "-"); it usually comes from copying UPF out of a slide or PDF

# run 3: the dash retyped
pmu_soc.upf:15: set_isolation: unknown option "-isolation_sence"; this command takes -domain -elements -exclude_elements -applies_to -applies_to_boundary -clamp_value -isolation_signal -isolation_sense -isolation_power_net -isolation_ground_net -isolation_supply -isolation_supply_set -location -source -sink -diff_supply_only -use_functional_equivalence -no_isolation -force_isolation -name_prefix -name_suffix -update

# run 4: -isolation_sense spelled right
Strategies
  set_isolation ISO_CORE (pmu_soc.upf:15): clamp 0, enable u_pmu.iso_en active high, supply {VDD_N VSS_N}, location parent
Looks likeIs reallyRetype as
“ ” (curly quotes)U+201C and U+201Dstraight quotes or braces
– (en dash)U+2013the ASCII minus sign -
a misspelled optiona word the command does not takethe option the message lists

The three defects of the pasted file, in the order OpenPA reported them.

UPF Is Tcl: Variables, Lists, Loops and Procs

A UPF file is a Tcl script (IEEE 1801-2024 5.1). UPF commands run in order, like any Tcl command. So variables, lists, foreach, if, expr and proc may build the commands.

The design hub has three units: u_cpu, u_dsp and u_npu. Each needs its own switchable domain, with the same four lines. A proc writes them once:

hub.upf: one proc, called from a foreach loop.
# One switchable domain per unit, made by a proc
proc switched_domain {unit} {
  set U [string toupper $unit]
  create_power_domain PD_$U -elements [list u_$unit]
  create_supply_net VDD_$U
  create_power_switch SW_$U -domain PD_$U \
      -input_supply_port {i VDD_N} -output_supply_port [list o VDD_$U] \
      -control_port [list c pwr_$unit] -on_state {on i {c}} -off_state {off {!c}}
  set_domain_supply_net PD_$U -primary_power_net VDD_$U -primary_ground_net VSS_N
}
foreach unit {cpu dsp npu} {
  switched_domain $unit
}
Tcl pieceIn this fileWhat it gives
proc name {args} {body}switched_domain {unit}A new command, run once per call
set and $nameset U [string toupper $unit]cpu becomes CPU, so names read PD_CPU and SW_CPU
[ ... ] command substitution[list u_$unit]The result of a command, used as a word
foreach var list {body}foreach unit {cpu dsp npu}The body runs three times
if {cond} {...} and exprif {$width > 8} { set mode wide } else { set mode narrow }Choose a branch; expr computes a value
string match pattern valuestring match data* $nameReturns 1 when the name matches, otherwise 0

The Tcl that production UPF files use most.

OpenPA runs the Tcl first and records each UPF command it produces. The report shows the three domains it built. Every one points to line 16, the line inside the proc:

OpenPA report for hub.upf (recorded).
Power domains
  PD_TOP (hub.upf:4): hub
    primary supply PD_TOP.primary: power VDD_N, ground VSS_N
    1 register(s): seen; 0 memory(ies)
  PD_CPU (hub.upf:16): u_cpu
    primary supply PD_CPU.primary: power VDD_CPU, ground VSS_N  [switchable]
    1 register(s): u_cpu.acc; 0 memory(ies)
  PD_DSP (hub.upf:16): u_dsp
    primary supply PD_DSP.primary: power VDD_DSP, ground VSS_N  [switchable]
    1 register(s): u_dsp.acc; 0 memory(ies)
  PD_NPU (hub.upf:16): u_npu
    primary supply PD_NPU.primary: power VDD_NPU, ground VSS_N  [switchable]
    1 register(s): u_npu.acc; 0 memory(ies)

An error inside a loop names the line inside the proc. Add a unit gpu that the design does not have:

Recorded.
hub.upf:16: create_power_domain PD_GPU -elements: no instance "u_gpu" under scope "hub"
CommandIEEE 1801-2024OpenPA 0.3.0
execAllowed: 5.1 asks for a full Tcl interpreter, 8.4 or laterexec is refused: a UPF file must not run programs
sourceAllowedsource is refused; use load_upf (with -scope if needed)
Files, sockets, regexpAllowedRefused, each with its line
proc, foreach, if, expr, lists, strings, arraysAllowedSupported
find_objectsThe one way to read the design from Tcl (5.1, 6.33)Not built yet (lesson W4.2)

Standard behaviour against OpenPA's. The site runs files from any visitor, so OpenPA's Tcl cannot run programs or read files.

Asked in interviews
  1. Why keep power intent out of the RTL?

    One file then drives simulation, synthesis, place and route and equivalence checks. The RTL stays reusable under another power architecture, and no tool guesses at hand-written power logic.

  2. What does upf_version do?

    It names the edition the commands follow and returns the edition the tool uses. IEEE 1801-2024 defines "4.0". Defaults differ between editions, so the line matters.

  3. Can a UPF file contain loops and procs?

    Yes. UPF is Tcl, so a proc can write a strategy once and a loop can apply it to many domains. The tool records the commands the script produces.

Try It

Run it. The bench turns the top domain's supply on, resets, runs three beats, then turns the supply off and on again.

Read the lines supply off and supply back. The registers go to X when the supply drops, and stay X until the reset.

Open What UPF added. Three lines of UPF added no cells: only corruption of the registers in PD_TOP.

Move the supply_off line before the three beats. Predict acc after them, then run.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: OPENPA-INFO corruption=x seed=1 supply on acc=xx beats=x total=xx pmu_state=x three beats acc=33 beats=3 total=33 pmu_state=0 supply off acc=xx beats=x total=xx pmu_state=x supply back acc=xx beats=x total=xx pmu_state=x after reset acc=0 beats=0 total=0 pmu_state=0 OPENPA-SUMMARY D1=0 D2=0 D3=0 D4=0 D5=0 D6=0 D7=0 D8=0 D9=0 D10=0 D11=0 D12=0 D13=0 D14=0 OPENPA-COVER-SUMMARY states=0/0 declared_transitions=0/0 sequences=0/0
Read the power intent: pmu_soc.upf
upf_version 4.0
set_design_top pmu_soc
create_power_domain PD_TOP -include_scope
Read the power-unaware RTL: pmu_soc.sv
// pmu_soc: two power domains. The top and the controller are always on; u_core can be switched off.
// The RTL is power-unaware: no isolation cell, no supply, no retention register is written here.
module pmu_soc (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       sleep_req,
  input  logic       wake_req,
  input  logic       en,
  input  logic [7:0] d,
  input  logic [1:0] rf_addr,
  input  logic       rf_we,
  output logic [7:0] total,
  output logic       led,
  output logic [7:0] rd,
  output logic [3:0] beats,
  output logic [7:0] status,
  output logic [2:0] pmu_state
);
  logic iso_en, save, restore, pwr_en, core_rst_n;
  logic [7:0] acc, rf_rd;
  logic busy;
  logic [3:0] core_beats;

  pmu u_pmu (
    .clk        (clk),
    .rst_n      (rst_n),
    .sleep_req  (sleep_req),
    .wake_req   (wake_req),
    .iso_en     (iso_en),
    .save       (save),
    .restore    (restore),
    .pwr_en     (pwr_en),
    .core_rst_n (core_rst_n),
    .state_o    (pmu_state)
  );

  core u_core (
    .clk     (clk),
    .rst_n   (core_rst_n),
    .en      (en),
    .d       (d),
    .rf_addr (rf_addr),
    .rf_we   (rf_we),
    .acc     (acc),
    .rf_rd   (rf_rd),
    .busy    (busy),
    .beats   (core_beats)
  );

  // Always-on consumers of the core's outputs.
  assign total = acc;
  assign led   = busy;
  assign rd    = rf_rd;
  assign beats = core_beats;
  // A status register: keeps the last accumulator value seen while the core was busy.
  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) status <= '0;
    else if (busy) status <= acc;
endmodule
Read the power-unaware RTL: pmu.sv
// pmu_soc: the always-on power controller. Power-unaware RTL: it only drives control signals.
// Sleep: isolate, save, switch off. Wake: switch on, reset, restore, release isolation.
module pmu (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       sleep_req,
  input  logic       wake_req,
  output logic       iso_en,
  output logic       save,
  output logic       restore,
  output logic       pwr_en,
  output logic       core_rst_n,
  output logic [2:0] state_o
);
  typedef enum logic [2:0] { RUN, ISOLATE, SAVE, OFF, PWRUP, RESET, RESTORE, RELEASE } st_e;
  st_e st;
  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) st <= RUN;
    else case (st)
      RUN:     if (sleep_req) st <= ISOLATE;
      ISOLATE: st <= SAVE;
      SAVE:    st <= OFF;
      OFF:     if (wake_req) st <= PWRUP;
      PWRUP:   st <= RESET;
      RESET:   st <= RESTORE;
      RESTORE: st <= RELEASE;
      RELEASE: st <= RUN;
      default: st <= RUN;
    endcase
  assign iso_en     = (st != RUN);
  assign save       = (st == SAVE);
  assign restore    = (st == RESTORE);
  assign pwr_en     = !(st == OFF);
  assign core_rst_n = rst_n && (st != RESET);
  assign state_o    = st;
endmodule
Read the power-unaware RTL: core.sv
// pmu_soc: the switchable core. An accumulator, a beat counter and a 4-word register file.
// Power-unaware RTL: nothing here knows about supplies.
module core (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       en,
  input  logic [7:0] d,
  input  logic [1:0] rf_addr,
  input  logic       rf_we,
  output logic [7:0] acc,
  output logic [7:0] rf_rd,
  output logic       busy,
  output logic [3:0] beats
);
  logic [7:0] rf [0:3];
  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) begin
      acc   <= '0;
      beats <= '0;
    end else if (en) begin
      acc   <= acc + d;
      beats <= beats + 4'd1;
    end
  always_ff @(posedge clk)
    if (rf_we) rf[rf_addr] <= acc;
  assign rf_rd = rf[rf_addr];
  assign busy  = en;
endmodule
What UPF added: 8 objects

2 supply net, 1 supply set, 4 register corruption, 1 memory corruption.

ObjectWhereDetailRuleUPF line
Supply netPD_TOP.primary.power
Supply netPD_TOP.primary.ground
Supply setPD_TOP.primarypmu_soc.upf:3
Register corruptionstatusC1pmu_soc.upf:3
Register corruptionu_core.accC1pmu_soc.upf:3
Register corruptionu_core.beatsC1pmu_soc.upf:3
Register corruptionu_pmu.stC1pmu_soc.upf:3
Memory corruptionu_core.rfC1pmu_soc.upf:3

OpenPA warnings:

  • pmu_soc.upf:3 power domain PD_TOP primary power: supply net PD_TOP.primary.power has no source in the UPF (no top-level input supply port or switch output); it is an implicit supply net (IEEE 1801-2024 6.27.2). It is OFF until the bench drives it: supply_on("PD_TOP.primary.power", volts) or set_supply_state("PD_TOP.primary.power", FULL_ON)
  • pmu_soc.upf:3 power domain PD_TOP primary ground: supply net PD_TOP.primary.ground has no source in the UPF (no top-level input supply port or switch output); it is an implicit supply net (IEEE 1801-2024 6.27.2). It is OFF until the bench drives it: supply_on("PD_TOP.primary.ground", volts) or set_supply_state("PD_TOP.primary.ground", FULL_ON)
  • no `timescale in the design and no --timescale: OpenPA messages print time in the design top's default unit
Read the power-aware copy that runs (generated by OpenPA 0.3.0): pa_pmu_soc.sv
// pa_pmu_soc.sv: power-aware copy of pmu_soc, generated by OpenPA from pmu_soc.upf.
// Do not edit: regenerate. Simulators: Icarus 12 (4-state, X corruption) or Verilator 5 with --timing (2-state).
// Build with -Wno-fatal on Verilator: forced registers raise MULTIDRIVEN warnings.
// ---------------------------------------------------------------------------
// package UPF: generated by OpenPA. Supply types, supply_on/supply_off and the power
// state of the design. Names starting with openpa_ are internal.
// ---------------------------------------------------------------------------
package UPF;
  typedef string upfStringT; typedef int upfIntegerT; typedef bit upfBooleanT; typedef logic upfLogicT; typedef real upfRealT; typedef int upfHandleT;
  typedef enum { OFF, FULL_ON, PARTIAL_ON, UNDETERMINED } upfSupplyStateE;
  typedef struct packed { upfSupplyStateE state; int voltage; } upfSupplyTypeT;  // voltage in microvolts
  typedef upfSupplyTypeT supply_net_type;
  bit openpa_armed;        // set by the first call that drives a supply
  bit openpa_kick;         // pulsed once at time 0 to evaluate everything
  bit openpa_xmode;        // 1: corrupt to X; 0: seeded 2-state values
  int unsigned openpa_seed = 1;
  int openpa_cmode;        // 2-state corruption: 0 random, 1 all zero, 2 all one
  supply_net_type openpa_root_PD_TOP_primary_power;   // root of PD_TOP.primary.power: no source in the UPF; driven by the bench (PD_TOP.primary.power)
  supply_net_type openpa_root_PD_TOP_primary_ground;   // root of PD_TOP.primary.ground: no source in the UPF; driven by the bench (PD_TOP.primary.ground)
  supply_net_type openpa_net_PD_TOP_primary_power;   // supply net PD_TOP.primary.power
  supply_net_type openpa_net_PD_TOP_primary_ground;   // supply net PD_TOP.primary.ground
  bit openpa_ss_PD_TOP_primary_ok; int unsigned openpa_ss_PD_TOP_primary_ep; int openpa_ss_PD_TOP_primary_st = -1; bit openpa_ss_PD_TOP_primary_multi; int openpa_ss_PD_TOP_primary_sim = 5;   // supply set PD_TOP.primary
  bit openpa_dom_PD_TOP_ok; int unsigned openpa_dom_PD_TOP_ep; int openpa_dom_PD_TOP_sim = 5;   // power domain PD_TOP: ok = powered (simstate not CORRUPT); sim = simstate code (pmu_soc.upf:3)
  // simstate codes, by IEEE 1801-2024 4.8 precedence: 0 NORMAL, 1 CORRUPT_STATE_ON_CHANGE, 2 CORRUPT_STATE_ON_ACTIVITY,
  // 3 CORRUPT_ON_CHANGE, 4 CORRUPT_ON_ACTIVITY, 5 CORRUPT (and NOT_NORMAL, 9.5.8); README "Simstates"
  function automatic logic [63:0] openpa_mix(int unsigned id, int unsigned ep, int unsigned lane);
    logic [63:0] z;
    if (openpa_cmode == 1) return 64'd0;
    if (openpa_cmode == 2) return ~64'd0;
    z = {32'd0, openpa_seed} * 64'h9E3779B97F4A7C15 + {32'd0, id} * 64'hC2B2AE3D27D4EB4F + {32'd0, ep} * 64'h165667B19E3779F9 + {32'd0, lane} * 64'hD6E8FEB86659FD93;
    z = (z ^ (z >> 30)) * 64'hBF58476D1CE4E5B9;
    z = (z ^ (z >> 27)) * 64'h94D049BB133111EB;
    return z ^ (z >> 31);
  endfunction
  function automatic bit openpa_bit(int unsigned id, int unsigned ep); logic [63:0] z; z = openpa_mix(id, ep, 0); return z[0]; endfunction
  function automatic int openpa_uv(real v); return $rtoi(v * 1.0e6 + (v < 0.0 ? -0.5 : 0.5)); endfunction
  // supply_on: FULL_ON at the given voltage (11.2.4; default 1.0 V)
  function automatic upfBooleanT supply_on(string pad_name, real value = 1.0);
    openpa_armed = 1;
    if (pad_name == "PD_TOP.primary.power") begin openpa_root_PD_TOP_primary_power.state = FULL_ON; openpa_root_PD_TOP_primary_power.voltage = openpa_uv(value); return 1; end
    if (pad_name == "PD_TOP.primary.ground") begin openpa_root_PD_TOP_primary_ground.state = FULL_ON; openpa_root_PD_TOP_primary_ground.voltage = openpa_uv(value); return 1; end
    $display("OPENPA-ERROR supply_on(\"%s\"): no supply port or root supply net of that name (writable: PD_TOP.primary.power PD_TOP.primary.ground)", pad_name);
    return 0;
  endfunction
  // supply_off: OFF, voltage unchanged (9.3.1); a second argument is accepted and ignored
  function automatic upfBooleanT supply_off(string pad_name, real value = 0.0);
    openpa_armed = 1;
    if (pad_name == "PD_TOP.primary.power") begin openpa_root_PD_TOP_primary_power.state = OFF; return 1; end
    if (pad_name == "PD_TOP.primary.ground") begin openpa_root_PD_TOP_primary_ground.state = OFF; return 1; end
    $display("OPENPA-ERROR supply_off(\"%s\"): no supply port or root supply net of that name (writable: PD_TOP.primary.power PD_TOP.primary.ground)", pad_name);
    return 0;
  endfunction
  // supply_partial_on: PARTIAL_ON at the given voltage (11.2.4)
  function automatic upfBooleanT supply_partial_on(string pad_name, real value = 1.0);
    openpa_armed = 1;
    if (pad_name == "PD_TOP.primary.power") begin openpa_root_PD_TOP_primary_power.state = PARTIAL_ON; openpa_root_PD_TOP_primary_power.voltage = openpa_uv(value); return 1; end
    if (pad_name == "PD_TOP.primary.ground") begin openpa_root_PD_TOP_primary_ground.state = PARTIAL_ON; openpa_root_PD_TOP_primary_ground.voltage = openpa_uv(value); return 1; end
    $display("OPENPA-ERROR supply_partial_on(\"%s\"): no supply port or root supply net of that name (writable: PD_TOP.primary.power PD_TOP.primary.ground)", pad_name);
    return 0;
  endfunction
  // set_supply_state: the state only, voltage unchanged (9.3.1)
  function automatic upfBooleanT set_supply_state(string pad_name, upfSupplyStateE supply_state);
    openpa_armed = 1;
    if (pad_name == "PD_TOP.primary.power") begin openpa_root_PD_TOP_primary_power.state = supply_state; return 1; end
    if (pad_name == "PD_TOP.primary.ground") begin openpa_root_PD_TOP_primary_ground.state = supply_state; return 1; end
    $display("OPENPA-ERROR set_supply_state(\"%s\"): no supply port or root supply net of that name (writable: PD_TOP.primary.power PD_TOP.primary.ground)", pad_name);
    return 0;
  endfunction
  // set_power_state (9.3.1) is not supported: OpenPA has no deferred power states. A call is reported, never ignored.
  function automatic upfBooleanT set_power_state(string object_name, string power_state);
    $display("OPENPA-ERROR set_power_state(\"%s\", \"%s\"): not supported by OpenPA; drive the supplies with supply_on, supply_off or set_supply_state", object_name, power_state);
    return 0;
  endfunction
  // Supply queries (11.2.4). Names: supply ports, supply nets and supply set functions as the UPF wrote them.
  function automatic upfSupplyTypeT get_supply_value(string name);
    if (name == "PD_TOP.primary.power") return openpa_net_PD_TOP_primary_power;
    if (name == "PD_TOP.primary.ground") return openpa_net_PD_TOP_primary_ground;
    $display("OPENPA-ERROR get_supply_value(\"%s\"): no supply net, port or supply set function of that name", name);
    return 0;
  endfunction
  function automatic upfRealT get_supply_voltage(upfSupplyTypeT arg); return arg.voltage / 1.0e6; endfunction
  // 11.2.4: 1 for FULL_ON; 0 otherwise.
  function automatic upfBooleanT get_supply_on_state(upfSupplyTypeT arg); return arg.state == FULL_ON; endfunction
  function automatic upfSupplyStateE get_supply_state(upfSupplyTypeT arg); return arg.state; endfunction
endpackage
// ---------------------------------------------------------------------------
// OpenPA cells (generated; do not edit)
// ---------------------------------------------------------------------------
// openpa_corrupt: rule C2. Passes d while the driving domain is NORMAL; otherwise drives X (4-state)
// or a seeded value (2-state). The value is computed ahead for the episode the next power-down starts
// (ep + 1 while ok), so at power-down the output goes straight from d to the new value: no delta glitch
// through the previous episode's value (Icarus would turn one into a clock edge).
module openpa_corrupt #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           ok,
  input  int unsigned  ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  always @(ep or ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID, ok ? ep + 1 : ep, i);
  assign q = ok ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

// openpa_corrupt_sim: rule C2 for a domain that has intermediate simstates (IEEE 1801-2024 9.5). As
// openpa_corrupt, and also corrupt while lhit is set (CORRUPT_ON_ACTIVITY after input activity), or after d
// changed while coc is set (CORRUPT_ON_CHANGE); leaving CORRUPT_ON_CHANGE clears that.
module openpa_corrupt_sim #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           ok,
  input  int unsigned  ep,
  input  bit           lhit,
  input  bit           coc
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  bit chg;
  always @(ep or ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID, ok ? ep + 1 : ep, i);
  // verilator lint_off MULTIDRIVEN
  for (genvar i = 0; i < W; i++) begin : g_chg
    always @(posedge d[i] or negedge d[i]) if (coc && ok) chg = 1'b1;
  end
  always @(negedge coc) chg = 1'b0;
  // verilator lint_on MULTIDRIVEN
  assign q = (ok && !lhit && !chg) ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

// openpa_iso: rules I1-I4 (IEEE 1801-2024 9.8). CLAMP 0, 1, 2 (latch: the value the input had while the enable
// was inactive) or 3 (Z: high impedance on 4-state; 0 on 2-state backends, which cannot represent Z).
// sup_ok is 1 while the isolation supply is NORMAL (always, for a strategy with no supply); otherwise the output,
// and a latched value, are corrupt. An enable at X or Z corrupts the output and the latched value.
module openpa_iso #(parameter int W = 1, parameter int CLAMP = 0, parameter bit SENSE = 1'b1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  logic         en,
  input  bit           sup_ok,
  input  int unsigned  sup_ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  logic [W-1:0] held;
  always @(sup_ep or sup_ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID + 32'h4000_0000, sup_ok ? sup_ep + 1 : sup_ep, i);
  wire active   = (en === SENSE);
  wire inactive = (en === !SENSE);
  wire [W-1:0] bad    = UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0];
  if (CLAMP == 2) begin : g_latch
    always @(d or en or sup_ok or bad) if (!sup_ok || !(active || inactive)) held = bad; else if (inactive) held = d;
  end
  wire [W-1:0] clampv = (CLAMP == 3) ? (UPF::openpa_xmode ? {W{1'bz}} : {W{1'b0}}) : (CLAMP == 2) ? held : (CLAMP == 1) ? {W{1'b1}} : {W{1'b0}};
  assign q = !sup_ok ? bad : active ? clampv : inactive ? d : bad;
endmodule

// openpa_ls: rule L1 (IEEE 1801-2024 9.9). Passes d while every supply set of the cell is NORMAL; otherwise corrupt.
module openpa_ls #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           src_ok,
  input  bit           dst_ok,
  input  int unsigned  ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  always @(ep or src_ok or dst_ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID + 32'h8000_0000, (src_ok && dst_ok) ? ep + 1 : ep, i);
  assign q = (src_ok && dst_ok) ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

`line 1 "pmu_soc.sv" 0
// pmu_soc: two power domains. The top and the controller are always on; u_core can be switched off.
// The RTL is power-unaware: no isolation cell, no supply, no retention register is written here.
module pmu_soc (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       sleep_req,
  input  logic       wake_req,
  input  logic       en,
  input  logic [7:0] d,
  input  logic [1:0] rf_addr,
  input  logic       rf_we,
  output logic [7:0] total,
  output logic       led,
  output logic [7:0] rd,
  output logic [3:0] beats,
  output logic [7:0] status,
  output logic [2:0] pmu_state
);
  logic iso_en, save, restore, pwr_en, core_rst_n;
  logic [7:0] acc, rf_rd;
  logic busy;
  logic [3:0] core_beats;

  pmu u_pmu (
    .clk        (clk),
    .rst_n      (rst_n),
    .sleep_req  (sleep_req),
    .wake_req   (wake_req),
    .iso_en     (iso_en),
    .save       (save),
    .restore    (restore),
    .pwr_en     (pwr_en),
    .core_rst_n (core_rst_n),
    .state_o    (pmu_state)
  );

  core u_core (
    .clk     (clk),
    .rst_n   (core_rst_n),
    .en      (en),
    .d       (d),
    .rf_addr (rf_addr),
    .rf_we   (rf_we),
    .acc     (acc),
    .rf_rd   (rf_rd),
    .busy    (busy),
    .beats   (core_beats)
  );

  // Always-on consumers of the core's outputs.
  assign total = acc;
  assign led   = busy;
  assign rd    = rf_rd;
  assign beats = core_beats;
  // A status register: keeps the last accumulator value seen while the core was busy.
  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) status <= '0;
    else if (busy) status <= acc;

`line 1 "openpa_overlay.sv" 0
  // ===================================================================================
  // OpenPA overlay for pmu_soc: generated from pmu_soc.upf. Do not edit.
  // ===================================================================================
  // verilator lint_off MULTIDRIVEN
  // verilator lint_off ENUMVALUE
  // verilator lint_off WIDTHTRUNC
  // verilator lint_off WIDTHEXPAND
  // verilator lint_off BLKSEQ
  // verilator lint_off IGNOREDRETURN
  import UPF::openpa_cmode;
  import UPF::openpa_dom_PD_TOP_ep;
  import UPF::openpa_dom_PD_TOP_ok;
  import UPF::openpa_dom_PD_TOP_sim;
  import UPF::openpa_kick;
  import UPF::openpa_net_PD_TOP_primary_ground;
  import UPF::openpa_net_PD_TOP_primary_power;
  import UPF::openpa_seed;
  import UPF::openpa_ss_PD_TOP_primary_ep;
  import UPF::openpa_ss_PD_TOP_primary_multi;
  import UPF::openpa_ss_PD_TOP_primary_ok;
  import UPF::openpa_ss_PD_TOP_primary_sim;
  import UPF::openpa_ss_PD_TOP_primary_st;
  import UPF::openpa_xmode;
  // ---- mode, seed, trace
  bit openpa_tr, openpa_obs;
  int openpa_n [1:14];
  int openpa_seq [1:1];   // good-form sequence bins (coverage)
  bit openpa_sreq; bit openpa_sp [1:1];   // deferred checks: request and pending flags
  string openpa_mode_arg;
  initial begin
  `ifdef VERILATOR
    openpa_xmode = 1'b0;
  `else
    openpa_xmode = 1'b1;
  `endif
    openpa_cmode = 0;
    if ($value$plusargs("openpa_corrupt=%s", openpa_mode_arg)) begin
      if (openpa_mode_arg == "x") openpa_xmode = 1'b1;
      else if (openpa_mode_arg == "random") openpa_xmode = 1'b0;
      else if (openpa_mode_arg == "zero") begin openpa_xmode = 1'b0; openpa_cmode = 1; end
      else if (openpa_mode_arg == "one") begin openpa_xmode = 1'b0; openpa_cmode = 2; end
      else $display("OPENPA-ERROR +openpa_corrupt=%s: use x, random, zero or one", openpa_mode_arg);
    end
    if (!$value$plusargs("openpa_seed=%d", openpa_seed)) openpa_seed = 1;
    openpa_tr = $test$plusargs("openpa_trace");
    openpa_obs = $test$plusargs("openpa_obs");
    $display("OPENPA-INFO corruption=%0s seed=%0d", openpa_xmode ? "x" : (openpa_cmode == 1 ? "zero" : openpa_cmode == 2 ? "one" : "random"), openpa_seed);
    #0 openpa_kick = 1'b1;
  end
  task automatic openpa_check(input int id, input string msg);
    openpa_n[id] = openpa_n[id] + 1;
    $display("OPENPA-CHECK D%0d @ %0t: %s", id, $time, msg);
  endtask
  task automatic openpa_t(input string msg);
    if (openpa_tr) $display("OPENPA-TRACE @ %0t: %s", $time, msg);
  endtask

  // ---- copies of the design signals the UPF names (4-state, so X is visible)

  // ---- supply network, switches, supply sets, simstates, power states (one block, evaluated in order)
  always @(openpa_kick or UPF::openpa_root_PD_TOP_primary_power or UPF::openpa_root_PD_TOP_primary_ground) begin : openpa_network
    openpa_net_PD_TOP_primary_power = UPF::openpa_root_PD_TOP_primary_power;   // PD_TOP.primary.power: root supply driven by the bench
    openpa_net_PD_TOP_primary_ground = UPF::openpa_root_PD_TOP_primary_ground;   // PD_TOP.primary.ground: root supply driven by the bench
    // supply set PD_TOP.primary: IEEE 1801-2024 4.7.3, 4.7.4, 6.5.6, 9.3.2, 5.7.8
    begin : openpa_ss_PD_TOP_primary
      bit nx; int sm;
      sm = (UPF::openpa_net_PD_TOP_primary_power.state == UPF::FULL_ON && UPF::openpa_net_PD_TOP_primary_ground.state == UPF::FULL_ON) ? 0 : 5;   // predefined ON (NORMAL) or OFF (CORRUPT), IEEE 1801-2024 4.7.4
      openpa_ss_PD_TOP_primary_sim = sm;
      nx = sm < 5;
      if (openpa_ss_PD_TOP_primary_ok && !nx) openpa_ss_PD_TOP_primary_ep = openpa_ss_PD_TOP_primary_ep + 1;
      openpa_ss_PD_TOP_primary_ok = nx;
    end
    // domain PD_TOP: simstate of its primary supply set PD_TOP.primary
    if (openpa_dom_PD_TOP_ok && !UPF::openpa_ss_PD_TOP_primary_ok) openpa_dom_PD_TOP_ep = openpa_dom_PD_TOP_ep + 1;
    openpa_dom_PD_TOP_ok = UPF::openpa_ss_PD_TOP_primary_ok;
    openpa_dom_PD_TOP_sim = openpa_ss_PD_TOP_primary_sim;
  end

  // ---- corruption: registers forced, memories overwritten (rules C1, C3)
  // domain PD_TOP (pmu_soc.upf:3): 4 register(s), 1 memory(ies)
  bit openpa_PD_TOP_applied, openpa_PD_TOP_valid;
  logic [7:0] openpa_cv1;   // corruption value for status
  logic [7:0] openpa_cv2;   // corruption value for u_core.acc
  logic [3:0] openpa_cv3;   // corruption value for u_core.beats
  logic [2:0] openpa_cv4;   // corruption value for u_pmu.st
  // The first evaluation counts as a power-up from OFF: registers take the corruption value even when the
  // supplies are already on at time 0 (rule C3), so 4-state and 2-state runs start alike.
  always @(UPF::openpa_dom_PD_TOP_ok or openpa_kick) if (!openpa_PD_TOP_valid || openpa_PD_TOP_applied != UPF::openpa_dom_PD_TOP_ok) begin
    openpa_t({"PD_TOP ", UPF::openpa_dom_PD_TOP_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_TOP_ok || !openpa_PD_TOP_valid) begin
      if (openpa_xmode) openpa_cv1 = 'x; else openpa_cv1 = UPF::openpa_mix(1, UPF::openpa_dom_PD_TOP_ep, 0);
      force status = openpa_cv1;
      if (openpa_xmode) openpa_cv2 = 'x; else openpa_cv2 = UPF::openpa_mix(2, UPF::openpa_dom_PD_TOP_ep, 0);
      force u_core.acc = openpa_cv2;
      if (openpa_xmode) openpa_cv3 = 'x; else openpa_cv3 = UPF::openpa_mix(3, UPF::openpa_dom_PD_TOP_ep, 0);
      force u_core.beats = openpa_cv3;
      if (openpa_xmode) openpa_cv4 = 'x; else openpa_cv4 = UPF::openpa_mix(4, UPF::openpa_dom_PD_TOP_ep, 0);
      force u_pmu.st = openpa_cv4;
      for (int i = 0; i < 4; i++) u_core.rf[0 + i] = openpa_xmode ? 8'bx : UPF::openpa_mix(100000, UPF::openpa_dom_PD_TOP_ep, (i) * 1 + 0);
    end
    if (UPF::openpa_dom_PD_TOP_ok) begin
      for (int i = 0; i < 4; i++) u_core.rf[0 + i] = openpa_xmode ? 8'bx : UPF::openpa_mix(100000, UPF::openpa_dom_PD_TOP_ep, (i) * 1 + 0);
      release status;
      release u_core.acc;
      release u_core.beats;
      release u_pmu.st;
    end
    openpa_PD_TOP_valid = 1'b1; openpa_PD_TOP_applied = UPF::openpa_dom_PD_TOP_ok;
  end

  // ---- observation for differential corruption (+openpa_obs): design-top outputs while the top domain is on
  `ifdef OPENPA_OBS
  longint openpa_obs_after;
  initial if (!$value$plusargs("openpa_obs_after=%d", openpa_obs_after)) openpa_obs_after = 0;
  always @(total) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: total=%h", $time, total);
  always @(led) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: led=%h", $time, led);
  always @(rd) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: rd=%h", $time, rd);
  always @(beats) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: beats=%h", $time, beats);
  always @(status) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: status=%h", $time, status);
  always @(pmu_state) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: pmu_state=%h", $time, pmu_state);
  `else
  initial if ($test$plusargs("openpa_obs")) $display("OPENPA-ERROR +openpa_obs needs the copy compiled with OPENPA_OBS defined (-DOPENPA_OBS or +define+OPENPA_OBS)");
  `endif

  // Icarus 12 runs no named block inside a final block, so the report is a function.
  function automatic void openpa_cover_report();
      int hs, ht, hq;
      hs = 0; ht = 0; hq = 0;
      $display("OPENPA-COVER-SUMMARY states=%0d/0 declared_transitions=%0d/0 sequences=%0d/0", hs, ht, hq);
  endfunction

  // ---- settle process: 0 deferred check(s), run after one #0 in a fixed order
  initial forever begin
    wait (openpa_sreq && openpa_kick);
    #0;
    openpa_sreq = 1'b0;
  end
  final begin
    $display("OPENPA-SUMMARY D1=%0d D2=%0d D3=%0d D4=%0d D5=%0d D6=%0d D7=%0d D8=%0d D9=%0d D10=%0d D11=%0d D12=%0d D13=%0d D14=%0d", openpa_n[1], openpa_n[2], openpa_n[3], openpa_n[4], openpa_n[5], openpa_n[6], openpa_n[7], openpa_n[8], openpa_n[9], openpa_n[10], openpa_n[11], openpa_n[12], openpa_n[13], openpa_n[14]);
    openpa_cover_report();
    if (!UPF::openpa_armed) $display("OPENPA-WARNING no supply was driven (supply_on/supply_off never called): every domain stayed CORRUPT");
  end
  // verilator lint_on MULTIDRIVEN
`line 59 "pmu_soc.sv" 0
endmodule

`line 1 "pmu.sv" 0
// pmu_soc: the always-on power controller. Power-unaware RTL: it only drives control signals.
// Sleep: isolate, save, switch off. Wake: switch on, reset, restore, release isolation.
module pmu (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       sleep_req,
  input  logic       wake_req,
  output logic       iso_en,
  output logic       save,
  output logic       restore,
  output logic       pwr_en,
  output logic       core_rst_n,
  output logic [2:0] state_o
);
  typedef enum logic [2:0] { RUN, ISOLATE, SAVE, OFF, PWRUP, RESET, RESTORE, RELEASE } st_e;
  st_e st;
  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) st <= RUN;
    else case (st)
      RUN:     if (sleep_req) st <= ISOLATE;
      ISOLATE: st <= SAVE;
      SAVE:    st <= OFF;
      OFF:     if (wake_req) st <= PWRUP;
      PWRUP:   st <= RESET;
      RESET:   st <= RESTORE;
      RESTORE: st <= RELEASE;
      RELEASE: st <= RUN;
      default: st <= RUN;
    endcase
  assign iso_en     = (st != RUN);
  assign save       = (st == SAVE);
  assign restore    = (st == RESTORE);
  assign pwr_en     = !(st == OFF);
  assign core_rst_n = rst_n && (st != RESET);
  assign state_o    = st;
endmodule

`line 1 "core.sv" 0
// pmu_soc: the switchable core. An accumulator, a beat counter and a 4-word register file.
// Power-unaware RTL: nothing here knows about supplies.
module core (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       en,
  input  logic [7:0] d,
  input  logic [1:0] rf_addr,
  input  logic       rf_we,
  output logic [7:0] acc,
  output logic [7:0] rf_rd,
  output logic       busy,
  output logic [3:0] beats
);
  logic [7:0] rf [0:3];
  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) begin
      acc   <= '0;
      beats <= '0;
    end else if (en) begin
      acc   <= acc + d;
      beats <= beats + 4'd1;
    end
  always_ff @(posedge clk)
    if (rf_we) rf[rf_addr] <= acc;
  assign rf_rd = rf[rf_addr];
  assign busy  = en;
endmodule

Check Yourself

Predict the outputThis bench runs on the lab's power-aware copy. The supply drops for 1 ns between two clock edges and comes back. There is no reset after it. What does the last line print?

module tb;
  import UPF::*;
  logic clk = 0, rst_n = 0, sleep_req = 0, wake_req = 0, en = 0, rf_we = 0;
  logic [7:0] d = 0; logic [1:0] rf_addr = 0;
  wire [7:0] total, rd, status; wire led; wire [3:0] beats; wire [2:0] pmu_state;
  pmu_soc dut (.*);
  always #5 clk = ~clk;
  initial begin
    void'(supply_on("PD_TOP.primary.power", 1.0));
    void'(supply_on("PD_TOP.primary.ground", 0.0));
    repeat (2) @(posedge clk); #1 rst_n = 1;
    en = 1; d = 8'h05; @(posedge clk); #1;      // one beat: acc = 05
    void'(supply_off("PD_TOP.primary.power"));  // the supply drops ...
    #1 void'(supply_on("PD_TOP.primary.power", 1.0));  // ... and comes back 1 ns later
    @(posedge clk); #1 en = 0;                  // one more beat, no reset
    $display("acc=%0h", dut.u_core.acc);
    $finish;
  end
endmodule
Read included file: pa_pmu_soc.sv
// pa_pmu_soc.sv: power-aware copy of pmu_soc, generated by OpenPA from pmu_soc.upf.
// Do not edit: regenerate. Simulators: Icarus 12 (4-state, X corruption) or Verilator 5 with --timing (2-state).
// Build with -Wno-fatal on Verilator: forced registers raise MULTIDRIVEN warnings.
// ---------------------------------------------------------------------------
// package UPF: generated by OpenPA. Supply types, supply_on/supply_off and the power
// state of the design. Names starting with openpa_ are internal.
// ---------------------------------------------------------------------------
package UPF;
  typedef string upfStringT; typedef int upfIntegerT; typedef bit upfBooleanT; typedef logic upfLogicT; typedef real upfRealT; typedef int upfHandleT;
  typedef enum { OFF, FULL_ON, PARTIAL_ON, UNDETERMINED } upfSupplyStateE;
  typedef struct packed { upfSupplyStateE state; int voltage; } upfSupplyTypeT;  // voltage in microvolts
  typedef upfSupplyTypeT supply_net_type;
  bit openpa_armed;        // set by the first call that drives a supply
  bit openpa_kick;         // pulsed once at time 0 to evaluate everything
  bit openpa_xmode;        // 1: corrupt to X; 0: seeded 2-state values
  int unsigned openpa_seed = 1;
  int openpa_cmode;        // 2-state corruption: 0 random, 1 all zero, 2 all one
  supply_net_type openpa_root_PD_TOP_primary_power;   // root of PD_TOP.primary.power: no source in the UPF; driven by the bench (PD_TOP.primary.power)
  supply_net_type openpa_root_PD_TOP_primary_ground;   // root of PD_TOP.primary.ground: no source in the UPF; driven by the bench (PD_TOP.primary.ground)
  supply_net_type openpa_net_PD_TOP_primary_power;   // supply net PD_TOP.primary.power
  supply_net_type openpa_net_PD_TOP_primary_ground;   // supply net PD_TOP.primary.ground
  bit openpa_ss_PD_TOP_primary_ok; int unsigned openpa_ss_PD_TOP_primary_ep; int openpa_ss_PD_TOP_primary_st = -1; bit openpa_ss_PD_TOP_primary_multi; int openpa_ss_PD_TOP_primary_sim = 5;   // supply set PD_TOP.primary
  bit openpa_dom_PD_TOP_ok; int unsigned openpa_dom_PD_TOP_ep; int openpa_dom_PD_TOP_sim = 5;   // power domain PD_TOP: ok = powered (simstate not CORRUPT); sim = simstate code (pmu_soc.upf:3)
  // simstate codes, by IEEE 1801-2024 4.8 precedence: 0 NORMAL, 1 CORRUPT_STATE_ON_CHANGE, 2 CORRUPT_STATE_ON_ACTIVITY,
  // 3 CORRUPT_ON_CHANGE, 4 CORRUPT_ON_ACTIVITY, 5 CORRUPT (and NOT_NORMAL, 9.5.8); README "Simstates"
  function automatic logic [63:0] openpa_mix(int unsigned id, int unsigned ep, int unsigned lane);
    logic [63:0] z;
    if (openpa_cmode == 1) return 64'd0;
    if (openpa_cmode == 2) return ~64'd0;
    z = {32'd0, openpa_seed} * 64'h9E3779B97F4A7C15 + {32'd0, id} * 64'hC2B2AE3D27D4EB4F + {32'd0, ep} * 64'h165667B19E3779F9 + {32'd0, lane} * 64'hD6E8FEB86659FD93;
    z = (z ^ (z >> 30)) * 64'hBF58476D1CE4E5B9;
    z = (z ^ (z >> 27)) * 64'h94D049BB133111EB;
    return z ^ (z >> 31);
  endfunction
  function automatic bit openpa_bit(int unsigned id, int unsigned ep); logic [63:0] z; z = openpa_mix(id, ep, 0); return z[0]; endfunction
  function automatic int openpa_uv(real v); return $rtoi(v * 1.0e6 + (v < 0.0 ? -0.5 : 0.5)); endfunction
  // supply_on: FULL_ON at the given voltage (11.2.4; default 1.0 V)
  function automatic upfBooleanT supply_on(string pad_name, real value = 1.0);
    openpa_armed = 1;
    if (pad_name == "PD_TOP.primary.power") begin openpa_root_PD_TOP_primary_power.state = FULL_ON; openpa_root_PD_TOP_primary_power.voltage = openpa_uv(value); return 1; end
    if (pad_name == "PD_TOP.primary.ground") begin openpa_root_PD_TOP_primary_ground.state = FULL_ON; openpa_root_PD_TOP_primary_ground.voltage = openpa_uv(value); return 1; end
    $display("OPENPA-ERROR supply_on(\"%s\"): no supply port or root supply net of that name (writable: PD_TOP.primary.power PD_TOP.primary.ground)", pad_name);
    return 0;
  endfunction
  // supply_off: OFF, voltage unchanged (9.3.1); a second argument is accepted and ignored
  function automatic upfBooleanT supply_off(string pad_name, real value = 0.0);
    openpa_armed = 1;
    if (pad_name == "PD_TOP.primary.power") begin openpa_root_PD_TOP_primary_power.state = OFF; return 1; end
    if (pad_name == "PD_TOP.primary.ground") begin openpa_root_PD_TOP_primary_ground.state = OFF; return 1; end
    $display("OPENPA-ERROR supply_off(\"%s\"): no supply port or root supply net of that name (writable: PD_TOP.primary.power PD_TOP.primary.ground)", pad_name);
    return 0;
  endfunction
  // supply_partial_on: PARTIAL_ON at the given voltage (11.2.4)
  function automatic upfBooleanT supply_partial_on(string pad_name, real value = 1.0);
    openpa_armed = 1;
    if (pad_name == "PD_TOP.primary.power") begin openpa_root_PD_TOP_primary_power.state = PARTIAL_ON; openpa_root_PD_TOP_primary_power.voltage = openpa_uv(value); return 1; end
    if (pad_name == "PD_TOP.primary.ground") begin openpa_root_PD_TOP_primary_ground.state = PARTIAL_ON; openpa_root_PD_TOP_primary_ground.voltage = openpa_uv(value); return 1; end
    $display("OPENPA-ERROR supply_partial_on(\"%s\"): no supply port or root supply net of that name (writable: PD_TOP.primary.power PD_TOP.primary.ground)", pad_name);
    return 0;
  endfunction
  // set_supply_state: the state only, voltage unchanged (9.3.1)
  function automatic upfBooleanT set_supply_state(string pad_name, upfSupplyStateE supply_state);
    openpa_armed = 1;
    if (pad_name == "PD_TOP.primary.power") begin openpa_root_PD_TOP_primary_power.state = supply_state; return 1; end
    if (pad_name == "PD_TOP.primary.ground") begin openpa_root_PD_TOP_primary_ground.state = supply_state; return 1; end
    $display("OPENPA-ERROR set_supply_state(\"%s\"): no supply port or root supply net of that name (writable: PD_TOP.primary.power PD_TOP.primary.ground)", pad_name);
    return 0;
  endfunction
  // set_power_state (9.3.1) is not supported: OpenPA has no deferred power states. A call is reported, never ignored.
  function automatic upfBooleanT set_power_state(string object_name, string power_state);
    $display("OPENPA-ERROR set_power_state(\"%s\", \"%s\"): not supported by OpenPA; drive the supplies with supply_on, supply_off or set_supply_state", object_name, power_state);
    return 0;
  endfunction
  // Supply queries (11.2.4). Names: supply ports, supply nets and supply set functions as the UPF wrote them.
  function automatic upfSupplyTypeT get_supply_value(string name);
    if (name == "PD_TOP.primary.power") return openpa_net_PD_TOP_primary_power;
    if (name == "PD_TOP.primary.ground") return openpa_net_PD_TOP_primary_ground;
    $display("OPENPA-ERROR get_supply_value(\"%s\"): no supply net, port or supply set function of that name", name);
    return 0;
  endfunction
  function automatic upfRealT get_supply_voltage(upfSupplyTypeT arg); return arg.voltage / 1.0e6; endfunction
  // 11.2.4: 1 for FULL_ON; 0 otherwise.
  function automatic upfBooleanT get_supply_on_state(upfSupplyTypeT arg); return arg.state == FULL_ON; endfunction
  function automatic upfSupplyStateE get_supply_state(upfSupplyTypeT arg); return arg.state; endfunction
endpackage
// ---------------------------------------------------------------------------
// OpenPA cells (generated; do not edit)
// ---------------------------------------------------------------------------
// openpa_corrupt: rule C2. Passes d while the driving domain is NORMAL; otherwise drives X (4-state)
// or a seeded value (2-state). The value is computed ahead for the episode the next power-down starts
// (ep + 1 while ok), so at power-down the output goes straight from d to the new value: no delta glitch
// through the previous episode's value (Icarus would turn one into a clock edge).
module openpa_corrupt #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           ok,
  input  int unsigned  ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  always @(ep or ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID, ok ? ep + 1 : ep, i);
  assign q = ok ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

// openpa_corrupt_sim: rule C2 for a domain that has intermediate simstates (IEEE 1801-2024 9.5). As
// openpa_corrupt, and also corrupt while lhit is set (CORRUPT_ON_ACTIVITY after input activity), or after d
// changed while coc is set (CORRUPT_ON_CHANGE); leaving CORRUPT_ON_CHANGE clears that.
module openpa_corrupt_sim #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           ok,
  input  int unsigned  ep,
  input  bit           lhit,
  input  bit           coc
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  bit chg;
  always @(ep or ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID, ok ? ep + 1 : ep, i);
  // verilator lint_off MULTIDRIVEN
  for (genvar i = 0; i < W; i++) begin : g_chg
    always @(posedge d[i] or negedge d[i]) if (coc && ok) chg = 1'b1;
  end
  always @(negedge coc) chg = 1'b0;
  // verilator lint_on MULTIDRIVEN
  assign q = (ok && !lhit && !chg) ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

// openpa_iso: rules I1-I4 (IEEE 1801-2024 9.8). CLAMP 0, 1, 2 (latch: the value the input had while the enable
// was inactive) or 3 (Z: high impedance on 4-state; 0 on 2-state backends, which cannot represent Z).
// sup_ok is 1 while the isolation supply is NORMAL (always, for a strategy with no supply); otherwise the output,
// and a latched value, are corrupt. An enable at X or Z corrupts the output and the latched value.
module openpa_iso #(parameter int W = 1, parameter int CLAMP = 0, parameter bit SENSE = 1'b1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  logic         en,
  input  bit           sup_ok,
  input  int unsigned  sup_ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  logic [W-1:0] held;
  always @(sup_ep or sup_ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID + 32'h4000_0000, sup_ok ? sup_ep + 1 : sup_ep, i);
  wire active   = (en === SENSE);
  wire inactive = (en === !SENSE);
  wire [W-1:0] bad    = UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0];
  if (CLAMP == 2) begin : g_latch
    always @(d or en or sup_ok or bad) if (!sup_ok || !(active || inactive)) held = bad; else if (inactive) held = d;
  end
  wire [W-1:0] clampv = (CLAMP == 3) ? (UPF::openpa_xmode ? {W{1'bz}} : {W{1'b0}}) : (CLAMP == 2) ? held : (CLAMP == 1) ? {W{1'b1}} : {W{1'b0}};
  assign q = !sup_ok ? bad : active ? clampv : inactive ? d : bad;
endmodule

// openpa_ls: rule L1 (IEEE 1801-2024 9.9). Passes d while every supply set of the cell is NORMAL; otherwise corrupt.
module openpa_ls #(parameter int W = 1, parameter int unsigned ID = 0) (
  input  logic [W-1:0] d,
  output logic [W-1:0] q,
  input  bit           src_ok,
  input  bit           dst_ok,
  input  int unsigned  ep
);
  localparam int L = (W + 63) / 64;
  logic [L*64-1:0] cv;
  always @(ep or src_ok or dst_ok or UPF::openpa_kick)
    for (int i = 0; i < L; i++) cv[i*64 +: 64] = UPF::openpa_mix(ID + 32'h8000_0000, (src_ok && dst_ok) ? ep + 1 : ep, i);
  assign q = (src_ok && dst_ok) ? d : (UPF::openpa_xmode ? {W{1'bx}} : cv[W-1:0]);
endmodule

`line 1 "pmu_soc.sv" 0
// pmu_soc: two power domains. The top and the controller are always on; u_core can be switched off.
// The RTL is power-unaware: no isolation cell, no supply, no retention register is written here.
module pmu_soc (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       sleep_req,
  input  logic       wake_req,
  input  logic       en,
  input  logic [7:0] d,
  input  logic [1:0] rf_addr,
  input  logic       rf_we,
  output logic [7:0] total,
  output logic       led,
  output logic [7:0] rd,
  output logic [3:0] beats,
  output logic [7:0] status,
  output logic [2:0] pmu_state
);
  logic iso_en, save, restore, pwr_en, core_rst_n;
  logic [7:0] acc, rf_rd;
  logic busy;
  logic [3:0] core_beats;

  pmu u_pmu (
    .clk        (clk),
    .rst_n      (rst_n),
    .sleep_req  (sleep_req),
    .wake_req   (wake_req),
    .iso_en     (iso_en),
    .save       (save),
    .restore    (restore),
    .pwr_en     (pwr_en),
    .core_rst_n (core_rst_n),
    .state_o    (pmu_state)
  );

  core u_core (
    .clk     (clk),
    .rst_n   (core_rst_n),
    .en      (en),
    .d       (d),
    .rf_addr (rf_addr),
    .rf_we   (rf_we),
    .acc     (acc),
    .rf_rd   (rf_rd),
    .busy    (busy),
    .beats   (core_beats)
  );

  // Always-on consumers of the core's outputs.
  assign total = acc;
  assign led   = busy;
  assign rd    = rf_rd;
  assign beats = core_beats;
  // A status register: keeps the last accumulator value seen while the core was busy.
  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) status <= '0;
    else if (busy) status <= acc;

`line 1 "openpa_overlay.sv" 0
  // ===================================================================================
  // OpenPA overlay for pmu_soc: generated from pmu_soc.upf. Do not edit.
  // ===================================================================================
  // verilator lint_off MULTIDRIVEN
  // verilator lint_off ENUMVALUE
  // verilator lint_off WIDTHTRUNC
  // verilator lint_off WIDTHEXPAND
  // verilator lint_off BLKSEQ
  // verilator lint_off IGNOREDRETURN
  import UPF::openpa_cmode;
  import UPF::openpa_dom_PD_TOP_ep;
  import UPF::openpa_dom_PD_TOP_ok;
  import UPF::openpa_dom_PD_TOP_sim;
  import UPF::openpa_kick;
  import UPF::openpa_net_PD_TOP_primary_ground;
  import UPF::openpa_net_PD_TOP_primary_power;
  import UPF::openpa_seed;
  import UPF::openpa_ss_PD_TOP_primary_ep;
  import UPF::openpa_ss_PD_TOP_primary_multi;
  import UPF::openpa_ss_PD_TOP_primary_ok;
  import UPF::openpa_ss_PD_TOP_primary_sim;
  import UPF::openpa_ss_PD_TOP_primary_st;
  import UPF::openpa_xmode;
  // ---- mode, seed, trace
  bit openpa_tr, openpa_obs;
  int openpa_n [1:14];
  int openpa_seq [1:1];   // good-form sequence bins (coverage)
  bit openpa_sreq; bit openpa_sp [1:1];   // deferred checks: request and pending flags
  string openpa_mode_arg;
  initial begin
  `ifdef VERILATOR
    openpa_xmode = 1'b0;
  `else
    openpa_xmode = 1'b1;
  `endif
    openpa_cmode = 0;
    if ($value$plusargs("openpa_corrupt=%s", openpa_mode_arg)) begin
      if (openpa_mode_arg == "x") openpa_xmode = 1'b1;
      else if (openpa_mode_arg == "random") openpa_xmode = 1'b0;
      else if (openpa_mode_arg == "zero") begin openpa_xmode = 1'b0; openpa_cmode = 1; end
      else if (openpa_mode_arg == "one") begin openpa_xmode = 1'b0; openpa_cmode = 2; end
      else $display("OPENPA-ERROR +openpa_corrupt=%s: use x, random, zero or one", openpa_mode_arg);
    end
    if (!$value$plusargs("openpa_seed=%d", openpa_seed)) openpa_seed = 1;
    openpa_tr = $test$plusargs("openpa_trace");
    openpa_obs = $test$plusargs("openpa_obs");
    $display("OPENPA-INFO corruption=%0s seed=%0d", openpa_xmode ? "x" : (openpa_cmode == 1 ? "zero" : openpa_cmode == 2 ? "one" : "random"), openpa_seed);
    #0 openpa_kick = 1'b1;
  end
  task automatic openpa_check(input int id, input string msg);
    openpa_n[id] = openpa_n[id] + 1;
    $display("OPENPA-CHECK D%0d @ %0t: %s", id, $time, msg);
  endtask
  task automatic openpa_t(input string msg);
    if (openpa_tr) $display("OPENPA-TRACE @ %0t: %s", $time, msg);
  endtask

  // ---- copies of the design signals the UPF names (4-state, so X is visible)

  // ---- supply network, switches, supply sets, simstates, power states (one block, evaluated in order)
  always @(openpa_kick or UPF::openpa_root_PD_TOP_primary_power or UPF::openpa_root_PD_TOP_primary_ground) begin : openpa_network
    openpa_net_PD_TOP_primary_power = UPF::openpa_root_PD_TOP_primary_power;   // PD_TOP.primary.power: root supply driven by the bench
    openpa_net_PD_TOP_primary_ground = UPF::openpa_root_PD_TOP_primary_ground;   // PD_TOP.primary.ground: root supply driven by the bench
    // supply set PD_TOP.primary: IEEE 1801-2024 4.7.3, 4.7.4, 6.5.6, 9.3.2, 5.7.8
    begin : openpa_ss_PD_TOP_primary
      bit nx; int sm;
      sm = (UPF::openpa_net_PD_TOP_primary_power.state == UPF::FULL_ON && UPF::openpa_net_PD_TOP_primary_ground.state == UPF::FULL_ON) ? 0 : 5;   // predefined ON (NORMAL) or OFF (CORRUPT), IEEE 1801-2024 4.7.4
      openpa_ss_PD_TOP_primary_sim = sm;
      nx = sm < 5;
      if (openpa_ss_PD_TOP_primary_ok && !nx) openpa_ss_PD_TOP_primary_ep = openpa_ss_PD_TOP_primary_ep + 1;
      openpa_ss_PD_TOP_primary_ok = nx;
    end
    // domain PD_TOP: simstate of its primary supply set PD_TOP.primary
    if (openpa_dom_PD_TOP_ok && !UPF::openpa_ss_PD_TOP_primary_ok) openpa_dom_PD_TOP_ep = openpa_dom_PD_TOP_ep + 1;
    openpa_dom_PD_TOP_ok = UPF::openpa_ss_PD_TOP_primary_ok;
    openpa_dom_PD_TOP_sim = openpa_ss_PD_TOP_primary_sim;
  end

  // ---- corruption: registers forced, memories overwritten (rules C1, C3)
  // domain PD_TOP (pmu_soc.upf:3): 4 register(s), 1 memory(ies)
  bit openpa_PD_TOP_applied, openpa_PD_TOP_valid;
  logic [7:0] openpa_cv1;   // corruption value for status
  logic [7:0] openpa_cv2;   // corruption value for u_core.acc
  logic [3:0] openpa_cv3;   // corruption value for u_core.beats
  logic [2:0] openpa_cv4;   // corruption value for u_pmu.st
  // The first evaluation counts as a power-up from OFF: registers take the corruption value even when the
  // supplies are already on at time 0 (rule C3), so 4-state and 2-state runs start alike.
  always @(UPF::openpa_dom_PD_TOP_ok or openpa_kick) if (!openpa_PD_TOP_valid || openpa_PD_TOP_applied != UPF::openpa_dom_PD_TOP_ok) begin
    openpa_t({"PD_TOP ", UPF::openpa_dom_PD_TOP_ok ? "NORMAL" : "CORRUPT"});
    if (!UPF::openpa_dom_PD_TOP_ok || !openpa_PD_TOP_valid) begin
      if (openpa_xmode) openpa_cv1 = 'x; else openpa_cv1 = UPF::openpa_mix(1, UPF::openpa_dom_PD_TOP_ep, 0);
      force status = openpa_cv1;
      if (openpa_xmode) openpa_cv2 = 'x; else openpa_cv2 = UPF::openpa_mix(2, UPF::openpa_dom_PD_TOP_ep, 0);
      force u_core.acc = openpa_cv2;
      if (openpa_xmode) openpa_cv3 = 'x; else openpa_cv3 = UPF::openpa_mix(3, UPF::openpa_dom_PD_TOP_ep, 0);
      force u_core.beats = openpa_cv3;
      if (openpa_xmode) openpa_cv4 = 'x; else openpa_cv4 = UPF::openpa_mix(4, UPF::openpa_dom_PD_TOP_ep, 0);
      force u_pmu.st = openpa_cv4;
      for (int i = 0; i < 4; i++) u_core.rf[0 + i] = openpa_xmode ? 8'bx : UPF::openpa_mix(100000, UPF::openpa_dom_PD_TOP_ep, (i) * 1 + 0);
    end
    if (UPF::openpa_dom_PD_TOP_ok) begin
      for (int i = 0; i < 4; i++) u_core.rf[0 + i] = openpa_xmode ? 8'bx : UPF::openpa_mix(100000, UPF::openpa_dom_PD_TOP_ep, (i) * 1 + 0);
      release status;
      release u_core.acc;
      release u_core.beats;
      release u_pmu.st;
    end
    openpa_PD_TOP_valid = 1'b1; openpa_PD_TOP_applied = UPF::openpa_dom_PD_TOP_ok;
  end

  // ---- observation for differential corruption (+openpa_obs): design-top outputs while the top domain is on
  `ifdef OPENPA_OBS
  longint openpa_obs_after;
  initial if (!$value$plusargs("openpa_obs_after=%d", openpa_obs_after)) openpa_obs_after = 0;
  always @(total) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: total=%h", $time, total);
  always @(led) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: led=%h", $time, led);
  always @(rd) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: rd=%h", $time, rd);
  always @(beats) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: beats=%h", $time, beats);
  always @(status) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: status=%h", $time, status);
  always @(pmu_state) if (openpa_obs && UPF::openpa_dom_PD_TOP_ok && $time >= openpa_obs_after) $display("OPENPA-OBS @ %0t: pmu_state=%h", $time, pmu_state);
  `else
  initial if ($test$plusargs("openpa_obs")) $display("OPENPA-ERROR +openpa_obs needs the copy compiled with OPENPA_OBS defined (-DOPENPA_OBS or +define+OPENPA_OBS)");
  `endif

  // Icarus 12 runs no named block inside a final block, so the report is a function.
  function automatic void openpa_cover_report();
      int hs, ht, hq;
      hs = 0; ht = 0; hq = 0;
      $display("OPENPA-COVER-SUMMARY states=%0d/0 declared_transitions=%0d/0 sequences=%0d/0", hs, ht, hq);
  endfunction

  // ---- settle process: 0 deferred check(s), run after one #0 in a fixed order
  initial forever begin
    wait (openpa_sreq && openpa_kick);
    #0;
    openpa_sreq = 1'b0;
  end
  final begin
    $display("OPENPA-SUMMARY D1=%0d D2=%0d D3=%0d D4=%0d D5=%0d D6=%0d D7=%0d D8=%0d D9=%0d D10=%0d D11=%0d D12=%0d D13=%0d D14=%0d", openpa_n[1], openpa_n[2], openpa_n[3], openpa_n[4], openpa_n[5], openpa_n[6], openpa_n[7], openpa_n[8], openpa_n[9], openpa_n[10], openpa_n[11], openpa_n[12], openpa_n[13], openpa_n[14]);
    openpa_cover_report();
    if (!UPF::openpa_armed) $display("OPENPA-WARNING no supply was driven (supply_on/supply_off never called): every domain stayed CORRUPT");
  end
  // verilator lint_on MULTIDRIVEN
`line 59 "pmu_soc.sv" 0
endmodule

`line 1 "pmu.sv" 0
// pmu_soc: the always-on power controller. Power-unaware RTL: it only drives control signals.
// Sleep: isolate, save, switch off. Wake: switch on, reset, restore, release isolation.
module pmu (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       sleep_req,
  input  logic       wake_req,
  output logic       iso_en,
  output logic       save,
  output logic       restore,
  output logic       pwr_en,
  output logic       core_rst_n,
  output logic [2:0] state_o
);
  typedef enum logic [2:0] { RUN, ISOLATE, SAVE, OFF, PWRUP, RESET, RESTORE, RELEASE } st_e;
  st_e st;
  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) st <= RUN;
    else case (st)
      RUN:     if (sleep_req) st <= ISOLATE;
      ISOLATE: st <= SAVE;
      SAVE:    st <= OFF;
      OFF:     if (wake_req) st <= PWRUP;
      PWRUP:   st <= RESET;
      RESET:   st <= RESTORE;
      RESTORE: st <= RELEASE;
      RELEASE: st <= RUN;
      default: st <= RUN;
    endcase
  assign iso_en     = (st != RUN);
  assign save       = (st == SAVE);
  assign restore    = (st == RESTORE);
  assign pwr_en     = !(st == OFF);
  assign core_rst_n = rst_n && (st != RESET);
  assign state_o    = st;
endmodule

`line 1 "core.sv" 0
// pmu_soc: the switchable core. An accumulator, a beat counter and a 4-word register file.
// Power-unaware RTL: nothing here knows about supplies.
module core (
  input  logic       clk,
  input  logic       rst_n,
  input  logic       en,
  input  logic [7:0] d,
  input  logic [1:0] rf_addr,
  input  logic       rf_we,
  output logic [7:0] acc,
  output logic [7:0] rf_rd,
  output logic       busy,
  output logic [3:0] beats
);
  logic [7:0] rf [0:3];
  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) begin
      acc   <= '0;
      beats <= '0;
    end else if (en) begin
      acc   <= acc + d;
      beats <= beats + 4'd1;
    end
  always_ff @(posedge clk)
    if (rf_we) rf[rf_addr] <= acc;
  assign rf_rd = rf[rf_addr];
  assign busy  = en;
endmodule

ConceptWhich tools read the same UPF file in a normal low-power flow?
ConceptOpenPA reports "character U+2013 is an en dash" on line 3. What do you change?
ConceptA file declares upf_version 1.0. Its isolation strategy has no -applies_to option. OpenPA isolates 6 crossings. With upf_version 4.0 it isolates 12. Why?
ConceptIn hub.upf, all three domains in the report point to line 16. What is on that line?
ConceptA UPF file on this site uses exec to read the date. What happens?

Common Mistakes

Wrong Write isolation cells and supply checks into the RTL by hand.

The RTL then describes one power architecture only. Synthesis, place and route and the simulator can no longer share one description.

Fix Keep the RTL power-unaware and put the power intent in a UPF file that every tool reads.

Wrong Write the year of the standard after upf_version, such as upf_version 2024.

The standard defines the string "4.0" for IEEE 1801-2024 (6.61). OpenPA refuses a year such as 2024.

Fix Write upf_version 4.0 as the first line of a file written for IEEE 1801-2024.

Wrong Copy a UPF command from a slide or PDF straight into a file.

Slides turn the minus sign into a dash and straight quotes into curly ones. Tcl does not read either as syntax.

Fix Retype options and quotes, or run the file through a reader that names the bad character.

Remember

  • UPF keeps power intent in its own file. The RTL stays power-unaware, and every tool reads the same intent.
  • upf_version names the edition. IEEE 1801-2024 calls itself "4.0", and defaults differ between editions.
  • set_design_top names the module a file was written for.
  • OpenPA stops at the first error and names the line. Slide characters and misspelled options are common causes.
  • UPF is Tcl. A proc and a foreach loop can write repeated commands once.

Practice

Report a problem with this page