atomic.S 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. .text
  2. .globl ainc /* int32_t ainc(int32_t *); */
  3. ainc:
  4. li a1, 1
  5. amoadd.w.aq a0, a1, 0(a0)
  6. ret
  7. .globl adec /* int32_t adec(int32_t *); */
  8. adec:
  9. li a1, -1
  10. amoadd.w.aq a0, a1, 0(a0)
  11. ret
  12. /* This works fine either way as we are little endian. */
  13. /* boy we have a lot of names for this. I don't know how *that* happened. */
  14. .globl _tas32 /* int _tas32(int *); */
  15. _tas32:
  16. .globl tas32 /* int _tas32(int *); */
  17. tas32:
  18. .globl _tas /* int _tas(int *); */
  19. _tas:
  20. li a1, 1
  21. amoswap.w.aq a0, a1, 0(a0)
  22. ret
  23. .globl aswap /* int aswap(int *, int); */
  24. aswap:
  25. amoswap.w.aq a0, a1, 0(a0)
  26. ret
  27. .globl cas32
  28. // int cas32(void* %rdi, uint32_t %esi, uint32_t %edx);
  29. // a0 holds address of memory location
  30. // a1 holds expected value
  31. // a2 holds desired value
  32. // v0 return value, 0 if successful, !0 otherwise
  33. cas32:
  34. lr.w x16, (a0) // Load original value
  35. li x16, 1 # Preset return to fail
  36. bne x17, a1, return # Doesn’t match, so fail
  37. sc.w x16, a2, (a0) # Try to update
  38. return: jr ra
  39. .globl mfence
  40. mfence:
  41. fence
  42. ret