Skip to content

sync/atomic: public And/Or ops and race instrumentation #64331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
add0e65
sync/atomic: public And/Or apis
mauri870 Nov 25, 2023
7216be6
remove extra newline in api spec
mauri870 Nov 30, 2023
0df5ee4
Merge branch 'master' into feature/atomic-and-or
mauri870 Feb 13, 2024
d1b1813
add doc for issue 61395
mauri870 Feb 17, 2024
2b8769e
Merge branch 'master' into feature/atomic-and-or
mauri870 Feb 17, 2024
23fdd62
Merge branch 'master' into feature/atomic-and-or
mauri870 Mar 4, 2024
9a98e66
tentative fix, remove NOFRAME from s390x race
mauri870 Mar 5, 2024
787d515
Merge branch 'master' into feature/atomic-and-or
mauri870 Mar 15, 2024
dd9e303
s/racecall(SB)/racecall<>(SB)/
mauri870 Mar 15, 2024
93bb04b
change AndUintptr to return old
mauri870 Mar 15, 2024
8fde246
revert runtime·racecall(SB) to remove <>
mauri870 Mar 15, 2024
5049076
move race openbsd amd64 impl to race_amd64.s
mauri870 Mar 15, 2024
635f965
doc for And/Or
mauri870 Mar 15, 2024
28e63b1
fix condition for mask in tests
mauri870 Mar 15, 2024
e742b39
add todo for stack frame sizes in openbsd impl
mauri870 Apr 9, 2024
26e1ed0
Merge branch 'master' into feature/atomic-and-or
mauri870 Apr 10, 2024
515fa66
Merge branch 'master' into feature/atomic-and-or
mauri870 Apr 26, 2024
02ef876
Merge branch 'master' into feature/atomic-and-or
mauri870 May 1, 2024
81b6279
Merge remote-tracking branch 'origin' into feature/atomic-and-or
mauri870 May 6, 2024
727f5ff
Merge branch 'master' into feature/atomic-and-or
mauri870 May 13, 2024
97cd4bb
trying to figure out the calling convention
mauri870 May 13, 2024
e837f96
add comment with issue ticket in doc
mauri870 May 13, 2024
2384b05
use go:linkname for race CAS
mauri870 May 13, 2024
8f66378
fix copyright year
mauri870 May 14, 2024
d2219a2
remove openbsd workaround since -race is not supported anymore
mauri870 May 14, 2024
db314ff
remove newline
mauri870 May 14, 2024
0f5c275
fix issue number in api doc
mauri870 May 14, 2024
8354cb4
fix mask in OR tests
mauri870 May 14, 2024
21575fe
fix AND with mask
mauri870 May 14, 2024
f7dd791
more fixes for AND
mauri870 May 14, 2024
4b97947
remove NOFRAME from s390x and ppc
mauri870 May 15, 2024
06006a4
remove RET from ppc64le routines
mauri870 May 16, 2024
f174297
Merge remote-tracking branch 'origin/master' into feature/atomic-and-or
mauri870 May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions api/next/61395.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pkg sync/atomic, func AndInt32(*int32, int32) int32 #61395
pkg sync/atomic, func AndInt64(*int64, int64) int64 #61395
pkg sync/atomic, func AndUint32(*uint32, uint32) uint32 #61395
pkg sync/atomic, func AndUint64(*uint64, uint64) uint64 #61395
pkg sync/atomic, func AndUintptr(*uintptr, uintptr) uintptr #61395
pkg sync/atomic, func OrInt32(*int32, int32) int32 #61395
pkg sync/atomic, func OrInt64(*int64, int64) int64 #61395
pkg sync/atomic, func OrUint32(*uint32, uint32) uint32 #61395
pkg sync/atomic, func OrUint64(*uint64, uint64) uint64 #61395
pkg sync/atomic, func OrUintptr(*uintptr, uintptr) uintptr #61395
pkg sync/atomic, method (*Int32) And(int32) int32 #61395
pkg sync/atomic, method (*Int64) And(int64) int64 #61395
pkg sync/atomic, method (*Uint32) And(uint32) uint32 #61395
pkg sync/atomic, method (*Uint64) And(uint64) uint64 #61395
pkg sync/atomic, method (*Uintptr) And(uintptr) uintptr #61395
pkg sync/atomic, method (*Int32) Or(int32) int32 #61395
pkg sync/atomic, method (*Int64) Or(int64) int64 #61395
pkg sync/atomic, method (*Uint32) Or(uint32) uint32 #61395
pkg sync/atomic, method (*Uint64) Or(uint64) uint64 #61395
pkg sync/atomic, method (*Uintptr) Or(uintptr) uintptr #61395
3 changes: 3 additions & 0 deletions doc/next/6-stdlib/99-minor/sync/atomic/61395.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- Issue #61395 -->
The new [`atomic.And`](/pkg/sync/atomic#And) and [`atomic.Or`](/pkg/sync/atomic#Or)
operators apply a bitwise `AND` or `OR` to the given input, returning the old value.
34 changes: 34 additions & 0 deletions src/runtime/race.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ var __tsan_report_count byte
//go:cgo_import_static __tsan_go_atomic64_exchange
//go:cgo_import_static __tsan_go_atomic32_fetch_add
//go:cgo_import_static __tsan_go_atomic64_fetch_add
//go:cgo_import_static __tsan_go_atomic32_fetch_and
//go:cgo_import_static __tsan_go_atomic64_fetch_and
//go:cgo_import_static __tsan_go_atomic32_fetch_or
//go:cgo_import_static __tsan_go_atomic64_fetch_or
//go:cgo_import_static __tsan_go_atomic32_compare_exchange
//go:cgo_import_static __tsan_go_atomic64_compare_exchange

Expand Down Expand Up @@ -642,6 +646,36 @@ func abigen_sync_atomic_AddUint64(addr *uint64, delta uint64) (new uint64)
//go:linkname abigen_sync_atomic_AddUintptr sync/atomic.AddUintptr
func abigen_sync_atomic_AddUintptr(addr *uintptr, delta uintptr) (new uintptr)

//go:linkname abigen_sync_atomic_AndInt32 sync/atomic.AndInt32
func abigen_sync_atomic_AndInt32(addr *int32, mask int32) (old int32)

//go:linkname abigen_sync_atomic_AndUint32 sync/atomic.AndUint32
func abigen_sync_atomic_AndUint32(addr *uint32, mask uint32) (old uint32)

//go:linkname abigen_sync_atomic_AndInt64 sync/atomic.AndInt64
func abigen_sync_atomic_AndInt64(addr *int64, mask int64) (old int64)

//go:linkname abigen_sync_atomic_AndUint64 sync/atomic.AndUint64
func abigen_sync_atomic_AndUint64(addr *uint64, mask uint64) (old uint64)

//go:linkname abigen_sync_atomic_AndUintptr sync/atomic.AndUintptr
func abigen_sync_atomic_AndUintptr(addr *uintptr, mask uintptr) (old uintptr)

//go:linkname abigen_sync_atomic_OrInt32 sync/atomic.OrInt32
func abigen_sync_atomic_OrInt32(addr *int32, mask int32) (old int32)

//go:linkname abigen_sync_atomic_OrUint32 sync/atomic.OrUint32
func abigen_sync_atomic_OrUint32(addr *uint32, mask uint32) (old uint32)

//go:linkname abigen_sync_atomic_OrInt64 sync/atomic.OrInt64
func abigen_sync_atomic_OrInt64(addr *int64, mask int64) (old int64)

//go:linkname abigen_sync_atomic_OrUint64 sync/atomic.OrUint64
func abigen_sync_atomic_OrUint64(addr *uint64, mask uint64) (old uint64)

//go:linkname abigen_sync_atomic_OrUintptr sync/atomic.OrUintptr
func abigen_sync_atomic_OrUintptr(addr *uintptr, mask uintptr) (old uintptr)

//go:linkname abigen_sync_atomic_CompareAndSwapInt32 sync/atomic.CompareAndSwapInt32
func abigen_sync_atomic_CompareAndSwapInt32(addr *int32, old, new int32) (swapped bool)

Expand Down
51 changes: 51 additions & 0 deletions src/runtime/race_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,57 @@ TEXT sync∕atomic·AddUintptr(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·AddInt64(SB)

// And
TEXT sync∕atomic·AndInt32(SB), NOSPLIT|NOFRAME, $0-20
GO_ARGS
MOVQ $__tsan_go_atomic32_fetch_and(SB), AX
CALL racecallatomic<>(SB)
RET

TEXT sync∕atomic·AndInt64(SB), NOSPLIT|NOFRAME, $0-24
GO_ARGS
MOVQ $__tsan_go_atomic64_fetch_and(SB), AX
CALL racecallatomic<>(SB)
RET

TEXT sync∕atomic·AndUint32(SB), NOSPLIT, $0-20
GO_ARGS
JMP sync∕atomic·AndInt32(SB)

TEXT sync∕atomic·AndUint64(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·AndInt64(SB)

TEXT sync∕atomic·AndUintptr(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·AndInt64(SB)

// Or
TEXT sync∕atomic·OrInt32(SB), NOSPLIT|NOFRAME, $0-20
GO_ARGS
MOVQ $__tsan_go_atomic32_fetch_or(SB), AX
CALL racecallatomic<>(SB)
RET

TEXT sync∕atomic·OrInt64(SB), NOSPLIT|NOFRAME, $0-24
GO_ARGS
MOVQ $__tsan_go_atomic64_fetch_or(SB), AX
CALL racecallatomic<>(SB)
RET

TEXT sync∕atomic·OrUint32(SB), NOSPLIT, $0-20
GO_ARGS
JMP sync∕atomic·OrInt32(SB)

TEXT sync∕atomic·OrUint64(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·OrInt64(SB)

TEXT sync∕atomic·OrUintptr(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·OrInt64(SB)


// CompareAndSwap
TEXT sync∕atomic·CompareAndSwapInt32(SB), NOSPLIT|NOFRAME, $0-17
GO_ARGS
Expand Down
50 changes: 50 additions & 0 deletions src/runtime/race_arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,56 @@ TEXT sync∕atomic·AddUintptr(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·AddInt64(SB)

// And
TEXT sync∕atomic·AndInt32(SB), NOSPLIT, $0-20
GO_ARGS
MOVD $__tsan_go_atomic32_fetch_and(SB), R9
BL racecallatomic<>(SB)
RET

TEXT sync∕atomic·AndInt64(SB), NOSPLIT, $0-24
GO_ARGS
MOVD $__tsan_go_atomic64_fetch_and(SB), R9
BL racecallatomic<>(SB)
RET

TEXT sync∕atomic·AndUint32(SB), NOSPLIT, $0-20
GO_ARGS
JMP sync∕atomic·AndInt32(SB)

TEXT sync∕atomic·AndUint64(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·AndInt64(SB)

TEXT sync∕atomic·AndUintptr(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·AndInt64(SB)

// Or
TEXT sync∕atomic·OrInt32(SB), NOSPLIT, $0-20
GO_ARGS
MOVD $__tsan_go_atomic32_fetch_or(SB), R9
BL racecallatomic<>(SB)
RET

TEXT sync∕atomic·OrInt64(SB), NOSPLIT, $0-24
GO_ARGS
MOVD $__tsan_go_atomic64_fetch_or(SB), R9
BL racecallatomic<>(SB)
RET

TEXT sync∕atomic·OrUint32(SB), NOSPLIT, $0-20
GO_ARGS
JMP sync∕atomic·OrInt32(SB)

TEXT sync∕atomic·OrUint64(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·OrInt64(SB)

TEXT sync∕atomic·OrUintptr(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·OrInt64(SB)

// CompareAndSwap
TEXT sync∕atomic·CompareAndSwapInt32(SB), NOSPLIT, $0-17
GO_ARGS
Expand Down
46 changes: 46 additions & 0 deletions src/runtime/race_ppc64le.s
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,52 @@ TEXT sync∕atomic·AddUintptr(SB), NOSPLIT, $0-24
GO_ARGS
BR sync∕atomic·AddInt64(SB)

// And
TEXT sync∕atomic·AndInt32(SB), NOSPLIT, $0-20
GO_ARGS
MOVD $__tsan_go_atomic32_fetch_and(SB), R8
BR racecallatomic<>(SB)

TEXT sync∕atomic·AndInt64(SB), NOSPLIT, $0-24
GO_ARGS
MOVD $__tsan_go_atomic64_fetch_and(SB), R8
BR racecallatomic<>(SB)

TEXT sync∕atomic·AndUint32(SB), NOSPLIT, $0-20
GO_ARGS
BR sync∕atomic·AndInt32(SB)

TEXT sync∕atomic·AndUint64(SB), NOSPLIT, $0-24
GO_ARGS
BR sync∕atomic·AndInt64(SB)

TEXT sync∕atomic·AndUintptr(SB), NOSPLIT, $0-24
GO_ARGS
BR sync∕atomic·AndInt64(SB)

// Or
TEXT sync∕atomic·OrInt32(SB), NOSPLIT, $0-20
GO_ARGS
MOVD $__tsan_go_atomic32_fetch_or(SB), R8
BR racecallatomic<>(SB)

TEXT sync∕atomic·OrInt64(SB), NOSPLIT, $0-24
GO_ARGS
MOVD $__tsan_go_atomic64_fetch_or(SB), R8
BR racecallatomic<>(SB)

TEXT sync∕atomic·OrUint32(SB), NOSPLIT, $0-20
GO_ARGS
BR sync∕atomic·OrInt32(SB)

TEXT sync∕atomic·OrUint64(SB), NOSPLIT, $0-24
GO_ARGS
BR sync∕atomic·OrInt64(SB)

TEXT sync∕atomic·OrUintptr(SB), NOSPLIT, $0-24
GO_ARGS
BR sync∕atomic·OrInt64(SB)

// CompareAndSwap in tsan
TEXT sync∕atomic·CompareAndSwapInt32(SB), NOSPLIT, $0-17
GO_ARGS
Expand Down
50 changes: 50 additions & 0 deletions src/runtime/race_s390x.s
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,56 @@ TEXT sync∕atomic·AddUintptr(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·AddInt64(SB)

// And
TEXT sync∕atomic·AndInt32(SB), NOSPLIT, $0-20
GO_ARGS
MOVD $__tsan_go_atomic32_fetch_and(SB), R1
BL racecallatomic<>(SB)
RET

TEXT sync∕atomic·AndInt64(SB), NOSPLIT, $0-24
GO_ARGS
MOVD $__tsan_go_atomic64_fetch_and(SB), R1
BL racecallatomic<>(SB)
RET

TEXT sync∕atomic·AndUint32(SB), NOSPLIT, $0-20
GO_ARGS
JMP sync∕atomic·AndInt32(SB)

TEXT sync∕atomic·AndUint64(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·AndInt64(SB)

TEXT sync∕atomic·AndUintptr(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·AndInt64(SB)

// Or
TEXT sync∕atomic·OrInt32(SB), NOSPLIT, $0-20
GO_ARGS
MOVD $__tsan_go_atomic32_fetch_or(SB), R1
BL racecallatomic<>(SB)
RET

TEXT sync∕atomic·OrInt64(SB), NOSPLIT, $0-24
GO_ARGS
MOVD $__tsan_go_atomic64_fetch_or(SB), R1
BL racecallatomic<>(SB)
RET

TEXT sync∕atomic·OrUint32(SB), NOSPLIT, $0-20
GO_ARGS
JMP sync∕atomic·OrInt32(SB)

TEXT sync∕atomic·OrUint64(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·OrInt64(SB)

TEXT sync∕atomic·OrUintptr(SB), NOSPLIT, $0-24
GO_ARGS
JMP sync∕atomic·OrInt64(SB)

// CompareAndSwap

TEXT sync∕atomic·CompareAndSwapInt32(SB), NOSPLIT, $0-17
Expand Down
30 changes: 30 additions & 0 deletions src/sync/atomic/asm.s
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,33 @@ TEXT ·StoreUint64(SB),NOSPLIT,$0

TEXT ·StoreUintptr(SB),NOSPLIT,$0
JMP internal∕runtime∕atomic·Storeuintptr(SB)

TEXT ·AndInt32(SB),NOSPLIT,$0
JMP internal∕runtime∕atomic·And32(SB)

TEXT ·AndUint32(SB),NOSPLIT,$0
JMP internal∕runtime∕atomic·And32(SB)

TEXT ·AndUintptr(SB),NOSPLIT,$0
JMP internal∕runtime∕atomic·Anduintptr(SB)

TEXT ·AndInt64(SB),NOSPLIT,$0
JMP internal∕runtime∕atomic·And64(SB)

TEXT ·AndUint64(SB),NOSPLIT,$0
JMP internal∕runtime∕atomic·And64(SB)

TEXT ·OrInt32(SB),NOSPLIT,$0
JMP internal∕runtime∕atomic·Or32(SB)

TEXT ·OrUint32(SB),NOSPLIT,$0
JMP internal∕runtime∕atomic·Or32(SB)

TEXT ·OrUintptr(SB),NOSPLIT,$0
JMP internal∕runtime∕atomic·Oruintptr(SB)

TEXT ·OrInt64(SB),NOSPLIT,$0
JMP internal∕runtime∕atomic·Or64(SB)

TEXT ·OrUint64(SB),NOSPLIT,$0
JMP internal∕runtime∕atomic·Or64(SB)
Loading