github.com/q45/go@v0.0.0-20151101211701-a4fb8c13db3f/src/runtime/atomic_arm64.go (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package runtime
     6  
     7  import "unsafe"
     8  
     9  //go:noescape
    10  func xadd(ptr *uint32, delta int32) uint32
    11  
    12  //go:noescape
    13  func xadd64(ptr *uint64, delta int64) uint64
    14  
    15  //go:noescape
    16  //go:linkname xadduintptr runtime.xadd64
    17  func xadduintptr(ptr *uintptr, delta uintptr) uintptr
    18  
    19  //go:noescape
    20  func xchg(ptr *uint32, new uint32) uint32
    21  
    22  //go:noescape
    23  func xchg64(ptr *uint64, new uint64) uint64
    24  
    25  //go:noescape
    26  func xchguintptr(ptr *uintptr, new uintptr) uintptr
    27  
    28  //go:noescape
    29  func atomicload(ptr *uint32) uint32
    30  
    31  //go:noescape
    32  func atomicload64(ptr *uint64) uint64
    33  
    34  //go:noescape
    35  func atomicloadp(ptr unsafe.Pointer) unsafe.Pointer
    36  
    37  //go:nosplit
    38  func atomicor8(addr *uint8, v uint8) {
    39  	// TODO(dfc) implement this in asm.
    40  	// Align down to 4 bytes and use 32-bit CAS.
    41  	uaddr := uintptr(unsafe.Pointer(addr))
    42  	addr32 := (*uint32)(unsafe.Pointer(uaddr &^ 3))
    43  	word := uint32(v) << ((uaddr & 3) * 8) // little endian
    44  	for {
    45  		old := *addr32
    46  		if cas(addr32, old, old|word) {
    47  			return
    48  		}
    49  	}
    50  }
    51  
    52  //go:nosplit
    53  func atomicand8(addr *uint8, v uint8) {
    54  	// TODO(dfc) implement this in asm.
    55  	// Align down to 4 bytes and use 32-bit CAS.
    56  	uaddr := uintptr(unsafe.Pointer(addr))
    57  	addr32 := (*uint32)(unsafe.Pointer(uaddr &^ 3))
    58  	word := uint32(v) << ((uaddr & 3) * 8)    // little endian
    59  	mask := uint32(0xFF) << ((uaddr & 3) * 8) // little endian
    60  	word |= ^mask
    61  	for {
    62  		old := *addr32
    63  		if cas(addr32, old, old&word) {
    64  			return
    65  		}
    66  	}
    67  }
    68  
    69  //go:noescape
    70  func cas64(ptr *uint64, old, new uint64) bool
    71  
    72  //go:noescape
    73  func atomicstore(ptr *uint32, val uint32)
    74  
    75  //go:noescape
    76  func atomicstore64(ptr *uint64, val uint64)
    77  
    78  // NO go:noescape annotation; see atomic_pointer.go.
    79  func atomicstorep1(ptr unsafe.Pointer, val unsafe.Pointer)