On Thu, Sep 27, 2018 at 7:34 PM, Andrew Waterman
<
wate...@eecs.berkeley.edu> wrote:
>
>
>
> On Thu, Sep 27, 2018 at 7:52 AM Luke Kenneth Casson Leighton <
lk...@lkcl.net>
> wrote:
>> when looking in processor_t::get_csr() there does not appear to be a
>> place where the instruction is decoded (a second time) such that it
>> may be determined if rd == x0
>>
>> is this an oversight?
>
>
>
> It is an oversight that there's not a comment explaining why this is
> OK: no standard CSRs, and no CSRs that Spike implements, have side
> effects on reads.
ok so the main priority: it's safe (spec-compliant). whew.
secondary: yes, with c++ being what it is (hidden overloading) a code
review of *just* get_csr would not necessarily pick up that accessing
the processor_t::state variable has (potential) side-effects, a
comment at the top of get_csr would be good [can create a patch if you
like?]
third, it's not necessarily optimal, i would be surprised if g++
notices that the old value isn't used and cuts out the entire call...
wait... csrrwi.h doesn't have the check to stop a write to the zero
reg...
... ah, it's in regfile_t:write (decode.h) - *that's* where the test
to see if writing to x0 results in the value to be written being
ignored.
ok so this is more about optimisation than anything, and if CSR
setting/getting is not a major activity it could be argued that
developer time is better spent elsewhere (80/20 rule)
> Can cross that bridge if a proposed standard adds
> CSRs with side effects on reads (which I think many people would like
> never to happen).
agreed. however... it'll be something that i could see catching out
people writing custom CSRs and/or people with less experience with
RISC-V. particularly when their first port of call would be to go "hm
done the spec, what's the next bit, ah yes: write a proof-of-concept
by implementing the custom extension in spike".
they would then find that the code's specifically not designed to
allow them to do that. or, worse, they *don't* find it, and spend
considerable time debugging [and eventually come here and spend list
members' cpu cycles on enquiries finding out why]
>> secondly, there may be a potential conflict in how SETVL is to be
>> implemented using CSRs,
>> [...]
>> now, it could be reasonably claimed that the implementation of SETVL
>> "reading the CSR" could have "side-effects" which involve actually
>> setting VL: it's a bit of a stretch, and, honestly, in SV i feel i may
>> end up having to have a special-case version of csrrwi.h, which would
>> be a bit of a nuisance, but doable.
>
>
> It is indeed a stretch, which is why, as of a July 2017 draft, RVV
> doesn't use CSRRW to implement SETVL. It is its own instruction,
> which just happens to manipulate CSRs.
okaay. and i've just noticed there's a cross-reference now to
https://github.com/riscv/riscv-v-spec been added to
V20180801-draft - excellent!
https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#code-vl-code-and-code-vsetvl-code-instruction
ok yes, got it: that's clear, "vsetvl not encoded as regular
CSRRW.... regular CSR can still read/write it"
damn. that's a pain. if implementing [SV]SETVL as a CSRRWI
overload, SV requires absolutely no new instructions whatsoever. may
just have to bite the bullet on that one and use an I-type encoding
(SV's SETVL is of the form SETVL t0, a0, #imm)
thanks for clarifying, andrew.
l.