xadd.s 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # mach: bpf
  2. # output: pass\nexit 0 (0x0)\n
  3. ;;; xadd.s
  4. ;;; Tests for BPF atomic exchange-and-add instructions in simulator
  5. ;;;
  6. ;;; The xadd instructions (XADDW, XADDDW) operate on a memory location
  7. ;;; specified in $dst + offset16, atomically adding the value in $src.
  8. ;;;
  9. ;;; In the simulator, there isn't anything else happening. The atomic
  10. ;;; instructions are identical to a non-atomic load/add/store.
  11. .include "testutils.inc"
  12. .text
  13. .global main
  14. .type main, @function
  15. main:
  16. mov %r1, 0x1000
  17. mov %r2, 5
  18. ;; basic xadd w
  19. stw [%r1+0], 10
  20. xaddw [%r1+0], %r2
  21. ldxw %r3, [%r1+0]
  22. fail_ne %r3, 15
  23. ;; basic xadd dw
  24. stdw [%r1+8], 42
  25. xadddw [%r1+8], %r2
  26. ldxdw %r3, [%r1+8]
  27. fail_ne %r3, 47
  28. ;; xadd w negative value
  29. mov %r4, -1
  30. xaddw [%r1+0], %r4
  31. ldxw %r3, [%r1+0]
  32. fail_ne %r3, 14
  33. ;; xadd dw negative val
  34. xadddw [%r1+8], %r4
  35. ldxdw %r3, [%r1+8]
  36. fail_ne %r3, 46
  37. pass