Skip to content

Commit d98f74b

Browse files
Cooper-Qugopherbot
authored andcommitted
cmd/compile/internal: intrinsify publicationBarrier on riscv64
This enables publicationBarrier to be used as an intrinsic on riscv64, optimizing the required function call and return instructions for invoking the "runtime.publicationBarrier" function. This function is called by mallocgc. The benchmark results for malloc tested on Lichee-Pi-4A(TH1520, RISC-V 2.0G C910 x4) are as follows. goos: linux goarch: riscv64 pkg: runtime │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ Malloc8-4 92.78n ± 1% 90.77n ± 1% -2.17% (p=0.001 n=10) Malloc16-4 156.5n ± 1% 151.7n ± 2% -3.10% (p=0.000 n=10) MallocTypeInfo8-4 131.7n ± 1% 130.6n ± 2% ~ (p=0.165 n=10) MallocTypeInfo16-4 186.5n ± 2% 186.2n ± 1% ~ (p=0.956 n=10) MallocLargeStruct-4 1.345µ ± 1% 1.355µ ± 1% ~ (p=0.093 n=10) geomean 216.9n 214.5n -1.10% Change-Id: Ieab6c02309614bac5c1b12b5ee3311f988ff644d Reviewed-on: https://go-review.googlesource.com/c/go/+/531719 Reviewed-by: Michael Pratt <[email protected]> Auto-Submit: Michael Pratt <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: M Zhuo <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Joel Sing <[email protected]>
1 parent 1b5cfc6 commit d98f74b

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
lines changed

src/cmd/compile/internal/riscv64/ssa.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,10 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
695695
p.To.Sym = ir.Syms.Duffcopy
696696
p.To.Offset = v.AuxInt
697697

698+
case ssa.OpRISCV64LoweredPubBarrier:
699+
// FENCE
700+
s.Prog(v.Op.Asm())
701+
698702
case ssa.OpRISCV64LoweredRound32F, ssa.OpRISCV64LoweredRound64F:
699703
// input is already rounded
700704

src/cmd/compile/internal/ssa/_gen/RISCV64.rules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@
412412
// Write barrier.
413413
(WB ...) => (LoweredWB ...)
414414

415+
// Publication barrier as intrinsic
416+
(PubBarrier ...) => (LoweredPubBarrier ...)
417+
415418
(PanicBounds [kind] x y mem) && boundsABI(kind) == 0 => (LoweredPanicBoundsA [kind] x y mem)
416419
(PanicBounds [kind] x y mem) && boundsABI(kind) == 1 => (LoweredPanicBoundsB [kind] x y mem)
417420
(PanicBounds [kind] x y mem) && boundsABI(kind) == 2 => (LoweredPanicBoundsC [kind] x y mem)

src/cmd/compile/internal/ssa/_gen/RISCV64Ops.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ func init() {
399399
// Returns a pointer to a write barrier buffer in X24.
400400
{name: "LoweredWB", argLength: 1, reg: regInfo{clobbers: (callerSave &^ (gpMask | regNamed["g"])) | regNamed["X1"], outputs: []regMask{regNamed["X24"]}}, clobberFlags: true, aux: "Int64"},
401401

402+
// Do data barrier. arg0=memorys
403+
{name: "LoweredPubBarrier", argLength: 1, asm: "FENCE", hasSideEffects: true},
404+
402405
// There are three of these functions so that they can have three different register inputs.
403406
// When we check 0 <= c <= cap (A), then 0 <= b <= c (B), then 0 <= a <= b (C), we want the
404407
// default registers to match so we don't need to copy registers around unnecessarily.

src/cmd/compile/internal/ssa/opGen.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/compile/internal/ssa/rewriteRISCV64.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/compile/internal/ssagen/ssa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4147,7 +4147,7 @@ func InitTables() {
41474147
s.vars[memVar] = s.newValue1(ssa.OpPubBarrier, types.TypeMem, s.mem())
41484148
return nil
41494149
},
4150-
sys.ARM64, sys.PPC64)
4150+
sys.ARM64, sys.PPC64, sys.RISCV64)
41514151

41524152
brev_arch := []sys.ArchFamily{sys.AMD64, sys.I386, sys.ARM64, sys.ARM, sys.S390X}
41534153
if buildcfg.GOPPC64 >= 10 {

0 commit comments

Comments
 (0)