;;; TOOL: run-interp
;;; ARGS*: --enable-threads
(module
  (memory 1 1 shared)

  ;; i32

  (func (export "i32.atomic.rmw8.cmpxchg_u-true-result") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const 1000000 i32.const 1 i32.atomic.rmw8.cmpxchg_u)
  (func (export "i32.atomic.rmw8.cmpxchg_u-true-memory") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const 1000000 i32.const 1 i32.atomic.rmw8.cmpxchg_u drop
    i32.const 0 i32.load8_u)

  (func (export "i32.atomic.rmw8.cmpxchg_u-false-result") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const     123 i32.const 1       i32.atomic.rmw8.cmpxchg_u)
  (func (export "i32.atomic.rmw8.cmpxchg_u-false-memory") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const     123 i32.const 1       i32.atomic.rmw8.cmpxchg_u drop
    i32.const 0 i32.load8_u)


  (func (export "i32.atomic.rmw16.cmpxchg_u-true-result") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const 1000000 i32.const 1 i32.atomic.rmw16.cmpxchg_u)
  (func (export "i32.atomic.rmw16.cmpxchg_u-true-memory") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const 1000000 i32.const 1 i32.atomic.rmw16.cmpxchg_u drop
    i32.const 0 i32.load16_u)

  (func (export "i32.atomic.rmw16.cmpxchg_u-false-result") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const     123 i32.const 1       i32.atomic.rmw16.cmpxchg_u)
  (func (export "i32.atomic.rmw16.cmpxchg_u-false-memory") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const     123 i32.const 1       i32.atomic.rmw16.cmpxchg_u drop
    i32.const 0 i32.load16_u)


  (func (export "i32.atomic.rmw.cmpxchg-true-result") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const 1000000 i32.const 1 i32.atomic.rmw.cmpxchg)
  (func (export "i32.atomic.rmw.cmpxchg-true-memory") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const 1000000 i32.const 1 i32.atomic.rmw.cmpxchg drop
    i32.const 0 i32.load)

  (func (export "i32.atomic.rmw.cmpxchg-false-result") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const     123 i32.const 1       i32.atomic.rmw.cmpxchg)

  (func (export "i32.atomic.rmw.cmpxchg-false-memory") (result i32)
    i32.const 0 i32.const 1000000 i32.store
    i32.const 0 i32.const     123 i32.const 1       i32.atomic.rmw.cmpxchg drop
    i32.const 0 i32.load)



  ;; i64

  (func (export "i64.atomic.rmw8.cmpxchg_u-true-result") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const 10000000000 i64.const 1 i64.atomic.rmw8.cmpxchg_u)
  (func (export "i64.atomic.rmw8.cmpxchg_u-true-memory") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const 10000000000 i64.const 1 i64.atomic.rmw8.cmpxchg_u drop
    i32.const 0 i64.load8_u)

  (func (export "i64.atomic.rmw8.cmpxchg_u-false-result") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const         123 i64.const 1 i64.atomic.rmw8.cmpxchg_u)
  (func (export "i64.atomic.rmw8.cmpxchg_u-false-memory") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const         123 i64.const 1 i64.atomic.rmw8.cmpxchg_u drop
    i32.const 0 i64.load8_u)


  (func (export "i64.atomic.rmw16.cmpxchg_u-true-result") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const 10000000000 i64.const 1 i64.atomic.rmw16.cmpxchg_u)
  (func (export "i64.atomic.rmw16.cmpxchg_u-true-memory") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const 10000000000 i64.const 1 i64.atomic.rmw16.cmpxchg_u drop
    i32.const 0 i64.load16_u)

  (func (export "i64.atomic.rmw16.cmpxchg_u-false-result") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const         123 i64.const 1 i64.atomic.rmw16.cmpxchg_u)
  (func (export "i64.atomic.rmw16.cmpxchg_u-false-memory") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const         123 i64.const 1 i64.atomic.rmw16.cmpxchg_u drop
    i32.const 0 i64.load16_u)


  (func (export "i64.atomic.rmw32.cmpxchg_u-true-result") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const 10000000000 i64.const 1 i64.atomic.rmw32.cmpxchg_u)
  (func (export "i64.atomic.rmw32.cmpxchg_u-true-memory") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const 10000000000 i64.const 1 i64.atomic.rmw32.cmpxchg_u drop
    i32.const 0 i64.load32_u)

  (func (export "i64.atomic.rmw32.cmpxchg_u-false-result") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const         123 i64.const 1 i64.atomic.rmw32.cmpxchg_u)
  (func (export "i64.atomic.rmw32.cmpxchg_u-false-memory") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const         123 i64.const 1 i64.atomic.rmw32.cmpxchg_u drop
    i32.const 0 i64.load32_u)


  (func (export "i64.atomic.rmw.cmpxchg-true-result") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const 10000000000 i64.const 1 i64.atomic.rmw.cmpxchg)
  (func (export "i64.atomic.rmw.cmpxchg-true-memory") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const 10000000000 i64.const 1 i64.atomic.rmw.cmpxchg drop
    i32.const 0 i64.load)

  (func (export "i64.atomic.rmw.cmpxchg-false-result") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const         123 i64.const 1 i64.atomic.rmw.cmpxchg)
  (func (export "i64.atomic.rmw.cmpxchg-false-memory") (result i64)
    i32.const 0 i64.const 10000000000 i64.store
    i32.const 0 i64.const         123 i64.const 1 i64.atomic.rmw.cmpxchg drop
    i32.const 0 i64.load)


  ;; Test bad alignment

  (func (export "bad_align-i32.atomic.rmw16.cmpxchg_u")
    i32.const 1 i32.const 0 i32.const 0 i32.atomic.rmw16.cmpxchg_u drop)
  (func (export "bad_align-i32.atomic.rmw.cmpxchg")
    i32.const 2 i32.const 0 i32.const 0 i32.atomic.rmw.cmpxchg drop)

  (func (export "bad_align-i64.atomic.rmw16.cmpxchg_u")
    i32.const 1 i64.const 0 i64.const 0 i64.atomic.rmw16.cmpxchg_u drop)
  (func (export "bad_align-i64.atomic.rmw32.cmpxchg_u")
    i32.const 2 i64.const 0 i64.const 0 i64.atomic.rmw32.cmpxchg_u drop)
  (func (export "bad_align-i64.atomic.rmw.cmpxchg")
    i32.const 4 i64.const 0 i64.const 0 i64.atomic.rmw.cmpxchg drop)

)
(;; STDOUT ;;;
i32.atomic.rmw8.cmpxchg_u-true-result() => i32:64
i32.atomic.rmw8.cmpxchg_u-true-memory() => i32:1
i32.atomic.rmw8.cmpxchg_u-false-result() => i32:64
i32.atomic.rmw8.cmpxchg_u-false-memory() => i32:64
i32.atomic.rmw16.cmpxchg_u-true-result() => i32:16960
i32.atomic.rmw16.cmpxchg_u-true-memory() => i32:1
i32.atomic.rmw16.cmpxchg_u-false-result() => i32:16960
i32.atomic.rmw16.cmpxchg_u-false-memory() => i32:16960
i32.atomic.rmw.cmpxchg-true-result() => i32:1000000
i32.atomic.rmw.cmpxchg-true-memory() => i32:1
i32.atomic.rmw.cmpxchg-false-result() => i32:1000000
i32.atomic.rmw.cmpxchg-false-memory() => i32:1000000
i64.atomic.rmw8.cmpxchg_u-true-result() => i64:0
i64.atomic.rmw8.cmpxchg_u-true-memory() => i64:1
i64.atomic.rmw8.cmpxchg_u-false-result() => i64:0
i64.atomic.rmw8.cmpxchg_u-false-memory() => i64:0
i64.atomic.rmw16.cmpxchg_u-true-result() => i64:58368
i64.atomic.rmw16.cmpxchg_u-true-memory() => i64:1
i64.atomic.rmw16.cmpxchg_u-false-result() => i64:58368
i64.atomic.rmw16.cmpxchg_u-false-memory() => i64:58368
i64.atomic.rmw32.cmpxchg_u-true-result() => i64:1410065408
i64.atomic.rmw32.cmpxchg_u-true-memory() => i64:1
i64.atomic.rmw32.cmpxchg_u-false-result() => i64:1410065408
i64.atomic.rmw32.cmpxchg_u-false-memory() => i64:1410065408
i64.atomic.rmw.cmpxchg-true-result() => i64:10000000000
i64.atomic.rmw.cmpxchg-true-memory() => i64:1
i64.atomic.rmw.cmpxchg-false-result() => i64:10000000000
i64.atomic.rmw.cmpxchg-false-memory() => i64:10000000000
bad_align-i32.atomic.rmw16.cmpxchg_u() => error: invalid atomic access at 1+0
bad_align-i32.atomic.rmw.cmpxchg() => error: invalid atomic access at 2+0
bad_align-i64.atomic.rmw16.cmpxchg_u() => error: invalid atomic access at 1+0
bad_align-i64.atomic.rmw32.cmpxchg_u() => error: invalid atomic access at 2+0
bad_align-i64.atomic.rmw.cmpxchg() => error: invalid atomic access at 4+0
;;; STDOUT ;;)
