libc_mips64le.go 950 B

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