Skip to content

Commit dc8902f

Browse files
rhyshgopherbot
authored andcommitted
cmd/compile/internal/ssa: intrinsify atomic.Xchg8 on amd64
For #68578 Change-Id: Ia9580579bfc4709945bfcf6ec3803d5d11812187 Reviewed-on: https://go-review.googlesource.com/c/go/+/606901 Reviewed-by: Mauri de Souza Meneguzzo <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Martin Möhrmann <[email protected]> Auto-Submit: Rhys Hiltner <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 841bb62 commit dc8902f

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@
563563
(AtomicStorePtrNoWB ptr val mem) => (Select1 (XCHGQ <types.NewTuple(typ.BytePtr,types.TypeMem)> val ptr mem))
564564

565565
// Atomic exchanges.
566+
(AtomicExchange8 ptr val mem) => (XCHGB val ptr mem)
566567
(AtomicExchange32 ptr val mem) => (XCHGL val ptr mem)
567568
(AtomicExchange64 ptr val mem) => (XCHGQ val ptr mem)
568569

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

+1
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ var genericOps = []opData{
604604
{name: "AtomicStorePtrNoWB", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns memory.
605605
{name: "AtomicStoreRel32", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Lock release, returns memory.
606606
{name: "AtomicStoreRel64", argLength: 3, typ: "Mem", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Lock release, returns memory.
607+
{name: "AtomicExchange8", argLength: 3, typ: "(UInt8,Mem)", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns old contents of *arg0 and new memory.
607608
{name: "AtomicExchange32", argLength: 3, typ: "(UInt32,Mem)", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns old contents of *arg0 and new memory.
608609
{name: "AtomicExchange64", argLength: 3, typ: "(UInt64,Mem)", hasSideEffects: true}, // Store arg1 to *arg0. arg2=memory. Returns old contents of *arg0 and new memory.
609610
{name: "AtomicAdd32", argLength: 3, typ: "(UInt32,Mem)", hasSideEffects: true}, // Do *arg0 += arg1. arg2=memory. Returns sum and new memory.

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

+7
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

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+7
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ func initIntrinsics(cfg *intrinsicBuildConfig) {
296296
},
297297
sys.PPC64)
298298

299+
addF("internal/runtime/atomic", "Xchg8",
300+
func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
301+
v := s.newValue3(ssa.OpAtomicExchange8, types.NewTuple(types.Types[types.TUINT8], types.TypeMem), args[0], args[1], s.mem())
302+
s.vars[memVar] = s.newValue1(ssa.OpSelect1, types.TypeMem, v)
303+
return s.newValue1(ssa.OpSelect0, types.Types[types.TUINT8], v)
304+
},
305+
sys.AMD64)
299306
addF("internal/runtime/atomic", "Xchg",
300307
func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
301308
v := s.newValue3(ssa.OpAtomicExchange32, types.NewTuple(types.Types[types.TUINT32], types.TypeMem), args[0], args[1], s.mem())

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

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ var wantIntrinsics = map[testIntrinsicKey]struct{}{
8484
{"amd64", "internal/runtime/atomic", "Xadduintptr"}: struct{}{},
8585
{"amd64", "internal/runtime/atomic", "Xchg"}: struct{}{},
8686
{"amd64", "internal/runtime/atomic", "Xchg64"}: struct{}{},
87+
{"amd64", "internal/runtime/atomic", "Xchg8"}: struct{}{},
8788
{"amd64", "internal/runtime/atomic", "Xchgint32"}: struct{}{},
8889
{"amd64", "internal/runtime/atomic", "Xchgint64"}: struct{}{},
8990
{"amd64", "internal/runtime/atomic", "Xchguintptr"}: struct{}{},

0 commit comments

Comments
 (0)