rdinstret

RISC-V rdinstret Pseudo-Instruction Details

Assembler pseudo-instruction

Read-instret-counter pseudo-instruction, expanding to csrrs rd, instret, x0. It reads the low XLEN bits of the retired-instruction counter.

What You Write
rdinstret rd
Typical Real Expansion
csrrs rd, instret, x0

What This Pseudo Instruction Is Saving You From Writing

Counters are read-only CSRs; the pseudo-instruction hides the fixed CSRRS rd, csr, x0 form and makes performance/time reads clearer.

rdinstret primarily means "Read low XLEN counter bits". It is assembler-level shorthand; when debugging, auditing, or reading machine code, reason from the real expansion and relocation semantics listed on this page.

Official Semantics Checklist

The official assembly manual treats rdinstret as an assembler-level pseudo-instruction or alias; hardware executes the expanded real instruction sequence.
The real semantics come from the ISA definitions of CSRRS and the other expanded instructions, not from a separate rdinstret hardware opcode.
CSR read, write, set, clear, and immediate behavior follows the Zicsr CSRRW/CSRRS/CSRRC instructions and their immediate variants.

Availability And Extension Conditions

Base Conditions
  • Zicntr counter CSR semantics
  • Reads the low XLEN bits of instret
Single-Instruction Or Standard Form
  • The target platform allows the current privilege level to read instret
Fallback / Boundary
If the platform or privilege level forbids counter reads, access may be unavailable or trap; a full 64-bit RV32 read needs rdinstreth and rollover handling.
Notes
  • instret counts retired instructions and differs from cycle and time.

How To Read The Expansion

Step 1
CSRRS reads the instret CSR; rs1=x0 leaves the counter unchanged.

What You May See In objdump / Disassembly

Disassembly may show rdcycle/rdtime/rdinstret or csrrs rd, csr, x0.

Official References And Reading Order

This page treats pseudo-instructions as assembler-level aliases or macros: first read what real instructions they expand to, then use the official ISA manual for the behavior of those real instructions. ABI, relocation, and linker-relaxation details follow the psABI document.

When To Think Of It First

Measure cycles or retired instructions for a short code region
Read a platform time base
Write benchmarks, runtime-library code, or low-level diagnostics

Pitfalls / Common Confusions

On RV32, reading a complete 64-bit counter usually needs the h-suffixed form and rollover handling
Whether lower privilege levels can read the counters depends on platform and CSR access control
In multicore or dynamic-frequency environments, cycle/time interpretation is platform-defined

FAQ

Is rdinstret a real RISC-V instruction?

rdinstret is an assembler pseudo-instruction or alias, not a separate hardware opcode. The “Typical Real Expansion” section lists the official expansion, and behavior is defined by the expanded ISA instructions.

What is the main trap when using rdinstret?

On RV32, reading a complete 64-bit counter usually needs the h-suffixed form and rollover handling