Skip to content

Commit b8a39d3

Browse files
authored
Merge pull request #1413 from RalfJung/nofence
some asm block flags also mean there can be no fences
2 parents 8947db0 + c7690f1 commit b8a39d3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/inline-assembly.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,13 @@ Flags are used to further influence the behavior of the inline assembly block.
414414
Currently the following options are defined:
415415
- `pure`: The `asm!` block has no side effects, and its outputs depend only on its direct inputs (i.e. the values themselves, not what they point to) or values read from memory (unless the `nomem` options is also set).
416416
This allows the compiler to execute the `asm!` block fewer times than specified in the program (e.g. by hoisting it out of a loop) or even eliminate it entirely if the outputs are not used.
417+
The `pure` option must be combined with either the `nomem` or `readonly` options, otherwise a compile-time error is emitted.
417418
- `nomem`: The `asm!` blocks does not read or write to any memory.
418419
This allows the compiler to cache the values of modified global variables in registers across the `asm!` block since it knows that they are not read or written to by the `asm!`.
420+
The compiler also assumes that this `asm!` block does not perform any kind of synchronization with other threads, e.g. via fences.
419421
- `readonly`: The `asm!` block does not write to any memory.
420422
This allows the compiler to cache the values of unmodified global variables in registers across the `asm!` block since it knows that they are not written to by the `asm!`.
423+
The compiler also assumes that this `asm!` block does not perform any kind of synchronization with other threads, e.g. via fences.
421424
- `preserves_flags`: The `asm!` block does not modify the flags register (defined in the rules below).
422425
This allows the compiler to avoid recomputing the condition flags after the `asm!` block.
423426
- `noreturn`: The `asm!` block never returns, and its return type is defined as `!` (never).
@@ -432,7 +435,6 @@ Currently the following options are defined:
432435

433436
The compiler performs some additional checks on options:
434437
- The `nomem` and `readonly` options are mutually exclusive: it is a compile-time error to specify both.
435-
- The `pure` option must be combined with either the `nomem` or `readonly` options, otherwise a compile-time error is emitted.
436438
- It is a compile-time error to specify `pure` on an asm block with no outputs or only discarded outputs (`_`).
437439
- It is a compile-time error to specify `noreturn` on an asm block with outputs.
438440

0 commit comments

Comments
 (0)