VREM.VV

RISC-V VREM.VV Instruction Details

Instruction ManualOPMVV (OP-V)

VREM.VV computes signed SEW remainders for active elements; a nonzero remainder has the dividend’s sign, and a zero divisor returns the dividend.

Instruction Syntax

vrem.vv vd, vs2, vs1, vm
Operand Breakdown
Syntax: vrem.vv vd, vs2, vs1[, v0.t]; omit the mask for vm=1, include v0.t for vm=0. 32-bit OP-V: opcode=1010111, funct3=010 (OPMVV), funct6=100011.
vs2[i] is the dividend and vs1[i] is the divisor, interpreted as signed SEW integers. A nonzero remainder has the dividend's sign. A zero divisor returns the dividend; minimum divided by -1 returns remainder zero.
Active body satisfies vstart≤i<vl with the mask enabled. Inactive/tail follow vma/vta: retain or agnostic, without a fixed value to rely on. vl=0 updates no destination elements.
Same-width sources/destination may overlap. Masked vd cannot be v0; v0 cannot provide both the EEW=1 mask and SEW data. Group starts align to EMUL, EMUL≤8.
Require V 1.0, enabled vector state and valid supported vtype/SEW. The animation fixes m1, vstart=0 and VLEN=4096; teaching steps are not processor cycles.
VVector IntegerDivide/Remainder

Instruction Behavior

VREM.VV is a RISC-V V extension vector-vector signed integer remainder instruction. Each active element uses vs2 as the dividend and the same-lane vs1 element as the divisor, computes the SEW-width remainder, and writes vd; zero divisors and signed overflow cases use the official specified results without a divide-by-zero trap.

VREM.VV Decode And Execute Animation

Starts from OP-V encoding fields, then shows how VREM computes each signed remainder and applies the official divide-by-zero and signed-overflow special cases.

Instruction input
vrem.vv

Require V 1.0, enabled vector state and valid supported vtype/SEW. Fix LMUL=m1, vstart=0, VLEN=4096 and VLMAX=4096/16=256. An ordinary masked vd cannot be v0; equal-width source/destination overlap is legal. Both sources are interpreted as signed SEW integers; a nonzero remainder has the dividend’s sign. Enter nonnegative SEW bit patterns. When v0 supplies the EEW=1 mask it cannot also supply SEW data. VL=0 updates no destination elements. Only body is shown without definite inactive/tail values. Steps are teaching stages, not processor cycles.

Execution Context
OP-V encodingvrem.vv
funct6
100011
vm
0
vs2
01000
vs1
01100
funct3
010
vd
00100
opcode
1010111
lane
0
1
2
3
4
5
6
7
v8
0x0064
0xffd6
0x8000
0x007f
0xffff
0x0001
0x0064
0xffd6
%
%
%
%
%
%
%
%
v12
0x0009
0x0000
0xffff
0xffff
0x0003
0x0001
0x0009
0x0000
v0.t
1
0
1
1
1
0
1
1
v4
...
-
...
...
...
-
...
...
Current step

Show OP-V 32-bit encoding fields

vrem.vv uses OP-V encoding. The animation places fixed fields, register fields, vm, and the vs1 field in one encoding strip.

This animation shows OP-V field decode, active-element reads, SEW-width signed integer remainder, mask control, and vd writeback. These are teaching stages; they do not model pipelines, caches, or timing.

Quick Understanding & Search Notes

VREM.VV does not raise a divide-by-zero exception. For active elements within the current vl, it reads vs2 as the dividend and the same-lane vs1 element as the divisor, writes the signed remainder, and with vm=0 only body elements whose v0.t bit is 1 execute.

VREM.VV uses 32-bit OP-V encoding: opcode=1010111, funct3=010 (OPMVV), funct6=100011.
vs2 is the dividend and the divisor comes from the same-lane vs1 element; each lane is computed independently with no cross-lane combination.
Operands are interpreted as signed two's-complement SEW integers, and the result is the remainder.
When the divisor is zero, the remainder result is the dividend SEW-bit pattern.
For signed minimum divided by -1 overflow, VDIV writes the dividend and VREM writes zero.
With vm=0, v0.t is the execution mask; masked-off and tail elements follow the current vtype policies.
The signed quotient rounds toward zero; a nonzero remainder has the dividend’s sign. Require enabled vector state and valid supported vtype/SEW; vl=0 updates no destination elements.

Vector Execution Context

Syntax: vrem.vv vd, vs2, vs1[, v0.t]; omit the mask for vm=1, include v0.t for vm=0. 32-bit OP-V: opcode=1010111, funct3=010 (OPMVV), funct6=100011.

vs2[i] is the dividend and vs1[i] is the divisor, interpreted as signed SEW integers. A nonzero remainder has the dividend's sign. A zero divisor returns the dividend; minimum divided by -1 returns remainder zero.

Active body satisfies vstart≤i<vl with the mask enabled. Inactive/tail follow vma/vta: retain or agnostic, without a fixed value to rely on. vl=0 updates no destination elements.

Same-width sources/destination may overlap. Masked vd cannot be v0; v0 cannot provide both the EEW=1 mask and SEW data. Group starts align to EMUL, EMUL≤8.

Require V 1.0, enabled vector state and valid supported vtype/SEW. The animation fixes m1, vstart=0 and VLEN=4096; teaching steps are not processor cycles.

The RISC-V Instruction Set Manual, Volume I: Unprivileged Architecture — Version 20260120, Chapter 31

Common Usage Scenarios

Element-wise signed remainder

Assume enabled V/VS, valid m1, supported SEW, VLEN≥128, vl=4, vstart=0, v0.mask[0..3]=1111 and initialized sources. SEW=8, v12=[249(-7),7,128(-128),5], v4=[3,253(-3),255(-1),0] → v8=[255(-1),1,0,5]. Compute element-wise remainders; inactive/tail follow vma/vta. vl=0 leaves the destination unchanged.

Masked vector remainder

Assume enabled V/VS, valid m1, supported SEW, VLEN≥128, vl=4, vstart=0, v0.mask[0..3]=1111 and initialized sources. SEW=8, v12=[249(-7),7,128(-128),5], v4=[3,253(-3),255(-1),0] → v8=[255(-1),1,0,5]. Compute element-wise remainders; inactive/tail follow vma/vta. vl=0 leaves the destination unchanged.

Pre-Use Checklist

Syntax Check
  • Syntax: vrem.vv vd, vs2, vs1[, v0.t]; omit the mask for vm=1, include v0.t for vm=0. 32-bit OP-V: opcode=1010111, funct3=010 (OPMVV), funct6=100011.
  • vs2[i] is the dividend and vs1[i] is the divisor, interpreted as signed SEW integers. A nonzero remainder has the dividend's sign. A zero divisor returns the dividend; minimum divided by -1 returns remainder zero.
Semantic Check
  • Active body satisfies vstart≤i<vl with the mask enabled. Inactive/tail follow vma/vta: retain or agnostic, without a fixed value to rely on. vl=0 updates no destination elements.
  • Same-width sources/destination may overlap. Masked vd cannot be v0; v0 cannot provide both the EEW=1 mask and SEW data. Group starts align to EMUL, EMUL≤8.
  • Require V 1.0, enabled vector state and valid supported vtype/SEW. The animation fixes m1, vstart=0 and VLEN=4096; teaching steps are not processor cycles.

Pitfalls / Common Confusions

A zero divisor does not trap; software that needs an error path must test divisors explicitly.
The signed minimum divided by -1 case is architecturally defined: divide writes the dividend, and remainder writes zero.
The second source is the same-lane element of vs1; there is no scalar-divided-by-vector reverse form.

FAQ

Does VREM.VV trap on divide by zero?

No. The official V extension defines the divide-by-zero result: the remainder is the dividend, and the instruction itself does not raise a divide-by-zero trap.

How is VREM.VV related to VDIV?

VREM.VV writes the remainder; the paired VDIV form writes the quotient for the same divide relation. Both use the same divide-by-zero and signed-overflow special-case rules.