Skip to content

Commit

Permalink
Fetch Instruction/Category clarification (#1824)
Browse files Browse the repository at this point in the history
* Enhance FENCE table

* Caps FENCE

* Tweak description of FENCE

The description of the "FENCE" instructions under "Memory Ordering
Instructions" (section 2.7) has some inconsistencies which are magnified
by the coexistence of "FENCE" as a set of instructions depending on the
value of the _fm_ field, and a specific instruction that uses the `FENCE`
mnemonic when _fm_=0b0000.

Try to improve the documentation in this section with the following changes:
- I avoid "the FENCE instruction" in favor of "FENCE instructions" or
  "a FENCE instruction" (just all caps here, too).
- I capitalized "fence" when it was clearly referring to
  "FENCE instructions".
- I used `FENCE` when the referring to the `FENCE` instruction
  (with _fm_=0000).
- I put "with _fm_=0000" in paretheses when it was already associated with
  the `FENCE` instruction (with _fm_=0000) to convey that this was just to
  add some clarity (not specialization) for something that should already
  be fairly clear.
  (Although using text attributes for clarity is not terribly accessible,
  perhaps?)
- I changed uses of `FENCE` to FENCE when it was referring to the class.
- I put all references to `FENCE.TSO` in backticks, since this is referring
  to a specific instruction (not the class).
- I put all references like `FENCE RW,RW` in backticks, since this is
  referring to a specific instruction.
- In this text:
  > many _fm_ and predecessor/successor set settings in <<fm>> are also reserved for future use.
  I removed "in <<fm>>" because I couldn't make sense of that sentence
  otherwise.
- I replaced "normal fences" with "`FENCE` instructions (with _fm_=0000)",
  since it's really a reference to a specific instruction.

---------

Co-authored-by: Paul A. Clarke <[email protected]>
  • Loading branch information
AFOliveira and ThinkOpenly authored Jan 26, 2025
1 parent 91b80d3 commit f156ba4
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/rv32.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ include::images/wavedrom/mem-order.edn[]
[[mem-order]]
//.Memory ordering instructions

The FENCE instruction is used to order device I/O and memory accesses as
FENCE instructions are used to order device I/O and memory accesses as
viewed by other RISC-V harts and external devices or coprocessors. Any
combination of device input (I), device output (O), memory reads \(R),
and memory writes (W) may be ordered with respect to any combination of
Expand All @@ -802,9 +802,9 @@ any operation in the _predecessor_ set preceding the FENCE.
<<memorymodel>> provides a precise description
of the RISC-V memory consistency model.

The FENCE instruction also orders memory reads and writes made by the
FENCE instructions also order memory reads and writes made by the
hart as observed by memory reads and writes made by an external device.
However, FENCE does not order observations of events made by an external
However, FENCE instructions do not order observations of events made by an external
device using any other signaling mechanism.

[NOTE]
Expand All @@ -813,7 +813,7 @@ A device might observe an access to a memory location via some external
communication mechanism, e.g., a memory-mapped control register that
drives an interrupt signal to an interrupt controller. This
communication is outside the scope of the FENCE ordering mechanism and
hence the FENCE instruction can provide no guarantee on when a change in
hence FENCE instructions can provide no guarantee on when a change in
the interrupt signal is visible to the interrupt controller. Specific
devices might provide additional ordering guarantees to reduce software
overhead but those are outside the scope of the RISC-V memory model.
Expand All @@ -827,23 +827,23 @@ memory-mapped I/O devices will typically be accessed with uncached loads
and stores that are ordered using the I and O bits rather than the R and
W bits. Instruction-set extensions might also describe new I/O
instructions that will also be ordered using the I and O bits in a
FENCE.
FENCE instruction.

[[fm]]
[float="center",align="center",cols="^1,^1,<3",options="header"]
.Fence mode encoding
|===
|_fm_ field |Mnemonic |Meaning
|_fm_ field |Mnemonic suffix|Meaning
|0000 |_none_ |Normal Fence
|1000 |TSO |With `FENCE RW,RW`: exclude write-to-read ordering; otherwise: _Reserved for future use._
2+|_other_ |_Reserved for future use._
|1000 |.TSO |With `FENCE RW,RW`: exclude write-to-read ordering; otherwise: _Reserved for future use._
|_other_|_other_ |_Reserved for future use._
|===

The fence mode field _fm_ defines the semantics of the `FENCE`. A `FENCE`
with _fm_=`0000` orders all memory operations in its predecessor set
The FENCE mode field _fm_ defines the semantics of the FENCE instruction. A `FENCE`
(with _fm_=`0000`) orders all memory operations in its predecessor set
before all memory operations in its successor set.

The `FENCE.TSO` instruction is encoded as a `FENCE` instruction
A `FENCE.TSO` instruction is encoded as a FENCE instruction
with _fm_=`1000`, _predecessor_=`RW`, and _successor_=`RW`. `FENCE.TSO` orders
all load operations in its predecessor set before all memory operations
in its successor set, and all store operations in its predecessor set
Expand All @@ -853,17 +853,17 @@ store operations in the `FENCE.TSO's` predecessor set unordered with

[NOTE]
====
Because FENCE RW,RW imposes a superset of the orderings that FENCE.TSO
imposes, it is correct to ignore the _fm_ field and implement FENCE.TSO as FENCE RW,RW.
Because `FENCE RW,RW` imposes a superset of the orderings that `FENCE.TSO`
imposes, it is correct to ignore the _fm_ field and implement `FENCE.TSO` as `FENCE RW,RW`.
====

The unused fields in the `FENCE` instructions--_rs1_ and _rd_--are reserved
The unused fields in the FENCE instructions--_rs1_ and _rd_--are reserved
for finer-grain fences in future extensions. For forward compatibility,
base implementations shall ignore these fields, and standard software
shall zero these fields. Likewise, many _fm_ and predecessor/successor
set settings in <<fm>> are also reserved for future use.
set settings are also reserved for future use.
Base implementations shall treat all such reserved configurations as
normal fences with _fm_=0000, and standard software shall use only
`FENCE` instructions (with _fm_=`0000`), and standard software shall use only
non-reserved configurations.

[NOTE]
Expand All @@ -875,7 +875,7 @@ ordering to avoid unnecessary serialization within a device-driver hart
and also to support alternative non-memory paths to control added
coprocessors or I/O devices. Simple implementations may additionally
ignore the _predecessor_ and _successor_ fields and always execute a
conservative fence on all operations.
conservative FENCE on all operations.
====

[[ecall-ebreak]]
Expand Down

0 comments on commit f156ba4

Please sign in to comment.