atomic.S 1.1 KB

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