Skip to content

Commit 44dbeaf

Browse files
committed
cmd/compile: intrinsify runtime/internal/atomic.{And,Or} on AMD64
These are identical to And8 and Or8, just using ANDL/ORL instead of ANDB/ORB. Change-Id: I99cf90a8b0b5f211fb23325dddd55821875f0c8f Reviewed-on: https://go-review.googlesource.com/c/go/+/263140 Run-TryBot: Michael Pratt <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Michael Pratt <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent ad61343 commit 44dbeaf

File tree

7 files changed

+103
-3
lines changed

7 files changed

+103
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
12101210
p = s.Prog(x86.ASETEQ)
12111211
p.To.Type = obj.TYPE_REG
12121212
p.To.Reg = v.Reg0()
1213-
case ssa.OpAMD64ANDBlock, ssa.OpAMD64ORBlock:
1213+
case ssa.OpAMD64ANDBlock, ssa.OpAMD64ANDLlock, ssa.OpAMD64ORBlock, ssa.OpAMD64ORLlock:
12141214
s.Prog(x86.ALOCK)
12151215
p := s.Prog(v.Op.Asm())
12161216
p.From.Type = obj.TYPE_REG

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3541,12 +3541,24 @@ func init() {
35413541
return nil
35423542
},
35433543
sys.AMD64, sys.ARM64, sys.MIPS, sys.PPC64, sys.S390X)
3544+
addF("runtime/internal/atomic", "And",
3545+
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
3546+
s.vars[&memVar] = s.newValue3(ssa.OpAtomicAnd32, types.TypeMem, args[0], args[1], s.mem())
3547+
return nil
3548+
},
3549+
sys.AMD64) // TODO: same arches as And8.
35443550
addF("runtime/internal/atomic", "Or8",
35453551
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
35463552
s.vars[&memVar] = s.newValue3(ssa.OpAtomicOr8, types.TypeMem, args[0], args[1], s.mem())
35473553
return nil
35483554
},
35493555
sys.AMD64, sys.ARM64, sys.MIPS, sys.PPC64, sys.S390X)
3556+
addF("runtime/internal/atomic", "Or",
3557+
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
3558+
s.vars[&memVar] = s.newValue3(ssa.OpAtomicOr32, types.TypeMem, args[0], args[1], s.mem())
3559+
return nil
3560+
},
3561+
sys.AMD64) // TODO: same arches as Or8.
35503562

35513563
alias("runtime/internal/atomic", "Loadint64", "runtime/internal/atomic", "Load64", all...)
35523564
alias("runtime/internal/atomic", "Xaddint64", "runtime/internal/atomic", "Xadd64", all...)

src/cmd/compile/internal/ssa/gen/AMD64.rules

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,10 @@
530530
(AtomicCompareAndSwap64 ptr old new_ mem) => (CMPXCHGQlock ptr old new_ mem)
531531

532532
// Atomic memory updates.
533-
(AtomicAnd8 ptr val mem) => (ANDBlock ptr val mem)
534-
(AtomicOr8 ptr val mem) => (ORBlock ptr val mem)
533+
(AtomicAnd8 ptr val mem) => (ANDBlock ptr val mem)
534+
(AtomicAnd32 ptr val mem) => (ANDLlock ptr val mem)
535+
(AtomicOr8 ptr val mem) => (ORBlock ptr val mem)
536+
(AtomicOr32 ptr val mem) => (ORLlock ptr val mem)
535537

536538
// Write barrier.
537539
(WB ...) => (LoweredWB ...)

src/cmd/compile/internal/ssa/gen/AMD64Ops.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,9 @@ func init() {
902902

903903
// Atomic memory updates.
904904
{name: "ANDBlock", argLength: 3, reg: gpstore, asm: "ANDB", aux: "SymOff", clobberFlags: true, faultOnNilArg0: true, hasSideEffects: true, symEffect: "RdWr"}, // *(arg0+auxint+aux) &= arg1
905+
{name: "ANDLlock", argLength: 3, reg: gpstore, asm: "ANDL", aux: "SymOff", clobberFlags: true, faultOnNilArg0: true, hasSideEffects: true, symEffect: "RdWr"}, // *(arg0+auxint+aux) &= arg1
905906
{name: "ORBlock", argLength: 3, reg: gpstore, asm: "ORB", aux: "SymOff", clobberFlags: true, faultOnNilArg0: true, hasSideEffects: true, symEffect: "RdWr"}, // *(arg0+auxint+aux) |= arg1
907+
{name: "ORLlock", argLength: 3, reg: gpstore, asm: "ORL", aux: "SymOff", clobberFlags: true, faultOnNilArg0: true, hasSideEffects: true, symEffect: "RdWr"}, // *(arg0+auxint+aux) |= arg1
906908
}
907909

908910
var AMD64blocks = []blockData{

src/cmd/compile/internal/ssa/gen/genericOps.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,9 @@ var genericOps = []opData{
565565
{name: "AtomicCompareAndSwap64", argLength: 4, typ: "(Bool,Mem)", hasSideEffects: true}, // if *arg0==arg1, then set *arg0=arg2. Returns true if store happens and new memory.
566566
{name: "AtomicCompareAndSwapRel32", argLength: 4, typ: "(Bool,Mem)", hasSideEffects: true}, // if *arg0==arg1, then set *arg0=arg2. Lock release, reports whether store happens and new memory.
567567
{name: "AtomicAnd8", argLength: 3, typ: "Mem", hasSideEffects: true}, // *arg0 &= arg1. arg2=memory. Returns memory.
568+
{name: "AtomicAnd32", argLength: 3, typ: "Mem", hasSideEffects: true}, // *arg0 &= arg1. arg2=memory. Returns memory.
568569
{name: "AtomicOr8", argLength: 3, typ: "Mem", hasSideEffects: true}, // *arg0 |= arg1. arg2=memory. Returns memory.
570+
{name: "AtomicOr32", argLength: 3, typ: "Mem", hasSideEffects: true}, // *arg0 |= arg1. arg2=memory. Returns memory.
569571

570572
// Atomic operation variants
571573
// These variants have the same semantics as above atomic operations.

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

Lines changed: 48 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/rewriteAMD64.go

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

0 commit comments

Comments
 (0)