VSUB.VX

RISC-V VSUB.VX Instruction Details

Instruction ManualOPIVX

VSUB.VX subtracts an integer scalar from active vs2 elements, keeping low SEW bits.

Instruction Syntax

vsub.vx vd, vs2, rs1, vm
Operand Breakdown
vd/vs2 are aligned EEW=SEW, EMUL=LMUL groups. Equal-width source/destination overlap is legal; equal sources read equal values. The rs1 scalar takes low SEW bits for XLEN>SEW and sign-extends for XLEN<SEW; x0 supplies zero.
32-bit OP-V: opcode=1010111, funct6=000010, funct3=100; vm at bit25, vs2 at bits24:20, rs1 at bits19:15, vd at bits11:7.
Active vd[i]=(vs2[i] - the converted scalar) mod 2^SEW, without a borrow flag, integer overflow trap, saturation or vxsat change. VRSUB reverses the subtraction direction.
Require RV32/RV64 V 1.0, enabled vector state, vill=0 and supported vtype/SEW. v0.t means vm=0; omission means vm=1. Only mask-enabled vstart<=i<vl elements compute; prestart stays unchanged, inactive/tail follow vma/vta, retaining or all ones; masked vd excludes v0. vstart>=vl (including vl=0) leaves vd unchanged; v0 cannot supply both EEW=1 mask and data. Success resets vstart=0.
VVector Operations

Instruction Behavior

VSUB.VX computes vs2[i] - scalar for active elements, wrapping at SEW width. The rs1 scalar uses low SEW bits when XLEN>SEW and is sign-extended when XLEN<SEW; x0 supplies zero.

VSUB.VX Decode And Execute Animation

Starts from OP-V encoding fields, then shows how VSUB subtracts the second source from vs2, wraps at SEW, and writes vd.

Instruction input
vsub.vx

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. XLEN>SEW takes low scalar bits; XLEN<SEW sign-extends; x0 supplies zero. 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 encodingvsub.vx
funct6
000010
vm
0
vs2
01000
rs1
01011
funct3
100
vd
00100
opcode
1010111
lane
0
1
2
3
4
5
6
7
v8
0x00fa
0x010b
0x011c
0x012d
0x013e
0x014f
0x0160
0x0171
-
-
-
-
-
-
-
-
x11
0x0013
0x0013
0x0013
0x0013
0x0013
0x0013
0x0013
0x0013
v0.t
1
0
1
1
1
0
1
1
v4
...
-
...
...
...
-
...
...
Current step

Show OP-V 32-bit encoding fields

vsub.vx uses OP-V encoding. The animation places fixed fields, register fields, vm, and the rs1 field in one encoding strip.

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

Quick Understanding & Search Notes

VSUB.VX computes vs2[i] - scalar for active elements, wrapping at SEW width. The rs1 scalar uses low SEW bits when XLEN>SEW and is sign-extended when XLEN<SEW; x0 supplies zero.

32-bit OP-V: opcode=1010111, funct6=000010, funct3=100; vs2 is the minuend. Keep low SEW bits without a borrow flag, integer overflow trap or vxsat change.
Require RV32/RV64 V 1.0, enabled vector state, vill=0 and supported vtype/SEW. Active elements have vstart<=i<vl and, with vm=0, v0.mask[i]=1. Omitting v0.t means vm=1.
Prestart stays unchanged; inactive/tail follow vma/vta, retaining old values or becoming all ones. vstart>=vl (including vl=0) updates no destination elements; success resets vstart=0.
Vector EEW=SEW, EMUL=LMUL; group starts must align. Equal-width source/destination overlap is allowed; equal sources read equal values. Masked vd excludes v0, which cannot supply both mask and SEW data.
The rs1 scalar uses low SEW bits for XLEN>SEW and sign-extends for XLEN<SEW; x0 supplies zero.

Vector Execution Context

vd/vs2 are aligned EEW=SEW, EMUL=LMUL groups. Equal-width source/destination overlap is legal; equal sources read equal values. The rs1 scalar takes low SEW bits for XLEN>SEW and sign-extends for XLEN<SEW; x0 supplies zero.

32-bit OP-V: opcode=1010111, funct6=000010, funct3=100; vm at bit25, vs2 at bits24:20, rs1 at bits19:15, vd at bits11:7.

Active vd[i]=(vs2[i] - the converted scalar) mod 2^SEW, without a borrow flag, integer overflow trap, saturation or vxsat change. VRSUB reverses the subtraction direction.

Require RV32/RV64 V 1.0, enabled vector state, vill=0 and supported vtype/SEW. v0.t means vm=0; omission means vm=1. Only mask-enabled vstart<=i<vl elements compute; prestart stays unchanged, inactive/tail follow vma/vta, retaining or all ones; masked vd excludes v0. vstart>=vl (including vl=0) leaves vd unchanged; v0 cannot supply both EEW=1 mask and data. Success resets vstart=0.

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

Common Usage Scenarios

Element-wise vector differences

Assume enabled V/VS, valid m1,tu,mu, VLEN=4096, vl=4, vstart=0, v0.mask[0..3]=1101; SEW=8, v12=[0,1,255,7], XLEN=64, x5=1. v8[0]=255, v8[1]=0, v8[3]=6. Lane2 and tails keep old values; vxsat stays unchanged. Success resets vstart=0.

Vector data subtraction

Assume enabled V/VS, valid m1,tu,mu, VLEN=4096, vl=4, vstart=0, v0.mask[0..3]=1101; SEW=8, v12=[0,1,255,7], XLEN=64, x5=1. v8[0]=255, v8[1]=0, v8[3]=6. Lane2 and tails keep old values; vxsat stays unchanged. Success resets vstart=0.

Pre-Use Checklist

Syntax Check
  • vd/vs2 are aligned EEW=SEW, EMUL=LMUL groups. Equal-width source/destination overlap is legal; equal sources read equal values. The rs1 scalar takes low SEW bits for XLEN>SEW and sign-extends for XLEN<SEW; x0 supplies zero.
  • 32-bit OP-V: opcode=1010111, funct6=000010, funct3=100; vm at bit25, vs2 at bits24:20, rs1 at bits19:15, vd at bits11:7.
Semantic Check
  • Active vd[i]=(vs2[i] - the converted scalar) mod 2^SEW, without a borrow flag, integer overflow trap, saturation or vxsat change. VRSUB reverses the subtraction direction.
  • Require RV32/RV64 V 1.0, enabled vector state, vill=0 and supported vtype/SEW. v0.t means vm=0; omission means vm=1. Only mask-enabled vstart<=i<vl elements compute; prestart stays unchanged, inactive/tail follow vma/vta, retaining or all ones; masked vd excludes v0. vstart>=vl (including vl=0) leaves vd unchanged; v0 cannot supply both EEW=1 mask and data. Success resets vstart=0.

Pitfalls / Common Confusions

The result wraps at SEW width and does not raise integer overflow exceptions.
Operand order is vs2 - vs1/rs1, not the reverse.
Use vrsub when scalar-minus-vector order is required.

FAQ

Is VSUB.VX scalar minus vector?

No. VSUB.VX is vs2[i] - x[rs1]. Use VRSUB.VX for scalar minus vector.

Where does the VSUB.VX scalar come from?

The VX scalar comes from integer register rs1 and is used for each active element.