Skip to content

Commit a691fec

Browse files
committed
ctxreg: handle riscv32 targets
1 parent 2a3a0b3 commit a691fec

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

internal/build/target_arch.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ func goarchFromTriple(triple string) string {
4040
case "riscv64":
4141
return "riscv64"
4242
case "riscv32":
43-
// ESP32-C3 and other RISC-V 32-bit targets can use the same x27 register as riscv64
44-
return "riscv64"
43+
return "riscv32"
4544
case "wasm32":
4645
return "wasm"
4746
}

internal/ctxreg/ctxreg.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var table = map[string]Info{
1111
"arm64": {Name: "x26", Constraint: "{x26}"},
1212
"386": {Name: "mm0", Constraint: "{mm0}"},
1313
"riscv64": {Name: "x27", Constraint: "{x27}"},
14+
"riscv32": {Name: "x27", Constraint: "{x27}"},
1415
}
1516

1617
// Get returns the register info for the given GOARCH.

ssa/ctxreg.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ var ctxAsmTemplates = map[string]ctxAsmTemplate{
3535
read: "mv $0, %s",
3636
dialect: llvm.InlineAsmDialectATT,
3737
},
38+
"riscv32": {
39+
write: "mv %s, $0",
40+
read: "mv $0, %s",
41+
dialect: llvm.InlineAsmDialectATT,
42+
},
3843
}
3944

4045
func ctxAsmStrings(goarch, reg string) (write string, read string, dialect llvm.InlineAsmDialect, ok bool) {

ssa/target.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Target struct {
4141
// - amd64: MM0 - MMX register (caller-saved), avoid MMX usage via -msse2
4242
// - 386: MM0 - MMX register (caller-saved), avoid MMX usage via -msse2
4343
// - arm64: X26 - callee-saved, reservable via +reserve-x26
44-
// - riscv64: X27 (s11) - callee-saved register
44+
// - riscv64/riscv32: X27 (s11) - callee-saved register
4545
//
4646
// Platforms without a ctx register:
4747
// - arm: r8-r15 are "high registers", LLVM can't use {rN} constraint in ARM mode
@@ -66,6 +66,8 @@ func (t *Target) CtxRegister() CtxRegister {
6666
return CtxRegister{Name: "mm0", Constraint: "{mm0}"}
6767
case "riscv64":
6868
return CtxRegister{Name: "x27", Constraint: "{x27}"}
69+
case "riscv32":
70+
return CtxRegister{Name: "x27", Constraint: "{x27}"}
6971
default:
7072
return CtxRegister{}
7173
}

0 commit comments

Comments
 (0)