Skip to content

Commit 5787c88

Browse files
authored
Merge pull request #1357 from loongarch-rs/loongarch
Add LoongArch to inline-assembly documentation
2 parents e5ecb2d + b36de24 commit 5787c88

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/inline-assembly.md

+27-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Support for inline assembly is stable on the following architectures:
1111
- ARM
1212
- AArch64
1313
- RISC-V
14+
- LoongArch
1415

1516
The compiler will emit an error if `asm!` is used on an unsupported target.
1617

@@ -185,6 +186,8 @@ Here is the list of currently supported register classes:
185186
| RISC-V | `reg` | `x1`, `x[5-7]`, `x[9-15]`, `x[16-31]` (non-RV32E) | `r` |
186187
| RISC-V | `freg` | `f[0-31]` | `f` |
187188
| RISC-V | `vreg` | `v[0-31]` | Only clobbers |
189+
| LoongArch | `reg` | `$r1`, `$r[4-20]`, `$r[23,30]` | `r` |
190+
| LoongArch | `freg` | `$f[0-31]` | `f` |
188191

189192
> **Notes**:
190193
> - On x86 we treat `reg_byte` differently from `reg` because the compiler can allocate `al` and `ah` separately whereas `reg` reserves the whole register.
@@ -223,6 +226,8 @@ The availability of supported types for a particular register class may depend o
223226
| RISC-V | `freg` | `f` | `f32` |
224227
| RISC-V | `freg` | `d` | `f64` |
225228
| RISC-V | `vreg` | N/A | Only clobbers |
229+
| LoongArch64 | `reg` | None | `i8`, `i16`, `i32`, `i64`, `f32`, `f64` |
230+
| LoongArch64 | `freg` | None | `f32`, `f64` |
226231

227232
> **Note**: For the purposes of the above table pointers, function pointers and `isize`/`usize` are treated as the equivalent integer type (`i16`/`i32`/`i64` depending on the target).
228233
@@ -284,22 +289,37 @@ Here is the list of all supported register aliases:
284289
| RISC-V | `f[10-17]` | `fa[0-7]` |
285290
| RISC-V | `f[18-27]` | `fs[2-11]` |
286291
| RISC-V | `f[28-31]` | `ft[8-11]` |
292+
| LoongArch | `$r0` | `$zero` |
293+
| LoongArch | `$r1` | `$ra` |
294+
| LoongArch | `$r2` | `$tp` |
295+
| LoongArch | `$r3` | `$sp` |
296+
| LoongArch | `$r[4-11]` | `$a[0-7]` |
297+
| LoongArch | `$r[12-20]` | `$t[0-8]` |
298+
| LoongArch | `$r21` | |
299+
| LoongArch | `$r22` | `$fp`, `$s9` |
300+
| LoongArch | `$r[23-31]` | `$s[0-8]` |
301+
| LoongArch | `$f[0-7]` | `$fa[0-7]` |
302+
| LoongArch | `$f[8-23]` | `$ft[0-15]` |
303+
| LoongArch | `$f[24-31]` | `$fs[0-7]` |
287304

288305
Some registers cannot be used for input or output operands:
289306

290307
| Architecture | Unsupported register | Reason |
291308
| ------------ | -------------------- | ------ |
292309
| All | `sp` | The stack pointer must be restored to its original value at the end of an asm code block. |
293-
| All | `bp` (x86), `x29` (AArch64), `x8` (RISC-V) | The frame pointer cannot be used as an input or output. |
310+
| All | `bp` (x86), `x29` (AArch64), `x8` (RISC-V), `$fp` (LoongArch) | The frame pointer cannot be used as an input or output. |
294311
| 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. |
295-
| All | `si` (x86-32), `bx` (x86-64), `r6` (ARM), `x19` (AArch64), `x9` (RISC-V) | This is used internally by LLVM as a "base pointer" for functions with complex stack frames. |
312+
| All | `si` (x86-32), `bx` (x86-64), `r6` (ARM), `x19` (AArch64), `x9` (RISC-V), `$s8` (LoongArch) | This is used internally by LLVM as a "base pointer" for functions with complex stack frames. |
296313
| x86 | `ip` | This is the program counter, not a real register. |
297314
| AArch64 | `xzr` | This is a constant zero register which can't be modified. |
298315
| AArch64 | `x18` | This is an OS-reserved register on some AArch64 targets. |
299316
| ARM | `pc` | This is the program counter, not a real register. |
300317
| ARM | `r9` | This is an OS-reserved register on some ARM targets. |
301318
| RISC-V | `x0` | This is a constant zero register which can't be modified. |
302319
| RISC-V | `gp`, `tp` | These registers are reserved and cannot be used as inputs or outputs. |
320+
| LoongArch | `$r0` or `$zero` | This is a constant zero register which can't be modified. |
321+
| LoongArch | `$r2` or `$tp` | This is reserved for TLS. |
322+
| LoongArch | `$r21` | This is reserved by the ABI. |
303323

304324
The frame pointer and base pointer registers are reserved for internal use by LLVM. While `asm!` statements cannot explicitly specify the use of reserved registers, in some cases LLVM will allocate one of these reserved registers for `reg` operands. Assembly code making use of reserved registers should be careful since `reg` operands may use the same registers.
305325

@@ -346,6 +366,8 @@ The supported modifiers are a subset of LLVM's (and GCC's) [asm template argumen
346366
| ARM | `qreg` | `e` / `f` | `d0` / `d1` | `e` / `f` |
347367
| RISC-V | `reg` | None | `x1` | None |
348368
| RISC-V | `freg` | None | `f0` | None |
369+
| LoongArch | `reg` | None | `$r1` | None |
370+
| LoongArch | `freg` | None | `$f0` | None |
349371

350372
> **Notes**:
351373
> - on ARM `e` / `f`: this prints the low or high doubleword register name of a NEON quad (128-bit) register.
@@ -379,6 +401,7 @@ The following ABIs can be used with `clobber_abi`:
379401
| AArch64 | `"C"`, `"system"`, `"efiapi"` | `x[0-17]`, `x18`\*, `x30`, `v[0-31]`, `p[0-15]`, `ffr` |
380402
| ARM | `"C"`, `"system"`, `"efiapi"`, `"aapcs"` | `r[0-3]`, `r12`, `r14`, `s[0-15]`, `d[0-7]`, `d[16-31]` |
381403
| RISC-V | `"C"`, `"system"`, `"efiapi"` | `x1`, `x[5-7]`, `x[10-17]`, `x[28-31]`, `f[0-7]`, `f[10-17]`, `f[28-31]`, `v[0-31]` |
404+
| LoongArch | `"C"`, `"system"`, `"efiapi"` | `$r1`, `$r[4-20]`, `$f[0-23]` |
382405

383406
> Notes:
384407
> - On AArch64 `x18` only included in the clobber list if it is not considered as a reserved register on the target.
@@ -466,6 +489,8 @@ To avoid undefined behavior, these rules must be followed when using function-sc
466489
- RISC-V
467490
- Floating-point exception flags in `fcsr` (`fflags`).
468491
- Vector extension state (`vtype`, `vl`, `vcsr`).
492+
- LoongArch
493+
- Floating-point condition flags in `$fcc[0-7]`.
469494
- On x86, the direction flag (DF in `EFLAGS`) is clear on entry to an asm block and must be clear on exit.
470495
- Behavior is undefined if the direction flag is set on exiting an asm block.
471496
- 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)") _, ...`.

0 commit comments

Comments
 (0)