You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/inline-assembly.md
+33-33
Original file line number
Diff line number
Diff line change
@@ -356,7 +356,7 @@ assert_eq!(y, [3, 2, 0, 1]);
356
356
357
357
r[asm.operand-type.supported-operands.label]
358
358
*`label <block>`
359
-
- The address of the block is substituted into the asm template string. The assembly block may jump to the substituted address.
359
+
- The address of the block is substituted into the asm template string. The assembly code may jump to the substituted address.
360
360
- After execution of the block, the `asm!` expression returns.
361
361
- The type of the block must be unit or `!` (never).
362
362
- The block starts a new safety context; despite the outer `unsafe` block needed for `asm!`, unsafe operations within the `label` block must be wrapped in an inner `unsafe` block.
@@ -749,7 +749,7 @@ Some registers cannot be used for input or output operands:
749
749
750
750
| Architecture | Unsupported register | Reason |
751
751
| ------------ | -------------------- | ------ |
752
-
| All |`sp`, `r15` (s390x) | The stack pointer must be restored to its original value at the end of an asm code block. |
752
+
| All |`sp`, `r15` (s390x) | The stack pointer must be restored to its original value at the end of an assembly code. |
753
753
| All |`bp` (x86), `x29` (AArch64 and Arm64EC), `x8` (RISC-V), `$fp` (LoongArch), `r11` (s390x) | The frame pointer cannot be used as an input or output. |
754
754
| ARM |`r7` or `r11`| On ARM the frame pointer can be either `r7` or `r11` depending on the target. The frame pointer cannot be used as an input or output. |
755
755
| All |`si` (x86-32), `bx` (x86-64), `r6` (ARM), `x19` (AArch64 and Arm64EC), `x9` (RISC-V), `$s8` (LoongArch) | This is used internally by LLVM as a "base pointer" for functions with complex stack frames. |
@@ -873,7 +873,7 @@ r[asm.abi-clobbers]
873
873
## ABI clobbers
874
874
875
875
r[asm.abi-clobbers.intro]
876
-
The `clobber_abi` keyword can be used to apply a default set of clobbers to an `asm!` block.
876
+
The `clobber_abi` keyword can be used to apply a default set of clobbers to the assembly code.
877
877
This will automatically insert the necessary clobber constraints as needed for calling a function with a particular calling convention: if the calling convention does not fully preserve the value of a register across a call then `lateout("...") _` is implicitly added to the operands list (where the `...` is replaced by the register's name).
878
878
879
879
```rust
@@ -966,12 +966,12 @@ r[asm.options]
966
966
## Options
967
967
968
968
r[asm.options.supported-options]
969
-
Flags are used to further influence the behavior of the inline assembly block.
969
+
Flags are used to further influence the behavior of the inline assembly code.
970
970
Currently the following options are defined:
971
971
972
972
r[asm.options.supported-options.pure]
973
-
-`pure`: The `asm!` block has no side effects, must eventually return, 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).
974
-
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.
973
+
-`pure`: The assembly code has no side effects, must eventually return, 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).
974
+
This allows the compiler to execute the assembly code 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.
975
975
The `pure` option must be combined with either the `nomem` or `readonly` options, otherwise a compile-time error is emitted.
976
976
977
977
```rust
@@ -998,9 +998,9 @@ assert_eq!(z, 0);
998
998
```
999
999
1000
1000
r[asm.options.supported-options.nomem]
1001
-
-`nomem`: The `asm!` block does not read from or write to any memory accessible outside of the `asm!` block.
1002
-
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!`.
1003
-
The compiler also assumes that this `asm!` block does not perform any kind of synchronization with other threads, e.g. via fences.
1001
+
-`nomem`: The assembly code does not read from or write to any memory accessible outside of the assembly code.
1002
+
This allows the compiler to cache the values of modified global variables in registers across the assembly code since it knows that they are not read or written to by the `asm!`.
1003
+
The compiler also assumes that the assembly code does not perform any kind of synchronization with other threads, e.g. via fences.
1004
1004
1005
1005
<!-- no_run: This test has unpredictable or undefined behavior at runtime -->
1006
1006
```rust,no_run
@@ -1044,9 +1044,9 @@ assert_eq!(z, 1);
1044
1044
```
1045
1045
1046
1046
r[asm.options.supported-options.readonly]
1047
-
-`readonly`: The `asm!` block does not write to any memory accessible outside of the `asm!` block.
1048
-
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!`.
1049
-
The compiler also assumes that this `asm!` block does not perform any kind of synchronization with other threads, e.g. via fences.
1047
+
-`readonly`: The assembly code does not write to any memory accessible outside of the assembly code.
1048
+
This allows the compiler to cache the values of unmodified global variables in registers across the assembly code since it knows that they are not written to by the `asm!`.
1049
+
The compiler also assumes that this assembly code does not perform any kind of synchronization with other threads, e.g. via fences.
1050
1050
1051
1051
<!-- no_run: This test has undefined behaviour at runtime -->
1052
1052
```rust,no_run
@@ -1090,14 +1090,14 @@ assert_eq!(z, 1);
1090
1090
```
1091
1091
1092
1092
r[asm.options.supported-options.preserves_flags]
1093
-
-`preserves_flags`: The `asm!` block does not modify the flags register (defined in the rules below).
1094
-
This allows the compiler to avoid recomputing the condition flags after the `asm!` block.
1093
+
-`preserves_flags`: The assembly code does not modify the flags register (defined in the rules below).
1094
+
This allows the compiler to avoid recomputing the condition flags after the assembly code.
1095
1095
1096
1096
r[asm.options.supported-options.noreturn]
1097
-
-`noreturn`: The `asm!` block never returns, and its return type is defined as `!` (never).
1097
+
-`noreturn`: The assembly code never returns, and its return type is defined as `!` (never).
1098
1098
Behavior is undefined if execution falls through past the end of the asm code.
1099
1099
A `noreturn` asm block behaves just like a function which doesn't return; notably, local variables in scope are not dropped before it is invoked.
1100
-
- When any `label` blocks are present, `noreturn` means the execution of the `asm!` block never falls through; the asm block may only exit by jumping to one of the specified blocks.
1100
+
- When any `label` blocks are present, `noreturn` means the execution of the assembly code never falls through; the assembly code may only exit by jumping to one of the specified blocks.
1101
1101
The entire `asm!` block will have unit type in this case, unless all `label` blocks diverge, in which case the return type is `!`.
-`nostack`: The `asm!` block does not push data to the stack, or write to the stack red-zone (if supported by the target).
1123
+
-`nostack`: The assembly code does not push data to the stack, or write to the stack red-zone (if supported by the target).
1124
1124
If this option is *not* used then the stack pointer is guaranteed to be suitably aligned (according to the target ABI) for a function call.
1125
1125
1126
1126
<!-- no_run: Test has undefined behavior at runtime -->
@@ -1217,27 +1217,27 @@ r[asm.rules.intro]
1217
1217
To avoid undefined behavior, these rules must be followed when using function-scope inline assembly (`asm!`):
1218
1218
1219
1219
r[asm.rules.reg-not-input]
1220
-
- Any registers not specified as inputs will contain an undefined value on entry to the asm block.
1220
+
- Any registers not specified as inputs will contain an undefined value on entry to the assembly code.
1221
1221
- An "undefined value" in the context of inline assembly means that the register can (non-deterministically) have any one of the possible values allowed by the architecture.
1222
1222
Notably it is not the same as an LLVM `undef` which can have a different value every time you read it (since such a concept does not exist in assembly code).
1223
1223
1224
1224
r[asm.rules.reg-not-output]
1225
-
- Any registers not specified as outputs must have the same value upon exiting the asm block as they had on entry, otherwise behavior is undefined.
1225
+
- Any registers not specified as outputs must have the same value upon exiting the assembly code as they had on entry, otherwise behavior is undefined.
1226
1226
- This only applies to registers which can be specified as an input or output.
1227
1227
Other registers follow target-specific rules.
1228
1228
- Note that a `lateout` may be allocated to the same register as an `in`, in which case this rule does not apply.
1229
1229
Code should not rely on this however since it depends on the results of register allocation.
1230
1230
1231
1231
r[asm.rules.unwind]
1232
-
- Behavior is undefined if execution unwinds out of an asm block.
1232
+
- Behavior is undefined if execution unwinds out of the assembly code.
1233
1233
- This also applies if the assembly code calls a function which then unwinds.
1234
1234
1235
1235
r[asm.rules.mem-same-as-ffi]
1236
1236
- The set of memory locations that assembly code is allowed to read and write are the same as those allowed for an FFI function.
1237
1237
- Refer to the unsafe code guidelines for the exact rules.
1238
1238
- If the `readonly` option is set, then only memory reads are allowed.
1239
1239
- If the `nomem` option is set then no reads or writes to memory are allowed.
1240
-
- These rules do not apply to memory which is private to the asm code, such as stack space allocated within the asm block.
1240
+
- These rules do not apply to memory which is private to the asm code, such as stack space allocated within the assembly code.
1241
1241
1242
1242
r[asm.rules.black-box]
1243
1243
- The compiler cannot assume that the instructions in the asm are the ones that will actually end up executed.
@@ -1247,22 +1247,22 @@ r[asm.rules.black-box]
1247
1247
1248
1248
r[asm.rules.stack-below-sp]
1249
1249
- Unless the `nostack` option is set, asm code is allowed to use stack space below the stack pointer.
1250
-
- On entry to the asm block the stack pointer is guaranteed to be suitably aligned (according to the target ABI) for a function call.
1250
+
- On entry to the assembly code the stack pointer is guaranteed to be suitably aligned (according to the target ABI) for a function call.
1251
1251
- You are responsible for making sure you don't overflow the stack (e.g. use stack probing to ensure you hit a guard page).
1252
1252
- You should adjust the stack pointer when allocating stack memory as required by the target ABI.
1253
-
- The stack pointer must be restored to its original value before leaving the asm block.
1253
+
- The stack pointer must be restored to its original value before leaving the assembly code.
1254
1254
1255
1255
r[asm.rules.noreturn]
1256
-
- If the `noreturn` option is set then behavior is undefined if execution falls through to the end of the asm block.
1256
+
- If the `noreturn` option is set then behavior is undefined if execution falls through to the end of the assembly code.
1257
1257
1258
1258
r[asm.rules.pure]
1259
1259
- If the `pure` option is set then behavior is undefined if the `asm!` has side-effects other than its direct outputs.
1260
1260
Behavior is also undefined if two executions of the `asm!` code with the same inputs result in different outputs.
1261
1261
- When used with the `nomem` option, "inputs" are just the direct inputs of the `asm!`.
1262
-
- When used with the `readonly` option, "inputs" comprise the direct inputs of the `asm!` and any memory that the `asm!` block is allowed to read.
1262
+
- When used with the `readonly` option, "inputs" comprise the direct inputs of the `asm!` and any memory that the assembly code is allowed to read.
1263
1263
1264
1264
r[asm.rules.preserved-registers]
1265
-
- These flags registers must be restored upon exiting the asm block if the `preserves_flags` option is set:
1265
+
- These flags registers must be restored upon exiting the assembly code if the `preserves_flags` option is set:
1266
1266
- x86
1267
1267
- Status flags in `EFLAGS` (CF, PF, AF, ZF, SF, OF).
- On x86, the direction flag (DF in `EFLAGS`) is clear on entry to an asm block and must be clear on exit.
1290
-
- Behavior is undefined if the direction flag is set on exiting an asm block.
1289
+
- On x86, the direction flag (DF in `EFLAGS`) is clear on entry to the assembly code and must be clear on exit.
1290
+
- Behavior is undefined if the direction flag is set on exiting the assembly code.
1291
1291
1292
1292
r[asm.rules.x86-x87]
1293
1293
- On x86, the x87 floating-point register stack must remain unchanged unless all of the `st([0-7])` registers have been marked as clobbered with `out("st(0)") _, out("st(1)") _, ...`.
1294
-
- If all x87 registers are clobbered then the x87 register stack is guaranteed to be empty upon entering an `asm` block. Assembly code must ensure that the x87 register stack is also empty when exiting the asm block.
1294
+
- If all x87 registers are clobbered then the x87 register stack is guaranteed to be empty upon entering the assembly code. Assembly code must ensure that the x87 register stack is also empty when exiting the asssembly code.
1295
1295
1296
1296
```rust
1297
1297
# #[cfg(target_arch ="x86_64")]
@@ -1330,8 +1330,8 @@ r[asm.rules.arm64ec]
1330
1330
- On arm64ec, [call checkers with appropriate thunks](https://learn.microsoft.com/en-us/windows/arm/arm64ec-abi#authoring-arm64ec-in-assembly) are mandatory when calling functions.
1331
1331
1332
1332
r[asm.rules.only-on-exit]
1333
-
- The requirement of restoring the stack pointer and non-output registers to their original value only applies when exiting an `asm!` block.
1334
-
- This means that `asm!` blocks that never return (even if not marked `noreturn`) don't need to preserve these registers.
1333
+
- The requirement of restoring the stack pointer and non-output registers to their original value only applies when exiting the assembly code.
1334
+
- This means that assembly code that never return (even if not marked `noreturn`) don't need to preserve these registers.
1335
1335
- When returning to a different `asm!` block than you entered (e.g. for context switching), these registers must contain the value they had upon entering the `asm!` block that you are *exiting*.
1336
1336
- You cannot exit an `asm!` block that has not been entered.
1337
1337
Neither can you exit an `asm!` block that has already been exited (without first entering it again).
@@ -1387,7 +1387,7 @@ Inline assembly supports a subset of the directives supported by both GNU AS and
1387
1387
The result of using other directives is assembler-specific (and may cause an error, or may be accepted as-is).
1388
1388
1389
1389
r[asm.directives.stateful]
1390
-
If inline assembly includes any "stateful" directive that modifies how subsequent assembly is processed, the block must undo the effects of any such directives before the inline assembly ends.
1390
+
If inline assembly includes any "stateful" directive that modifies how subsequent assembly is processed, the assembly code must undo the effects of any such directives before the inline assembly ends.
1391
1391
1392
1392
r[asm.directives.supported-directives]
1393
1393
The following directives are guaranteed to be supported by the assembler:
@@ -1514,7 +1514,7 @@ On x86 targets, both 32-bit and 64-bit, the following additional directives are
1514
1514
-`.code32`
1515
1515
-`.code64`
1516
1516
1517
-
Use of `.code16`, `.code32`, and `.code64` directives are only supported if the state is reset to the default before exiting the assembly block.
1517
+
Use of `.code16`, `.code32`, and `.code64` directives are only supported if the state is reset to the default before exiting the assembly code.
1518
1518
32-bit x86 uses `.code32` by default, and x86_64 uses `.code64` by default.
0 commit comments