rdinstret

Read instructions retired Pseudo-instruction

Reads the count of retired instructions into t1.

RISC-V manual: csrrs

Forms

Operands

t1
Any integer register, x0 to x31, or its named alias, such as zero, t0 or t6.
# Read the retired-instruction counter twice. Inspect t2=0: the second unsigned reading did not decrease.
.text
rdinstret t0
rdinstret t1
bltu t1, t0, backwards # Test whether the second reading is lower, treating both as unsigned.
li t2, 0
j done # Keep t2=0 by skipping the alternate result block.
backwards:
li t2, 1
done: