snez

RISC-V snez Pseudo-Instruction Details

Assembler pseudo-instruction

RISC-V snez pseudo-instruction expands to sltu rd, x0, rs. SLTU is an unsigned comparison; this form writes 1 to rd only when rs is not zero, otherwise 0.

What You Write
snez rd, rs
Typical Real Expansion
sltu rd, x0, rs

What This Pseudo Instruction Is Saving You From Writing

Directly expresses a nonzero test: SLTU uses unsigned comparison, so 0 < rs if and only if rs != 0. The result is 1 when rs is nonzero and 0 otherwise.

snez is assembler shorthand. Read its official sltu rd, x0, rs expansion and use the ISA definition of SLTU for its behavior.

Official Semantics Checklist

The official assembly manual treats snez as an assembler-level pseudo-instruction or alias; hardware executes the expanded real instruction sequence.
The real semantics come from the ISA definitions of SLTU and the other expanded instructions, not from a separate snez hardware opcode.

How To Read The Expansion

Step 1
Assembler expands to sltu rd, x0, rs.
Step 2
SLTU performs unsigned comparison: if x0(0) < rs (i.e., rs != 0), rd = 1; else rd = 0.

Assembly Forms And Real Instructions

The RISC-V Assembly Programmer's Manual gives the expansion sltu rd, x0, rs.

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

Need rd to be 1 when rs is not zero and 0 otherwise
Use the official assembly spelling snez rd, rs

Pitfalls / Common Confusions

SNEZ expands through the unsigned comparison SLTU.
SLTU rd, x0, rs writes 1 when rs is not zero, otherwise 0.

FAQ

Is snez a real RISC-V instruction?

snez 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 snez?

SNEZ is unsigned-based — but 0 < rs (unsigned) iff rs != 0, semantically correct in all cases