riscv-v-vstart

riscv vector vstart相关问题

vstart表示第一个参与计算的element的索引,是以SEW作为单位的。

关于vstart是否会报illegal instruction的问题,描述如下:

  • vstart的目的是,当某条指令执行到中间时,发生exception,硬件将发生exception的位置记录在vstart中,这样下次可以直接从这个位置继续执行。

  • 而vector只有访存类指令会在中间发生exception,所以一般情况下,只有访存类指令需要vstart。

  • 然而vstart作为一个独立于指令的寄存器,本质上对所有指令生效,那运算类指令理论上页会受vstart所影响,但如前面所说,其实运算类指令可以并不需要vstart。

  • 所以,结论是:当vstart不等于0时,运算类vector指令是否可以直接报illegal,在spec中明确指出,这种实现是合法的。换句话说,实现可以选择所有运算类vector指令在vstart不等于0时报illegal,也可以选择不报illegal来实现。

为了支撑这个结论,找到以下证据。

在spike源码中,有一个vstart_alu选项,是在编译时决定的,它决定了“所有运算类vector指令在vstart不等于0时是否报illegal”。默认情况下,vstart_alu=false,选择“所有运算类vector指令在vstart不等于0时报illegal”;如果增加该选择,vstart_alu=true,则选择“所有运算类vector指令在vstart不等于0时不报illegal”。

1
2
if (alu && !P.VU.vstart_alu) \
require(P.VU.vstart->read() == 0); \

而且waterman在spike的github中也回答了这个问题:

when 0<vstart<vl , executing vfadd.vv instruction, trap_illegal_instruction occurs · Issue #1282 · riscv-software-src/riscv-isa-sim · GitHub

aswaterman
commented
Mar 15, 2023

This behavior is entirely consistent with the spec:

Implementations are permitted to raise illegal instruction
exceptions when attempting to execute a vector instruction with a value
of vstart that the implementation can never produce when executing that
same instruction with the same vtype setting.

NOTE: For example, some implementations will never take
interrupts during execution of a vector arithmetic instruction, instead
waiting until the instruction completes to take the interrupt. Such
implementations are permitted to raise an illegal instruction exception
when attempting to execute a vector arithmetic instruction when vstart
is nonzero.

aswaterman
commented
Mar 15, 2023

For completeness, I will note that other
behaviors are legal. Executing the instruction in the obvious way,
starting from vstart, is also a valid implementation decision. We chose to adopt the most conservative implementation in
Spike for two reasons: it’s simple, and it discourages software
developers from misusing vstart.