Skip to content

Commit 7bc5839

Browse files
committed
Auto merge of rust-lang#77337 - lzutao:asm-mips64, r=Amanieu
Add asm! support for mips64 - [x] Updated `src/doc/unstable-book/src/library-features/asm.md`. - [ ] No vector type support. I don't know much about those types. cc rust-lang#76839
2 parents 87b71ed + 4d570fb commit 7bc5839

File tree

5 files changed

+161
-108
lines changed

5 files changed

+161
-108
lines changed

compiler/rustc_codegen_llvm/src/asm.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
259259
InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => {}
260260
InlineAsmArch::Nvptx64 => {}
261261
InlineAsmArch::Hexagon => {}
262-
InlineAsmArch::Mips => {}
262+
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {}
263263
}
264264
}
265265
if !options.contains(InlineAsmOptions::NOMEM) {
@@ -710,6 +710,7 @@ fn llvm_fixup_input(
710710
// MIPS only supports register-length arithmetics.
711711
Primitive::Int(Integer::I8 | Integer::I16, _) => bx.zext(value, bx.cx.type_i32()),
712712
Primitive::F32 => bx.bitcast(value, bx.cx.type_i32()),
713+
Primitive::F64 => bx.bitcast(value, bx.cx.type_i64()),
713714
_ => value,
714715
},
715716
_ => value,
@@ -785,6 +786,7 @@ fn llvm_fixup_output(
785786
Primitive::Int(Integer::I8, _) => bx.trunc(value, bx.cx.type_i8()),
786787
Primitive::Int(Integer::I16, _) => bx.trunc(value, bx.cx.type_i16()),
787788
Primitive::F32 => bx.bitcast(value, bx.cx.type_f32()),
789+
Primitive::F64 => bx.bitcast(value, bx.cx.type_f64()),
788790
_ => value,
789791
},
790792
_ => value,
@@ -854,6 +856,7 @@ fn llvm_fixup_output_type(
854856
// MIPS only supports register-length arithmetics.
855857
Primitive::Int(Integer::I8 | Integer::I16, _) => cx.type_i32(),
856858
Primitive::F32 => cx.type_i32(),
859+
Primitive::F64 => cx.type_i64(),
857860
_ => layout.llvm_type(cx),
858861
},
859862
_ => layout.llvm_type(cx),

compiler/rustc_target/src/asm/mips.rs

+37-36
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,44 @@ impl MipsInlineAsmRegClass {
3232

3333
pub fn supported_types(
3434
self,
35-
_arch: InlineAsmArch,
35+
arch: InlineAsmArch,
3636
) -> &'static [(InlineAsmType, Option<&'static str>)] {
37-
match self {
38-
Self::reg => types! { _: I8, I16, I32, F32; },
39-
Self::freg => types! { _: F32; },
37+
match (self, arch) {
38+
(Self::reg, InlineAsmArch::Mips64) => types! { _: I8, I16, I32, I64, F32, F64; },
39+
(Self::reg, _) => types! { _: I8, I16, I32, F32; },
40+
(Self::freg, _) => types! { _: F32, F64; },
4041
}
4142
}
4243
}
4344

4445
// The reserved registers are somewhat taken from <https://git.io/JUR1k#L150>.
4546
def_regs! {
4647
Mips MipsInlineAsmReg MipsInlineAsmRegClass {
47-
v0: reg = ["$2", "$v0"],
48-
v1: reg = ["$3", "$v1"],
49-
a0: reg = ["$4", "$a0"],
50-
a1: reg = ["$5", "$a1"],
51-
a2: reg = ["$6", "$a2"],
52-
a3: reg = ["$7", "$a3"],
48+
r2: reg = ["$2"],
49+
r3: reg = ["$3"],
50+
r4: reg = ["$4"],
51+
r5: reg = ["$5"],
52+
r6: reg = ["$6"],
53+
r7: reg = ["$7"],
5354
// FIXME: Reserve $t0, $t1 if in mips16 mode.
54-
t0: reg = ["$8", "$t0"],
55-
t1: reg = ["$9", "$t1"],
56-
t2: reg = ["$10", "$t2"],
57-
t3: reg = ["$11", "$t3"],
58-
t4: reg = ["$12", "$t4"],
59-
t5: reg = ["$13", "$t5"],
60-
t6: reg = ["$14", "$t6"],
61-
t7: reg = ["$15", "$t7"],
62-
s0: reg = ["$16", "$s0"],
63-
s1: reg = ["$17", "$s1"],
64-
s2: reg = ["$18", "$s2"],
65-
s3: reg = ["$19", "$s3"],
66-
s4: reg = ["$20", "$s4"],
67-
s5: reg = ["$21", "$s5"],
68-
s6: reg = ["$22", "$s6"],
69-
s7: reg = ["$23", "$s7"],
70-
t8: reg = ["$24", "$t8"],
71-
t9: reg = ["$25", "$t9"],
55+
r8: reg = ["$8"],
56+
r9: reg = ["$9"],
57+
r10: reg = ["$10"],
58+
r11: reg = ["$11"],
59+
r12: reg = ["$12"],
60+
r13: reg = ["$13"],
61+
r14: reg = ["$14"],
62+
r15: reg = ["$15"],
63+
r16: reg = ["$16"],
64+
r17: reg = ["$17"],
65+
r18: reg = ["$18"],
66+
r19: reg = ["$19"],
67+
r20: reg = ["$20"],
68+
r21: reg = ["$21"],
69+
r22: reg = ["$22"],
70+
r23: reg = ["$23"],
71+
r24: reg = ["$24"],
72+
r25: reg = ["$25"],
7273
f0: freg = ["$f0"],
7374
f1: freg = ["$f1"],
7475
f2: freg = ["$f2"],
@@ -101,21 +102,21 @@ def_regs! {
101102
f29: freg = ["$f29"],
102103
f30: freg = ["$f30"],
103104
f31: freg = ["$f31"],
104-
#error = ["$0", "$zero"] =>
105+
#error = ["$0"] =>
105106
"constant zero cannot be used as an operand for inline asm",
106-
#error = ["$1", "$at"] =>
107+
#error = ["$1"] =>
107108
"reserved for assembler (Assembler Temp)",
108-
#error = ["$26", "$k0"] =>
109+
#error = ["$26"] =>
109110
"OS-reserved register cannot be used as an operand for inline asm",
110-
#error = ["$27", "$k1"] =>
111+
#error = ["$27"] =>
111112
"OS-reserved register cannot be used as an operand for inline asm",
112-
#error = ["$28", "$gp"] =>
113+
#error = ["$28"] =>
113114
"the global pointer cannot be used as an operand for inline asm",
114-
#error = ["$29", "$sp"] =>
115+
#error = ["$29"] =>
115116
"the stack pointer cannot be used as an operand for inline asm",
116-
#error = ["$30", "$s8", "$fp"] =>
117+
#error = ["$30"] =>
117118
"the frame pointer cannot be used as an operand for inline asm",
118-
#error = ["$31", "$ra"] =>
119+
#error = ["$31"] =>
119120
"the return address register cannot be used as an operand for inline asm",
120121
}
121122
}

compiler/rustc_target/src/asm/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pub enum InlineAsmArch {
176176
Nvptx64,
177177
Hexagon,
178178
Mips,
179+
Mips64,
179180
}
180181

181182
impl FromStr for InlineAsmArch {
@@ -192,6 +193,7 @@ impl FromStr for InlineAsmArch {
192193
"nvptx64" => Ok(Self::Nvptx64),
193194
"hexagon" => Ok(Self::Hexagon),
194195
"mips" => Ok(Self::Mips),
196+
"mips64" => Ok(Self::Mips64),
195197
_ => Err(()),
196198
}
197199
}
@@ -259,7 +261,7 @@ impl InlineAsmReg {
259261
InlineAsmArch::Hexagon => {
260262
Self::Hexagon(HexagonInlineAsmReg::parse(arch, has_feature, target, &name)?)
261263
}
262-
InlineAsmArch::Mips => {
264+
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
263265
Self::Mips(MipsInlineAsmReg::parse(arch, has_feature, target, &name)?)
264266
}
265267
})
@@ -409,7 +411,9 @@ impl InlineAsmRegClass {
409411
InlineAsmArch::Hexagon => {
410412
Self::Hexagon(HexagonInlineAsmRegClass::parse(arch, name)?)
411413
}
412-
InlineAsmArch::Mips => Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?),
414+
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
415+
Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?)
416+
}
413417
})
414418
})
415419
}
@@ -565,7 +569,7 @@ pub fn allocatable_registers(
565569
hexagon::fill_reg_map(arch, has_feature, target, &mut map);
566570
map
567571
}
568-
InlineAsmArch::Mips => {
572+
InlineAsmArch::Mips | InlineAsmArch::Mips64 => {
569573
let mut map = mips::regclass_map();
570574
mips::fill_reg_map(arch, has_feature, target, &mut map);
571575
map

src/doc/unstable-book/src/library-features/asm.md

+13-14
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Inline assembly is currently supported on the following architectures:
2727
- RISC-V
2828
- NVPTX
2929
- Hexagon
30-
- MIPS32
30+
- MIPS32r2 and MIPS64r2
3131

3232
## Basic usage
3333

@@ -513,8 +513,8 @@ Here is the list of currently supported register classes:
513513
| ARM | `qreg` | `q[0-15]` | `w` |
514514
| ARM | `qreg_low8` | `q[0-7]` | `t` |
515515
| ARM | `qreg_low4` | `q[0-3]` | `x` |
516-
| MIPS32 | `reg` | `$[2-25]` | `r` |
517-
| MIPS32 | `freg` | `$f[0-31]` | `f` |
516+
| MIPS | `reg` | `$[2-25]` | `r` |
517+
| MIPS | `freg` | `$f[0-31]` | `f` |
518518
| NVPTX | `reg16` | None\* | `h` |
519519
| NVPTX | `reg32` | None\* | `r` |
520520
| NVPTX | `reg64` | None\* | `l` |
@@ -551,7 +551,9 @@ Each register class has constraints on which value types they can be used with.
551551
| ARM | `dreg` | `vfp2` | `i64`, `f64`, `i8x8`, `i16x4`, `i32x2`, `i64x1`, `f32x2` |
552552
| ARM | `qreg` | `neon` | `i8x16`, `i16x8`, `i32x4`, `i64x2`, `f32x4` |
553553
| MIPS32 | `reg` | None | `i8`, `i16`, `i32`, `f32` |
554-
| MIPS32 | `freg` | None | `f32` |
554+
| MIPS32 | `freg` | None | `f32`, `f64` |
555+
| MIPS64 | `reg` | None | `i8`, `i16`, `i32`, `i64`, `f32`, `f64` |
556+
| MIPS64 | `freg` | None | `f32`, `f64` |
555557
| NVPTX | `reg16` | None | `i8`, `i16` |
556558
| NVPTX | `reg32` | None | `i8`, `i16`, `i32`, `f32` |
557559
| NVPTX | `reg64` | None | `i8`, `i16`, `i32`, `f32`, `i64`, `f64` |
@@ -600,7 +602,6 @@ Some registers have multiple names. These are all treated by the compiler as ide
600602
| ARM | `r13` | `sp` |
601603
| ARM | `r14` | `lr` |
602604
| ARM | `r15` | `pc` |
603-
| MIPS32 | `$[2-25]` | Please [see the Wikipedia page][mips-regs] |
604605
| RISC-V | `x0` | `zero` |
605606
| RISC-V | `x1` | `ra` |
606607
| RISC-V | `x2` | `sp` |
@@ -621,8 +622,6 @@ Some registers have multiple names. These are all treated by the compiler as ide
621622
| Hexagon | `r30` | `fr` |
622623
| Hexagon | `r31` | `lr` |
623624

624-
[mips-regs]: https://en.wikibooks.org/wiki/MIPS_Assembly/Register_File#Registers
625-
626625
Some registers cannot be used for input or output operands:
627626

628627
| Architecture | Unsupported register | Reason |
@@ -637,11 +636,11 @@ Some registers cannot be used for input or output operands:
637636
| x86 | `st([0-7])` | x87 registers are not currently supported (but may be in the future). |
638637
| AArch64 | `xzr` | This is a constant zero register which can't be modified. |
639638
| ARM | `pc` | This is the program counter, not a real register. |
640-
| MIPS32 | `$0` or `$zero` | This is a constant zero register which can't be modified. |
641-
| MIPS32 | `$1` or `$at` | Reserved for assembler. |
642-
| MIPS32 | `$26`/`$k0`, `$27`/`$k1` | OS-reserved registers. |
643-
| MIPS32 | `$28`/`$gp` | Global pointer cannot be used as inputs or outputs. |
644-
| MIPS32 | `$ra` | Return address cannot be used as inputs or outputs. |
639+
| MIPS | `$0` or `$zero` | This is a constant zero register which can't be modified. |
640+
| MIPS | `$1` or `$at` | Reserved for assembler. |
641+
| MIPS | `$26`/`$k0`, `$27`/`$k1` | OS-reserved registers. |
642+
| MIPS | `$28`/`$gp` | Global pointer cannot be used as inputs or outputs. |
643+
| MIPS | `$ra` | Return address cannot be used as inputs or outputs. |
645644
| RISC-V | `x0` | This is a constant zero register which can't be modified. |
646645
| RISC-V | `gp`, `tp` | These registers are reserved and cannot be used as inputs or outputs. |
647646
| Hexagon | `lr` | This is the link register which cannot be used as an input or output. |
@@ -689,8 +688,8 @@ The supported modifiers are a subset of LLVM's (and GCC's) [asm template argumen
689688
| ARM | `dreg` | None | `d0` | `P` |
690689
| ARM | `qreg` | None | `q0` | `q` |
691690
| ARM | `qreg` | `e` / `f` | `d0` / `d1` | `e` / `f` |
692-
| MIPS32 | `reg` | None | `$2` | None |
693-
| MIPS32 | `freg` | None | `$f0` | None |
691+
| MIPS | `reg` | None | `$2` | None |
692+
| MIPS | `freg` | None | `$f0` | None |
694693
| NVPTX | `reg16` | None | `rs0` | None |
695694
| NVPTX | `reg32` | None | `r0` | None |
696695
| NVPTX | `reg64` | None | `rd0` | None |

0 commit comments

Comments
 (0)