Last time, I sorted out what happens to the values of elements beyond vl and elements masked off, in the four combinations of tu/ta and mu/ma, and looked at resuming from an exception using vstart.
From this installment we move on to vector loads and stores.
First, let's pin down the "instruction-side element width" that only loads and stores have.
The Element Width of Arithmetic Instructions Is Determined by vtype
A vector arithmetic instruction receives the width of the elements it processes from the SEW field of vtype.
If SEW=32 is set, each element of the vector register is divided into 32-bit units and operated on; if SEW=64 is set, it is divided into 64-bit units.
The same vadd.vv instruction becomes either a 32-bit add or a 64-bit add depending on the vtype setting.

For this reason, most arithmetic instructions carry no information about the operation width in the instruction itself.
vadd.vv only expresses "do an integer add", and its width is decided at run time by looking at vtype.
The exceptions are the widening instructions that double the width and the narrowing instructions that halve it, and these too use SEW as the reference, in the form "twice SEW".
Only Loads and Stores Have an Element Width
However, unit-stride and strided loads and stores do not take the element width from SEW.
A separate instruction is defined for each element width to load: vle8.v / vle16.v / vle32.v / vle64.v, so the instruction itself carries the element width in memory.
This instruction-side element width is called EEW (effective element width).
Only indexed loads and stores take the data width from SEW and use the instruction's EEW for the width of the indices, but I'll cover that in Part 8.
Therefore, the instruction's EEW and the SEW in vtype do not have to match.
In the following code, an EEW=64 load is executed while SEW stays at 32.
vsetvli t0, a0, e32, m1, ta, ma # SEW=32, LMUL=1 vle64.v v8, (a1) # EEW=64
The reason the specification allows this is to reduce vtype switching in loops that mix widths.
As a concrete example, consider a loop that adds 16-bit samples x[i] into 32-bit accumulated values y[i].
We want to compute in 32 bits, so vtype is set to e32, but we want to read x from memory as 16 bits.
loop:
vsetvli t0, a0, e32, m1, ta, ma # set once, with the 32-bit compute width
vle16.v v8, (a1) # EEW=16, EMUL=1/2: read x as 16 bits
vzext.vf2 v9, v8 # zero-extend 16 bits to 32 bits
vle32.v v10, (a2) # EEW=32, EMUL=1: read y
vadd.vv v10, v10, v9
vse32.v v10, (a2) # EEW=32, EMUL=1
slli t1, t0, 1
add a1, a1, t1 # x is 2 bytes per element
slli t1, t0, 2
add a2, a2, t1 # y is 4 bytes per element
sub a0, a0, t0
bnez a0, loop
In this loop, vsetvli appears only once at the top, and both the 16-bit load of x and the 32-bit load and store of y run under the same vtype.
vl is the same value for both loads, so the number of x elements and y elements read in one iteration naturally match.
vle16.v reads vl elements at 16-bit width, so it fills only the first half of v8, and vzext.vf2 widens them to 32 bits to fill v9.
vzext.vf2 is covered in Part 12.

If the design took the load/store width from SEW as well, we would have to insert vsetvli twice per iteration: switching to e16, mf2 before reading x and to e32, m1 before computing.
And to keep vl the same across the two settings, LMUL would also have to be changed to match the width.
By giving the instruction its own EEW, the difference in width is absorbed into the name of the load instruction, and vtype only needs to express the compute width.
When EEW and SEW Differ, EMUL Changes
When EEW and SEW differ, the number of elements does not change; only the element width follows the instruction.
The number of elements is the vl that vsetvli decided from SEW and LMUL, and the load reads vl elements of EEW bits.
For example, with VLEN=512, SEW=32, and LMUL=1, vl is at most 16.
If an EEW=64 load is executed in this state, 16 elements of 64 bits, 1024 bits in total, are written, which spans two vector registers.
This is not an illegal instruction; the load really is performed across two vector registers.
Spanning two vector registers can be thought of as this load alone running with LMUL=2.
Because "the number of vector registers actually used is determined by SEW, EEW, and LMUL" in this way, it is called EMUL (effective LMUL).
EMUL is calculated as EMUL = (EEW / SEW) × LMUL, which gives (64 / 32) × 1 = 2 in the example above.
Conversely, if vle8.v is executed with SEW=32 and LMUL=1, EMUL = (8 / 32) × 1 = 1/4, and the fractional LMUL we saw in Part 3 is used here.

| SEW | LMUL | Load instruction | EEW | EMUL |
|---|---|---|---|---|
| 32 | 1 | vle64.v |
64 | 2 |
| 32 | 1 | vle32.v |
32 | 1 |
| 32 | 1 | vle8.v |
8 | 1/4 |
| 16 | 4 | vle32.v |
32 | 8 |
| 8 | 8 | vle16.v |
16 | 16 (reserved) |
However, EMUL has a valid range.
Combinations where EMUL exceeds 8 or falls below 1/8 are reserved in the instruction encoding, and as in the last row of the table, an EEW wider than SEW cannot be used with LMUL=8.
Also, the register number must be on a correct boundary for EMUL: with EMUL=2 an even number must be specified, and with EMUL=4 a multiple of 4.
This is why the destination in the code above was v8; specifying v9 would make it reserved.
Series table of contents: Introduction to the RISC-V Vector Extension: Table of Contents
This is an English translation of the original Japanese post: RISC-V Vector Extension 入門(6):ベクトルロード・ストアの共通事項、EEW と EMUL