wa-lang.org/wazero@v1.0.2/internal/integration_test/spectest/v1/testdata/memory.wast (about) 1 ;; Test memory section structure 2 3 (module (memory 0 0)) 4 (module (memory 0 1)) 5 (module (memory 1 256)) 6 (module (memory 0 65536)) 7 8 (assert_invalid (module (memory 0) (memory 0)) "multiple memories") 9 (assert_invalid (module (memory (import "spectest" "memory") 0) (memory 0)) "multiple memories") 10 11 (module (memory (data)) (func (export "memsize") (result i32) (memory.size))) 12 (assert_return (invoke "memsize") (i32.const 0)) 13 (module (memory (data "")) (func (export "memsize") (result i32) (memory.size))) 14 (assert_return (invoke "memsize") (i32.const 0)) 15 (module (memory (data "x")) (func (export "memsize") (result i32) (memory.size))) 16 (assert_return (invoke "memsize") (i32.const 1)) 17 18 (assert_invalid (module (data (i32.const 0))) "unknown memory") 19 (assert_invalid (module (data (i32.const 0) "")) "unknown memory") 20 (assert_invalid (module (data (i32.const 0) "x")) "unknown memory") 21 22 (assert_invalid 23 (module (func (drop (f32.load (i32.const 0))))) 24 "unknown memory" 25 ) 26 (assert_invalid 27 (module (func (f32.store (i32.const 0) (f32.const 0)))) 28 "unknown memory" 29 ) 30 (assert_invalid 31 (module (func (drop (i32.load8_s (i32.const 0))))) 32 "unknown memory" 33 ) 34 (assert_invalid 35 (module (func (i32.store8 (i32.const 0) (i32.const 0)))) 36 "unknown memory" 37 ) 38 (assert_invalid 39 (module (func (drop (memory.size)))) 40 "unknown memory" 41 ) 42 (assert_invalid 43 (module (func (drop (memory.grow (i32.const 0))))) 44 "unknown memory" 45 ) 46 47 48 (assert_invalid 49 (module (memory 1 0)) 50 "size minimum must not be greater than maximum" 51 ) 52 (assert_invalid 53 (module (memory 65537)) 54 "memory size must be at most 65536 pages (4GiB)" 55 ) 56 (assert_invalid 57 (module (memory 2147483648)) 58 "memory size must be at most 65536 pages (4GiB)" 59 ) 60 (assert_invalid 61 (module (memory 4294967295)) 62 "memory size must be at most 65536 pages (4GiB)" 63 ) 64 (assert_invalid 65 (module (memory 0 65537)) 66 "memory size must be at most 65536 pages (4GiB)" 67 ) 68 (assert_invalid 69 (module (memory 0 2147483648)) 70 "memory size must be at most 65536 pages (4GiB)" 71 ) 72 (assert_invalid 73 (module (memory 0 4294967295)) 74 "memory size must be at most 65536 pages (4GiB)" 75 ) 76 77 (module 78 (memory 1) 79 (data (i32.const 0) "ABC\a7D") (data (i32.const 20) "WASM") 80 81 ;; Data section 82 (func (export "data") (result i32) 83 (i32.and 84 (i32.and 85 (i32.and 86 (i32.eq (i32.load8_u (i32.const 0)) (i32.const 65)) 87 (i32.eq (i32.load8_u (i32.const 3)) (i32.const 167)) 88 ) 89 (i32.and 90 (i32.eq (i32.load8_u (i32.const 6)) (i32.const 0)) 91 (i32.eq (i32.load8_u (i32.const 19)) (i32.const 0)) 92 ) 93 ) 94 (i32.and 95 (i32.and 96 (i32.eq (i32.load8_u (i32.const 20)) (i32.const 87)) 97 (i32.eq (i32.load8_u (i32.const 23)) (i32.const 77)) 98 ) 99 (i32.and 100 (i32.eq (i32.load8_u (i32.const 24)) (i32.const 0)) 101 (i32.eq (i32.load8_u (i32.const 1023)) (i32.const 0)) 102 ) 103 ) 104 ) 105 ) 106 107 ;; Memory cast 108 (func (export "cast") (result f64) 109 (i64.store (i32.const 8) (i64.const -12345)) 110 (if 111 (f64.eq 112 (f64.load (i32.const 8)) 113 (f64.reinterpret_i64 (i64.const -12345)) 114 ) 115 (then (return (f64.const 0))) 116 ) 117 (i64.store align=1 (i32.const 9) (i64.const 0)) 118 (i32.store16 align=1 (i32.const 15) (i32.const 16453)) 119 (f64.load align=1 (i32.const 9)) 120 ) 121 122 ;; Sign and zero extending memory loads 123 (func (export "i32_load8_s") (param $i i32) (result i32) 124 (i32.store8 (i32.const 8) (local.get $i)) 125 (i32.load8_s (i32.const 8)) 126 ) 127 (func (export "i32_load8_u") (param $i i32) (result i32) 128 (i32.store8 (i32.const 8) (local.get $i)) 129 (i32.load8_u (i32.const 8)) 130 ) 131 (func (export "i32_load16_s") (param $i i32) (result i32) 132 (i32.store16 (i32.const 8) (local.get $i)) 133 (i32.load16_s (i32.const 8)) 134 ) 135 (func (export "i32_load16_u") (param $i i32) (result i32) 136 (i32.store16 (i32.const 8) (local.get $i)) 137 (i32.load16_u (i32.const 8)) 138 ) 139 (func (export "i64_load8_s") (param $i i64) (result i64) 140 (i64.store8 (i32.const 8) (local.get $i)) 141 (i64.load8_s (i32.const 8)) 142 ) 143 (func (export "i64_load8_u") (param $i i64) (result i64) 144 (i64.store8 (i32.const 8) (local.get $i)) 145 (i64.load8_u (i32.const 8)) 146 ) 147 (func (export "i64_load16_s") (param $i i64) (result i64) 148 (i64.store16 (i32.const 8) (local.get $i)) 149 (i64.load16_s (i32.const 8)) 150 ) 151 (func (export "i64_load16_u") (param $i i64) (result i64) 152 (i64.store16 (i32.const 8) (local.get $i)) 153 (i64.load16_u (i32.const 8)) 154 ) 155 (func (export "i64_load32_s") (param $i i64) (result i64) 156 (i64.store32 (i32.const 8) (local.get $i)) 157 (i64.load32_s (i32.const 8)) 158 ) 159 (func (export "i64_load32_u") (param $i i64) (result i64) 160 (i64.store32 (i32.const 8) (local.get $i)) 161 (i64.load32_u (i32.const 8)) 162 ) 163 ) 164 165 (assert_return (invoke "data") (i32.const 1)) 166 (assert_return (invoke "cast") (f64.const 42.0)) 167 168 (assert_return (invoke "i32_load8_s" (i32.const -1)) (i32.const -1)) 169 (assert_return (invoke "i32_load8_u" (i32.const -1)) (i32.const 255)) 170 (assert_return (invoke "i32_load16_s" (i32.const -1)) (i32.const -1)) 171 (assert_return (invoke "i32_load16_u" (i32.const -1)) (i32.const 65535)) 172 173 (assert_return (invoke "i32_load8_s" (i32.const 100)) (i32.const 100)) 174 (assert_return (invoke "i32_load8_u" (i32.const 200)) (i32.const 200)) 175 (assert_return (invoke "i32_load16_s" (i32.const 20000)) (i32.const 20000)) 176 (assert_return (invoke "i32_load16_u" (i32.const 40000)) (i32.const 40000)) 177 178 (assert_return (invoke "i32_load8_s" (i32.const 0xfedc6543)) (i32.const 0x43)) 179 (assert_return (invoke "i32_load8_s" (i32.const 0x3456cdef)) (i32.const 0xffffffef)) 180 (assert_return (invoke "i32_load8_u" (i32.const 0xfedc6543)) (i32.const 0x43)) 181 (assert_return (invoke "i32_load8_u" (i32.const 0x3456cdef)) (i32.const 0xef)) 182 (assert_return (invoke "i32_load16_s" (i32.const 0xfedc6543)) (i32.const 0x6543)) 183 (assert_return (invoke "i32_load16_s" (i32.const 0x3456cdef)) (i32.const 0xffffcdef)) 184 (assert_return (invoke "i32_load16_u" (i32.const 0xfedc6543)) (i32.const 0x6543)) 185 (assert_return (invoke "i32_load16_u" (i32.const 0x3456cdef)) (i32.const 0xcdef)) 186 187 (assert_return (invoke "i64_load8_s" (i64.const -1)) (i64.const -1)) 188 (assert_return (invoke "i64_load8_u" (i64.const -1)) (i64.const 255)) 189 (assert_return (invoke "i64_load16_s" (i64.const -1)) (i64.const -1)) 190 (assert_return (invoke "i64_load16_u" (i64.const -1)) (i64.const 65535)) 191 (assert_return (invoke "i64_load32_s" (i64.const -1)) (i64.const -1)) 192 (assert_return (invoke "i64_load32_u" (i64.const -1)) (i64.const 4294967295)) 193 194 (assert_return (invoke "i64_load8_s" (i64.const 100)) (i64.const 100)) 195 (assert_return (invoke "i64_load8_u" (i64.const 200)) (i64.const 200)) 196 (assert_return (invoke "i64_load16_s" (i64.const 20000)) (i64.const 20000)) 197 (assert_return (invoke "i64_load16_u" (i64.const 40000)) (i64.const 40000)) 198 (assert_return (invoke "i64_load32_s" (i64.const 20000)) (i64.const 20000)) 199 (assert_return (invoke "i64_load32_u" (i64.const 40000)) (i64.const 40000)) 200 201 (assert_return (invoke "i64_load8_s" (i64.const 0xfedcba9856346543)) (i64.const 0x43)) 202 (assert_return (invoke "i64_load8_s" (i64.const 0x3456436598bacdef)) (i64.const 0xffffffffffffffef)) 203 (assert_return (invoke "i64_load8_u" (i64.const 0xfedcba9856346543)) (i64.const 0x43)) 204 (assert_return (invoke "i64_load8_u" (i64.const 0x3456436598bacdef)) (i64.const 0xef)) 205 (assert_return (invoke "i64_load16_s" (i64.const 0xfedcba9856346543)) (i64.const 0x6543)) 206 (assert_return (invoke "i64_load16_s" (i64.const 0x3456436598bacdef)) (i64.const 0xffffffffffffcdef)) 207 (assert_return (invoke "i64_load16_u" (i64.const 0xfedcba9856346543)) (i64.const 0x6543)) 208 (assert_return (invoke "i64_load16_u" (i64.const 0x3456436598bacdef)) (i64.const 0xcdef)) 209 (assert_return (invoke "i64_load32_s" (i64.const 0xfedcba9856346543)) (i64.const 0x56346543)) 210 (assert_return (invoke "i64_load32_s" (i64.const 0x3456436598bacdef)) (i64.const 0xffffffff98bacdef)) 211 (assert_return (invoke "i64_load32_u" (i64.const 0xfedcba9856346543)) (i64.const 0x56346543)) 212 (assert_return (invoke "i64_load32_u" (i64.const 0x3456436598bacdef)) (i64.const 0x98bacdef))