diff options
author | Ian Lance Taylor <iant@golang.org> | 2021-08-03 16:22:48 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-08-05 11:41:57 -0700 |
commit | 582c24e9fe81f75684892de0bf580e6918695dd9 (patch) | |
tree | 881521a731703960ecee3338ddffddbff4f1fa14 /libgo/go | |
parent | c8b024fa4b76bfd914e96dd3cecfbb6ee8e91316 (diff) | |
download | gcc-582c24e9fe81f75684892de0bf580e6918695dd9.tar.gz |
runtime: extend internal atomics to comply with sync/atomic
This is the gofrontend version of https://golang.org/cl/289152.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/339690
Diffstat (limited to 'libgo/go')
-rw-r--r-- | libgo/go/runtime/internal/atomic/atomic.c | 80 | ||||
-rw-r--r-- | libgo/go/runtime/internal/atomic/stubs.go | 25 |
2 files changed, 105 insertions, 0 deletions
diff --git a/libgo/go/runtime/internal/atomic/atomic.c b/libgo/go/runtime/internal/atomic/atomic.c index 569e56e450e..b5a0940563a 100644 --- a/libgo/go/runtime/internal/atomic/atomic.c +++ b/libgo/go/runtime/internal/atomic/atomic.c @@ -104,6 +104,16 @@ Loaduint (uintgo *ptr) return __atomic_load_n (ptr, __ATOMIC_SEQ_CST); } +int32_t Loadint32 (int32_t *ptr) + __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Loadint32") + __attribute__ ((no_split_stack)); + +int32_t +Loadint32 (int32_t *ptr) +{ + return __atomic_load_n (ptr, __ATOMIC_SEQ_CST); +} + int64_t Loadint64 (int64_t *ptr) __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Loadint64") __attribute__ ((no_split_stack)); @@ -126,6 +136,16 @@ Xadd (uint32_t *ptr, int32_t delta) return __atomic_add_fetch (ptr, (uint32_t) delta, __ATOMIC_SEQ_CST); } +int32_t Xaddint32 (int32_t *ptr, int32_t delta) + __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Xaddint32") + __attribute__ ((no_split_stack)); + +int32_t +Xaddint32 (int32_t *ptr, int32_t delta) +{ + return __atomic_add_fetch (ptr, delta, __ATOMIC_SEQ_CST); +} + uint64_t Xadd64 (uint64_t *ptr, int64_t delta) __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Xadd64") __attribute__ ((no_split_stack)); @@ -170,6 +190,16 @@ Xchg (uint32_t *ptr, uint32_t new) return __atomic_exchange_n (ptr, new, __ATOMIC_SEQ_CST); } +int32_t Xchgint32 (int32_t *ptr, int32_t new) + __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Xchgint32") + __attribute__ ((no_split_stack)); + +int32_t +Xchgint32 (int32_t *ptr, int32_t new) +{ + return __atomic_exchange_n (ptr, new, __ATOMIC_SEQ_CST); +} + uint64_t Xchg64 (uint64_t *ptr, uint64_t new) __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Xchg64") __attribute__ ((no_split_stack)); @@ -182,6 +212,16 @@ Xchg64 (uint64_t *ptr, uint64_t new) return __atomic_exchange_n (ptr, new, __ATOMIC_SEQ_CST); } +int64_t Xchgint64 (int64_t *ptr, int64_t new) + __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Xchgint64") + __attribute__ ((no_split_stack)); + +int64_t +Xchgint64 (int64_t *ptr, int64_t new) +{ + return __atomic_exchange_n (ptr, new, __ATOMIC_SEQ_CST); +} + uintptr_t Xchguintptr (uintptr_t *ptr, uintptr_t new) __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Xchguintptr") __attribute__ ((no_split_stack)); @@ -264,6 +304,26 @@ CasRel (uint32_t *ptr, uint32_t old, uint32_t new) return __atomic_compare_exchange_n (ptr, &old, new, false, __ATOMIC_RELEASE, __ATOMIC_RELAXED); } +_Bool Casint32 (int32_t *ptr, int32_t old, int32_t new) + __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Casint32") + __attribute__ ((no_split_stack)); + +_Bool +Casint32 (int32_t *ptr, int32_t old, int32_t new) +{ + return __atomic_compare_exchange_n (ptr, &old, new, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); +} + +_Bool Casint64 (int64_t *ptr, int64_t old, int64_t new) + __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Casint64") + __attribute__ ((no_split_stack)); + +_Bool +Casint64 (int64_t *ptr, int64_t old, int64_t new) +{ + return __atomic_compare_exchange_n (ptr, &old, new, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); +} + _Bool Casp1 (void **ptr, void *old, void *new) __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Casp1") __attribute__ ((no_split_stack)); @@ -304,6 +364,16 @@ Store8 (uint8_t *ptr, uint8_t val) __atomic_store_n (ptr, val, __ATOMIC_SEQ_CST); } +void Storeint32 (int32_t *ptr, int32_t val) + __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Storeint32") + __attribute__ ((no_split_stack)); + +void +Storeint32 (int32_t *ptr, int32_t val) +{ + __atomic_store_n (ptr, val, __ATOMIC_SEQ_CST); +} + void Store64 (uint64_t *ptr, uint64_t val) __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Store64") __attribute__ ((no_split_stack)); @@ -338,6 +408,16 @@ StoreRel64 (uint64_t *ptr, uint64_t val) __atomic_store_n (ptr, val, __ATOMIC_RELEASE); } +void Storeint64 (int64_t *ptr, int64_t val) + __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.Storeint64") + __attribute__ ((no_split_stack)); + +void +Storeint64 (int64_t *ptr, int64_t val) +{ + __atomic_store_n (ptr, val, __ATOMIC_SEQ_CST); +} + void StoreReluintptr (uintptr_t *ptr, uintptr_t val) __asm__ (GOSYM_PREFIX "runtime_1internal_1atomic.StoreReluintptr") __attribute__ ((no_split_stack)); diff --git a/libgo/go/runtime/internal/atomic/stubs.go b/libgo/go/runtime/internal/atomic/stubs.go index 62e30d17882..e7544ba4484 100644 --- a/libgo/go/runtime/internal/atomic/stubs.go +++ b/libgo/go/runtime/internal/atomic/stubs.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build !wasm // +build !wasm package atomic @@ -15,9 +16,21 @@ func Cas(ptr *uint32, old, new uint32) bool func Casp1(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool //go:noescape +func Casint32(ptr *int32, old, new int32) bool + +//go:noescape +func Casint64(ptr *int64, old, new int64) bool + +//go:noescape func Casuintptr(ptr *uintptr, old, new uintptr) bool //go:noescape +func Storeint32(ptr *int32, new int32) + +//go:noescape +func Storeint64(ptr *int64, new int64) + +//go:noescape func Storeuintptr(ptr *uintptr, new uintptr) //go:noescape @@ -29,7 +42,19 @@ func Loaduint(ptr *uint) uint // TODO(matloob): Should these functions have the go:noescape annotation? //go:noescape +func Loadint32(ptr *int32) int32 + +//go:noescape func Loadint64(ptr *int64) int64 //go:noescape +func Xaddint32(ptr *int32, delta int32) int32 + +//go:noescape func Xaddint64(ptr *int64, delta int64) int64 + +//go:noescape +func Xchgint32(ptr *int32, new int32) int32 + +//go:noescape +func Xchgint64(ptr *int64, new int64) int64 |