diff options
| author | Keith Randall <khr@golang.org> | 2016-08-23 16:49:28 -0700 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2016-08-25 20:09:04 +0000 |
| commit | 320ddcf8344beb1c322f3a7f0a251eea5e442a10 (patch) | |
| tree | 6401b5a28fd5beecec4d2d9518528bc3eb7fcd2c /src/runtime/internal/atomic | |
| parent | 71ab9fa312f8266379dbb358b9ee9303cde7bd6b (diff) | |
| download | go-320ddcf8344beb1c322f3a7f0a251eea5e442a10.tar.xz | |
cmd/compile: inline atomics from runtime/internal/atomic on amd64
Inline atomic reads and writes on amd64. There's no reason
to pay the overhead of a call for these.
To keep atomic loads from being reordered, we make them
return a <value,memory> tuple.
Change the meaning of resultInArg0 for tuple-generating ops
to mean the first part of the result tuple, not the second.
This means we can always put the store part of the tuple last,
matching how arguments are laid out. This requires reordering
the outputs of add32carry and sub32carry and their descendents
in various architectures.
benchmark old ns/op new ns/op delta
BenchmarkAtomicLoad64-8 2.09 0.26 -87.56%
BenchmarkAtomicStore64-8 7.54 5.72 -24.14%
TBD (in a different CL): Cas, Or8, ...
Change-Id: I713ea88e7da3026c44ea5bdb56ed094b20bc5207
Reviewed-on: https://go-review.googlesource.com/27641
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/runtime/internal/atomic')
| -rw-r--r-- | src/runtime/internal/atomic/asm_amd64.s | 3 | ||||
| -rw-r--r-- | src/runtime/internal/atomic/bench_test.go | 28 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/runtime/internal/atomic/asm_amd64.s b/src/runtime/internal/atomic/asm_amd64.s index 32dbbf763d..6fb5211c9c 100644 --- a/src/runtime/internal/atomic/asm_amd64.s +++ b/src/runtime/internal/atomic/asm_amd64.s @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Note: some of these functions are semantically inlined +// by the compiler (in src/cmd/compile/internal/gc/ssa.go). + #include "textflag.h" // bool Cas(int32 *val, int32 old, int32 new) diff --git a/src/runtime/internal/atomic/bench_test.go b/src/runtime/internal/atomic/bench_test.go new file mode 100644 index 0000000000..47010e32d5 --- /dev/null +++ b/src/runtime/internal/atomic/bench_test.go @@ -0,0 +1,28 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package atomic_test + +import ( + "runtime/internal/atomic" + "testing" +) + +var sink interface{} + +func BenchmarkAtomicLoad64(b *testing.B) { + var x uint64 + sink = &x + for i := 0; i < b.N; i++ { + _ = atomic.Load64(&x) + } +} + +func BenchmarkAtomicStore64(b *testing.B) { + var x uint64 + sink = &x + for i := 0; i < b.N; i++ { + atomic.Store64(&x, 0) + } +} |
