Skip to content

Commit

Permalink
Add Zimop/Zcmop draft
Browse files Browse the repository at this point in the history
  • Loading branch information
aswaterman committed Sep 16, 2023
1 parent 4c55e04 commit 2463e2a
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/images/wavedrom/c-mop.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[wavedrom, ,svg]
....
{reg:[
{ bits: 2, name: 0x1, type: 8 },
{ bits: 5, name: 0x0 },
{ bits: 1, name: 0x1, type: 4 },
{ bits: 3, name: 'n[2:0]', type: 4 },
{ bits: 1, name: 0x0, type: 4 },
{ bits: 1, name: 0x0 },
{ bits: 3, name: 0x3 },
]}
....
15 changes: 15 additions & 0 deletions src/images/wavedrom/mop-r.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[wavedrom, ,svg]
....
{reg:[
{ bits: 7, name: 0x73, attr: ['SYSTEM'], type: 8 },
{ bits: 5, name: 'rd', type: 2 },
{ bits: 3, name: 0x4 },
{ bits: 5, name: 'rs1', type: 4 },
{ bits: 2, name: 'n[1:0]' },
{ bits: 4, name: 0x7 },
{ bits: 2, name: 'n[3:2]' },
{ bits: 2, name: 0x0 },
{ bits: 1, name: 'n[4]' },
{ bits: 1, name: 0x1 },
], config: {fontsize: 11}}
....
15 changes: 15 additions & 0 deletions src/images/wavedrom/mop-rr.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[wavedrom, ,svg]
....
{reg:[
{ bits: 7, name: 0x73, attr: ['SYSTEM'], type: 8 },
{ bits: 5, name: 'rd', type: 2 },
{ bits: 3, name: 0x4 },
{ bits: 5, name: 'rs1', type: 4 },
{ bits: 5, name: 'rs2', type: 4 },
{ bits: 1, name: 0x1 },
{ bits: 2, name: 'n[1:0]' },
{ bits: 2, name: 0x0 },
{ bits: 1, name: 'n[2]' },
{ bits: 1, name: 0x1 },
], config: {fontsize: 11}}
....
1 change: 1 addition & 0 deletions src/riscv-unprivileged.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ include::rvwmo.adoc[]
//rvwmo.tex
include::c-st-ext.adoc[]
//c.tex
include::zimop.adoc[]
include::b-st-ext.adoc[]
//b.tex
include::j-st-ext.adoc[]
Expand Down
72 changes: 72 additions & 0 deletions src/zimop.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[[zimop]]
== "Zimop" May-Be-Operations Extension, Version 0.1
This chapter defines the "Zimop" extension, which introduces the concept of
instructions that _may be operations_ (MOPs). MOPs are initially defined to
perform no useful operation and raise no exceptions, but might be redefined by
later extensions to perform some other action. The Zimop extension defines an
encoding space for 40 MOPs.

[NOTE]
====
It is sometimes desirable to define instruction-set extensions whose
instructions do not raise illegal-instruction exceptions when the extension is

This comment has been minimized.

Copy link
@gfavor

gfavor Sep 16, 2023

Collaborator

In the Priv spec "illegal instruction" exception does not have a hyphen.

not implemented. For example, programs with control-flow integrity checks can

This comment has been minimized.

Copy link
@gfavor

gfavor Sep 16, 2023

Collaborator

... is not implemented and are guaranteed to simply execute as a NOP.

This comment has been minimized.

Copy link
@aswaterman

aswaterman Sep 16, 2023

Author Member

Pedantically this isn't quite right because most of these instructions do the very un-NOP thing of writing x[rd]. But I see the sentiment you want to express; I'll find an alternative.

execute correctly on implementations without the corresponding extension,
provided the checks are simply ignored. Implementing these checks as MOPs
allows the same programs to run on implementations with or without the
corresponding extension.
Although similar in some respects to HINTs, most MOPs cannot be encoded as

This comment has been minimized.

Copy link
@gfavor

gfavor Sep 16, 2023

Collaborator

It seems like "most" should be dropped since the only point of MOPs is for instructions that cannot be encoded as HINTs. Otherwise, for instructions that can be encoded as HINTs, we (ARC) would force that choice to save the limited amount of MOP encoding space.

This comment has been minimized.

Copy link
@aswaterman

aswaterman Sep 16, 2023

Author Member

Good point. "Most" describes the universe of possible things, not the universe of advisable things.

HINTs, because MOPs might sometimes alter architectural state, which HINTs are

This comment has been minimized.

Copy link
@gfavor

gfavor Sep 16, 2023

Collaborator

... as HINTs because MOPs are allowed to alter architectural state while HINTs are forbidden from doing so.

forbidden from doing.
====

The Zimop extension defines 32 MOP instructions named `mop.r.__n__`, where
__n__ is an integer between 0 and 31, inclusive.
Unless redefined by another extension, these instructions simply write 0 to
`x[rd]`. Their encoding allows future extensions to define them to read `x[rs1]`,
as well as write `x[rd]`.

This comment has been minimized.

Copy link
@gfavor

gfavor Sep 16, 2023

Collaborator

Once a MOP instruction is redefined to have more interesting functionality, is its instruction mnemonic also allowed to be redefined? I imagine so, in which case that should probably also be stated. (Or, to be more precise, the new extension can define a second mnemonic alias for the same instruction?)

For that matter, what is the assembly syntax for the default instruction, i.e. does it have an explicit rs1 operand or is x[rs1] implied to be, say, x0?

This comment has been minimized.

Copy link
@aswaterman

aswaterman Sep 16, 2023

Author Member

I was thinking it was implicit that the new extension might define a new mnemonic, but I'm happy to state it explicitly. And yes, the x-register specifiers are part of the assembly syntax for mop.r.N and mop.rr.N, but not for c.mop.N, because in the latter case N contains all of the info.


include::images/wavedrom/mop-r.adoc[]
[[mop-r]]

The Zimop extension additionally defines 8 MOP instructions named
`mop.rr.__n__`, where __n__ is an integer between 0 and 7, inclusive.
Unless redefined by another extension, these instructions simply
write 0 to `x[rd]`. Their encoding allows future extensions to define them to
read `x[rs1]` and `x[rs2]`, as well as write `x[rd]`.

This comment has been minimized.

Copy link
@gfavor

gfavor Sep 16, 2023

Collaborator

Ditto the above comment wrt now two source register operands.


include::images/wavedrom/mop-rr.adoc[]
[[mop-rr]]

NOTE: These MOPs are encoded in the SYSTEM major opcode in part because it is
expected their behavior will be modulated by privileged CSR state.

NOTE: These MOPs are defined to write `x[rd]`, rather than performing no
operation, to simplify instruction decoding and to allow testing the presence
of features by branching on the zeroness of the result.

The MOPs defined in the Zimop extension are not guaranteed to carry
a syntactic dependency from `x[rs1]` or `x[rs2]` to `x[rd]`.

NOTE: Not carrying a syntactic dependence relieves straightforward
implementations of reading `x[rs1]` and `x[rs2]`.

<<<

=== "Zcmop" Compressed May-Be-Operations Extension, Version 0.1

This section defines the "Zcmop" extension, which defines eight 16-bit MOP
instructions named `c.mop.__n__`, where __n__ is an integer between 0 and 7,
inclusive. `c.mop.__n__` is encoded in the reserved encoding space
corresponding to `c.lui x__m__, 0`, where __m__=2__n__+1. These instructions
are defined to not write any register. Their encoding allows future extensions
to define them to read register `x[__m__]`.

This comment has been minimized.

Copy link
@gfavor

gfavor Sep 16, 2023

Collaborator

Similar comments as above about the assembly syntax and mnemonic renaming possibility.

This comment has been minimized.

Copy link
@aswaterman

aswaterman Sep 16, 2023

Author Member

I'll leave out repeating the mnemonic renaming possibility down here, since this section already makes no sense without having read the Zimop section.


include::images/wavedrom/c-mop.adoc[]
[[c-mop]]


NOTE: The expectation is that each Zcmop instruction is equivalent to some
Zimop instruction, but the choice of expansion (if any) is left to the
extension that redefines the MOP.

0 comments on commit 2463e2a

Please sign in to comment.