On 23 January 2017 at 20:35, Andrew Waterman <
and...@sifive.com> wrote:
> On Mon, Jan 23, 2017 at 6:23 AM, Alex Bradbury <
a...@asbradbury.org> wrote:
>> On 22 January 2017 at 13:36, Andrew Waterman <
and...@sifive.com> wrote:
>>> Some M-mode implementations might choose to alias cycle to mcycle and
>>> instret to minstret. That likely won't be the case for time/mtime,
>>> which may not be backed by a CSR at all.
>>>
>>> In any case, M-mode software must be written with knowledge of the
>>> underlying hardware platform, and generally won't be portable, so this
>>> is a very minor quibble.
>>
>> Thanks Andrew, I've started a new thread to try to further clarify
>> this issue of what a developer or compiler can expect from an
>> M-mode-only implementation
>> <
https://groups.google.com/a/groups.riscv.org/d/msg/isa-dev/I3og57V1aHg/WVSjLVOzAQAJ>.
>> Surely you don't mean that an author of code that might run in M-mode
>> (e.g. on a RISC-V microcontroller) must be written with the knowledge
>> of which instructions are handled by trapping on a certain
>> implementation (and indeed, whether misaligned loads/stores trap)?
>
> Unavoidably, the authors of the support code that emulates missing
> instructions must know which features are implemented without
> trapping. Likewise, the authors of any trap handlers that don't spill
> enough of the context to recover from an exception must know.
Fully agreed, trap handlers and the like must be written with
awareness of core implementation details such as which instructions
might cause another trap.
> The authors of application code running in M-mode can be ignorant of
> this information, if they are willing to pay for the support code to
> be linked in. But some people will want to run M-mode code without
> linking in the support library (e.g., to reduce code size, or reduce
> the size of the trusted code base), in which case they also must be
> aware of what the hardware actually supports. I think we want to
> cater to both use cases.
This is obviously something people people can do as a last resort to
try to save some binary size, or on a deeply embedded system where the
implementer willing to pay the cost of moving away from being
'standard' RISC-V. However I'd be really concerned about this becoming
the norm for standalone M-mode-only RISC-V microcontrollers.
If I author, for instance, an MP3 decoder library in a mix of C and
RISC-V assembly then surely I should be confident that same library
will work without source modification across anything that claims to
support a sufficient RISC-V ISA subset. This means ignoring
performance I shouldn't have to care if it gets compiled for an
M-mode-only system, if some instructions are handled by trapping, or
if the library might produce misaligned memory accesses. The
specification seems quite clear that to be RISC-V, misaligned access
must be supported "The base ISA supports misaligned accesses, but
these might run extremely slowly depending on the implementation."
(p18
https://content.riscv.org/wp-content/uploads/2016/06/riscv-spec-v2.1.pdf).
If a core+SDK can't handle misaligned accesses, it loses compatibility
with the rest of the RISC-V ecosystem and I don't see how it can
reasonably be described as being RISC-V compliant.
> We need to have some way of describing what features the hardware
> actually supports. Perhaps the Foundation should create the notion of
> implementation profiles, which are standard sets of features that
> M-mode programmers can expect to exist. These can form compiler
> targets, so C programmers need not know the details.
Having a standard way of describing what does/doesn't trap could
certainly be helpful both for compiler code generation and for people
trying to write efficient assembly routines for M-mode targets.
Echoing my concern above: defining profiles that don't provide minimal
traps for misaligned memory accesses and unimplemented instructions
risks fragmenting the ecosystem by providing additional subsets to the
"base" RV32I/E functionality. Of course it should be possible for
people to do this just as they can pursue other non-standard
extensions or modifications, but calling these subsets "RISC-V" would
rather destroy the idea of RV32I/E providing a common minimal
baseline.
Best,
Alex