libc_amd64.go 980 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2023 The Libc 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. //go:build !(linux && amd64)
  5. package libc // import "modernc.org/libc"
  6. import (
  7. "fmt"
  8. "unsafe"
  9. )
  10. // Byte loads are atomic on this CPU.
  11. func a_load_8(addr uintptr) uint32 {
  12. return uint32(*(*byte)(unsafe.Pointer(addr)))
  13. }
  14. // int16 loads are atomic on this CPU when properly aligned.
  15. func a_load_16(addr uintptr) uint32 {
  16. if addr&1 != 0 {
  17. panic(fmt.Errorf("unaligned atomic 16 bit access at %#0x", addr))
  18. }
  19. return uint32(*(*uint16)(unsafe.Pointer(addr)))
  20. }
  21. // Byte sores are atomic on this CPU.
  22. func a_store_8(addr uintptr, b byte) {
  23. *(*byte)(unsafe.Pointer(addr)) = b
  24. }
  25. // int16 stores are atomic on this CPU when properly aligned.
  26. func a_store_16(addr uintptr, n uint16) {
  27. if addr&1 != 0 {
  28. panic(fmt.Errorf("unaligned atomic 16 bit access at %#0x", addr))
  29. }
  30. *(*uint16)(unsafe.Pointer(addr)) = n
  31. }