-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/runtime/atomic: add Xchg8 for amd64
For #68578 Change-Id: Idecfdbb793f46560dd69287af9170c07cf4ee973 Reviewed-on: https://go-review.googlesource.com/c/go/+/606900 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Mauri de Souza Meneguzzo <[email protected]> Auto-Submit: Rhys Hiltner <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024 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. | ||
|
||
//go:build amd64 | ||
|
||
package atomic_test | ||
|
||
import ( | ||
"internal/runtime/atomic" | ||
"testing" | ||
) | ||
|
||
func TestXchg8(t *testing.T) { | ||
var a [16]uint8 | ||
for i := range a { | ||
next := uint8(i + 50) | ||
a[i] = next | ||
} | ||
b := a | ||
|
||
// Compare behavior against non-atomic implementation. Expect the operation | ||
// to work at any byte offset and to not clobber neighboring values. | ||
for i := range a { | ||
next := uint8(i + 100) | ||
pa := atomic.Xchg8(&a[i], next) | ||
pb := b[i] | ||
b[i] = next | ||
if pa != pb { | ||
t.Errorf("atomic.Xchg8(a[%d]); %d != %d", i, pa, pb) | ||
} | ||
if a != b { | ||
t.Errorf("after atomic.Xchg8(a[%d]); %d != %d", i, a, b) | ||
} | ||
if t.Failed() { | ||
break | ||
} | ||
} | ||
} |