From: Ian Lance Taylor Date: Tue, 3 Aug 2021 23:22:48 +0000 (-0700) Subject: runtime: extend internal atomics to comply with sync/atomic X-Git-Tag: upstream/12.2.0~5923 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=582c24e9fe81f75684892de0bf580e6918695dd9;p=platform%2Fupstream%2Fgcc.git 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 --- diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 394530c..19ab2de 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -b47bcf942daa9a0c252db9b57b8f138adbfcdaa2 +32590102c464679f845667b5554e1dcce2549ad2 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 3e433d6..33177a7 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -11590,12 +11590,10 @@ Call_expression::intrinsify(Gogo* gogo, // sync/atomic functions and runtime/internal/atomic functions // are very similar. In order not to duplicate code, we just // redirect to the latter and let the code below to handle them. - // In case there is no equivalent functions (slight variance - // in types), we just make an artificial name (begin with '$'). // Note: no StorePointer, SwapPointer, and CompareAndSwapPointer, // as they need write barriers. if (name == "LoadInt32") - name = "$Loadint32"; + name = "Loadint32"; else if (name == "LoadInt64") name = "Loadint64"; else if (name == "LoadUint32") @@ -11607,9 +11605,9 @@ Call_expression::intrinsify(Gogo* gogo, else if (name == "LoadPointer") name = "Loadp"; else if (name == "StoreInt32") - name = "$Storeint32"; + name = "Storeint32"; else if (name == "StoreInt64") - name = "$Storeint64"; + name = "Storeint64"; else if (name == "StoreUint32") name = "Store"; else if (name == "StoreUint64") @@ -11617,7 +11615,7 @@ Call_expression::intrinsify(Gogo* gogo, else if (name == "StoreUintptr") name = "Storeuintptr"; else if (name == "AddInt32") - name = "$Xaddint32"; + name = "Xaddint32"; else if (name == "AddInt64") name = "Xaddint64"; else if (name == "AddUint32") @@ -11627,9 +11625,9 @@ Call_expression::intrinsify(Gogo* gogo, else if (name == "AddUintptr") name = "Xadduintptr"; else if (name == "SwapInt32") - name = "$Xchgint32"; + name = "Xchgint32"; else if (name == "SwapInt64") - name = "$Xchgint64"; + name = "Xchgint64"; else if (name == "SwapUint32") name = "Xchg"; else if (name == "SwapUint64") @@ -11637,9 +11635,9 @@ Call_expression::intrinsify(Gogo* gogo, else if (name == "SwapUintptr") name = "Xchguintptr"; else if (name == "CompareAndSwapInt32") - name = "$Casint32"; + name = "Casint32"; else if (name == "CompareAndSwapInt64") - name = "$Casint64"; + name = "Casint64"; else if (name == "CompareAndSwapUint32") name = "Cas"; else if (name == "CompareAndSwapUint64") @@ -11875,7 +11873,7 @@ Call_expression::intrinsify(Gogo* gogo, if ((name == "Load" || name == "Load64" || name == "Loadint64" || name == "Loadp" || name == "Loaduint" || name == "Loaduintptr" || name == "LoadAcq" - || name == "$Loadint32") + || name == "Loadint32") && this->args_ != NULL && this->args_->size() == 1) { if (int_size < 8 && (name == "Load64" || name == "Loadint64")) @@ -11895,7 +11893,7 @@ Call_expression::intrinsify(Gogo* gogo, code = Runtime::ATOMIC_LOAD_8; res_type = uint64_type; } - else if (name == "$Loadint32") + else if (name == "Loadint32") { code = Runtime::ATOMIC_LOAD_4; res_type = int32_type; @@ -11942,10 +11940,10 @@ Call_expression::intrinsify(Gogo* gogo, if ((name == "Store" || name == "Store64" || name == "StorepNoWB" || name == "Storeuintptr" || name == "StoreRel" - || name == "$Storeint32" || name == "$Storeint64") + || name == "Storeint32" || name == "Storeint64") && this->args_ != NULL && this->args_->size() == 2) { - if (int_size < 8 && (name == "Store64" || name == "$Storeint64")) + if (int_size < 8 && (name == "Store64" || name == "Storeint64")) return NULL; Runtime::Function code; @@ -11955,9 +11953,9 @@ Call_expression::intrinsify(Gogo* gogo, code = Runtime::ATOMIC_STORE_4; else if (name == "Store64") code = Runtime::ATOMIC_STORE_8; - else if (name == "$Storeint32") + else if (name == "Storeint32") code = Runtime::ATOMIC_STORE_4; - else if (name == "$Storeint64") + else if (name == "Storeint64") code = Runtime::ATOMIC_STORE_8; else if (name == "Storeuintptr") code = (ptr_size == 8 ? Runtime::ATOMIC_STORE_8 : Runtime::ATOMIC_STORE_4); @@ -11979,7 +11977,7 @@ Call_expression::intrinsify(Gogo* gogo, } if ((name == "Xchg" || name == "Xchg64" || name == "Xchguintptr" - || name == "$Xchgint32" || name == "$Xchgint64") + || name == "Xchgint32" || name == "Xchgint64") && this->args_ != NULL && this->args_->size() == 2) { if (int_size < 8 && (name == "Xchg64" || name == "Xchgint64")) @@ -11997,12 +11995,12 @@ Call_expression::intrinsify(Gogo* gogo, code = Runtime::ATOMIC_EXCHANGE_8; res_type = uint64_type; } - else if (name == "$Xchgint32") + else if (name == "Xchgint32") { code = Runtime::ATOMIC_EXCHANGE_4; res_type = int32_type; } - else if (name == "$Xchgint64") + else if (name == "Xchgint64") { code = Runtime::ATOMIC_EXCHANGE_8; res_type = int64_type; @@ -12025,10 +12023,10 @@ Call_expression::intrinsify(Gogo* gogo, if ((name == "Cas" || name == "Cas64" || name == "Casuintptr" || name == "Casp1" || name == "CasRel" - || name == "$Casint32" || name == "$Casint64") + || name == "Casint32" || name == "Casint64") && this->args_ != NULL && this->args_->size() == 3) { - if (int_size < 8 && (name == "Cas64" || name == "$Casint64")) + if (int_size < 8 && (name == "Cas64" || name == "Casint64")) return NULL; Runtime::Function code; @@ -12047,9 +12045,9 @@ Call_expression::intrinsify(Gogo* gogo, code = Runtime::ATOMIC_COMPARE_EXCHANGE_4; else if (name == "Cas64") code = Runtime::ATOMIC_COMPARE_EXCHANGE_8; - else if (name == "$Casint32") + else if (name == "Casint32") code = Runtime::ATOMIC_COMPARE_EXCHANGE_4; - else if (name == "$Casint64") + else if (name == "Casint64") code = Runtime::ATOMIC_COMPARE_EXCHANGE_8; else if (name == "Casuintptr") code = (ptr_size == 8 @@ -12077,7 +12075,7 @@ Call_expression::intrinsify(Gogo* gogo, } if ((name == "Xadd" || name == "Xadd64" || name == "Xaddint64" - || name == "Xadduintptr" || name == "$Xaddint32") + || name == "Xadduintptr" || name == "Xaddint32") && this->args_ != NULL && this->args_->size() == 2) { if (int_size < 8 && (name == "Xadd64" || name == "Xaddint64")) @@ -12095,7 +12093,7 @@ Call_expression::intrinsify(Gogo* gogo, code = Runtime::ATOMIC_ADD_FETCH_8; res_type = uint64_type; } - else if (name == "$Xaddint32") + else if (name == "Xaddint32") { code = Runtime::ATOMIC_ADD_FETCH_4; res_type = int32_type; diff --git a/libgo/go/runtime/internal/atomic/atomic.c b/libgo/go/runtime/internal/atomic/atomic.c index 569e56e..b5a0940 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 62e30d1..e7544ba 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