-
Notifications
You must be signed in to change notification settings - Fork 57
/
endianness.wast
217 lines (175 loc) · 9.85 KB
/
endianness.wast
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
(module
(memory 1)
;; Stores an i16 value in little-endian-format
(func $i16_store_little (param $address i32) (param $value i32)
(i32.store8 (local.get $address) (local.get $value))
(i32.store8 (i32.add (local.get $address) (i32.const 1)) (i32.shr_u (local.get $value) (i32.const 8)))
)
;; Stores an i32 value in little-endian format
(func $i32_store_little (param $address i32) (param $value i32)
(call $i16_store_little (local.get $address) (local.get $value))
(call $i16_store_little (i32.add (local.get $address) (i32.const 2)) (i32.shr_u (local.get $value) (i32.const 16)))
)
;; Stores an i64 value in little-endian format
(func $i64_store_little (param $address i32) (param $value i64)
(call $i32_store_little (local.get $address) (i32.wrap_i64 (local.get $value)))
(call $i32_store_little (i32.add (local.get $address) (i32.const 4)) (i32.wrap_i64 (i64.shr_u (local.get $value) (i64.const 32))))
)
;; Loads an i16 value in little-endian format
(func $i16_load_little (param $address i32) (result i32)
(i32.or
(i32.load8_u (local.get $address))
(i32.shl (i32.load8_u (i32.add (local.get $address) (i32.const 1))) (i32.const 8))
)
)
;; Loads an i32 value in little-endian format
(func $i32_load_little (param $address i32) (result i32)
(i32.or
(call $i16_load_little (local.get $address))
(i32.shl (call $i16_load_little (i32.add (local.get $address) (i32.const 2))) (i32.const 16))
)
)
;; Loads an i64 value in little-endian format
(func $i64_load_little (param $address i32) (result i64)
(i64.or
(i64.extend_i32_u (call $i32_load_little (local.get $address)))
(i64.shl (i64.extend_i32_u (call $i32_load_little (i32.add (local.get $address) (i32.const 4)))) (i64.const 32))
)
)
(func (export "i32_load16_s") (param $value i32) (result i32)
(call $i16_store_little (i32.const 0) (local.get $value))
(i32.load16_s (i32.const 0))
)
(func (export "i32_load16_u") (param $value i32) (result i32)
(call $i16_store_little (i32.const 0) (local.get $value))
(i32.load16_u (i32.const 0))
)
(func (export "i32_load") (param $value i32) (result i32)
(call $i32_store_little (i32.const 0) (local.get $value))
(i32.load (i32.const 0))
)
(func (export "i64_load16_s") (param $value i64) (result i64)
(call $i16_store_little (i32.const 0) (i32.wrap_i64 (local.get $value)))
(i64.load16_s (i32.const 0))
)
(func (export "i64_load16_u") (param $value i64) (result i64)
(call $i16_store_little (i32.const 0) (i32.wrap_i64 (local.get $value)))
(i64.load16_u (i32.const 0))
)
(func (export "i64_load32_s") (param $value i64) (result i64)
(call $i32_store_little (i32.const 0) (i32.wrap_i64 (local.get $value)))
(i64.load32_s (i32.const 0))
)
(func (export "i64_load32_u") (param $value i64) (result i64)
(call $i32_store_little (i32.const 0) (i32.wrap_i64 (local.get $value)))
(i64.load32_u (i32.const 0))
)
(func (export "i64_load") (param $value i64) (result i64)
(call $i64_store_little (i32.const 0) (local.get $value))
(i64.load (i32.const 0))
)
(func (export "f32_load") (param $value f32) (result f32)
(call $i32_store_little (i32.const 0) (i32.reinterpret_f32 (local.get $value)))
(f32.load (i32.const 0))
)
(func (export "f64_load") (param $value f64) (result f64)
(call $i64_store_little (i32.const 0) (i64.reinterpret_f64 (local.get $value)))
(f64.load (i32.const 0))
)
(func (export "i32_store16") (param $value i32) (result i32)
(i32.store16 (i32.const 0) (local.get $value))
(call $i16_load_little (i32.const 0))
)
(func (export "i32_store") (param $value i32) (result i32)
(i32.store (i32.const 0) (local.get $value))
(call $i32_load_little (i32.const 0))
)
(func (export "i64_store16") (param $value i64) (result i64)
(i64.store16 (i32.const 0) (local.get $value))
(i64.extend_i32_u (call $i16_load_little (i32.const 0)))
)
(func (export "i64_store32") (param $value i64) (result i64)
(i64.store32 (i32.const 0) (local.get $value))
(i64.extend_i32_u (call $i32_load_little (i32.const 0)))
)
(func (export "i64_store") (param $value i64) (result i64)
(i64.store (i32.const 0) (local.get $value))
(call $i64_load_little (i32.const 0))
)
(func (export "f32_store") (param $value f32) (result f32)
(f32.store (i32.const 0) (local.get $value))
(f32.reinterpret_i32 (call $i32_load_little (i32.const 0)))
)
(func (export "f64_store") (param $value f64) (result f64)
(f64.store (i32.const 0) (local.get $value))
(f64.reinterpret_i64 (call $i64_load_little (i32.const 0)))
)
)
(assert_return (invoke "i32_load16_s" (i32.const -1)) (i32.const -1))
(assert_return (invoke "i32_load16_s" (i32.const -4242)) (i32.const -4242))
(assert_return (invoke "i32_load16_s" (i32.const 42)) (i32.const 42))
(assert_return (invoke "i32_load16_s" (i32.const 0x3210)) (i32.const 0x3210))
(assert_return (invoke "i32_load16_u" (i32.const -1)) (i32.const 0xFFFF))
(assert_return (invoke "i32_load16_u" (i32.const -4242)) (i32.const 61294))
(assert_return (invoke "i32_load16_u" (i32.const 42)) (i32.const 42))
(assert_return (invoke "i32_load16_u" (i32.const 0xCAFE)) (i32.const 0xCAFE))
(assert_return (invoke "i32_load" (i32.const -1)) (i32.const -1))
(assert_return (invoke "i32_load" (i32.const -42424242)) (i32.const -42424242))
(assert_return (invoke "i32_load" (i32.const 42424242)) (i32.const 42424242))
(assert_return (invoke "i32_load" (i32.const 0xABAD1DEA)) (i32.const 0xABAD1DEA))
(assert_return (invoke "i64_load16_s" (i64.const -1)) (i64.const -1))
(assert_return (invoke "i64_load16_s" (i64.const -4242)) (i64.const -4242))
(assert_return (invoke "i64_load16_s" (i64.const 42)) (i64.const 42))
(assert_return (invoke "i64_load16_s" (i64.const 0x3210)) (i64.const 0x3210))
(assert_return (invoke "i64_load16_u" (i64.const -1)) (i64.const 0xFFFF))
(assert_return (invoke "i64_load16_u" (i64.const -4242)) (i64.const 61294))
(assert_return (invoke "i64_load16_u" (i64.const 42)) (i64.const 42))
(assert_return (invoke "i64_load16_u" (i64.const 0xCAFE)) (i64.const 0xCAFE))
(assert_return (invoke "i64_load32_s" (i64.const -1)) (i64.const -1))
(assert_return (invoke "i64_load32_s" (i64.const -42424242)) (i64.const -42424242))
(assert_return (invoke "i64_load32_s" (i64.const 42424242)) (i64.const 42424242))
(assert_return (invoke "i64_load32_s" (i64.const 0x12345678)) (i64.const 0x12345678))
(assert_return (invoke "i64_load32_u" (i64.const -1)) (i64.const 0xFFFFFFFF))
(assert_return (invoke "i64_load32_u" (i64.const -42424242)) (i64.const 4252543054))
(assert_return (invoke "i64_load32_u" (i64.const 42424242)) (i64.const 42424242))
(assert_return (invoke "i64_load32_u" (i64.const 0xABAD1DEA)) (i64.const 0xABAD1DEA))
(assert_return (invoke "i64_load" (i64.const -1)) (i64.const -1))
(assert_return (invoke "i64_load" (i64.const -42424242)) (i64.const -42424242))
(assert_return (invoke "i64_load" (i64.const 0xABAD1DEA)) (i64.const 0xABAD1DEA))
(assert_return (invoke "i64_load" (i64.const 0xABADCAFEDEAD1DEA)) (i64.const 0xABADCAFEDEAD1DEA))
(assert_return (invoke "f32_load" (f32.const -1)) (f32.const -1))
(assert_return (invoke "f32_load" (f32.const 1234e-5)) (f32.const 1234e-5))
(assert_return (invoke "f32_load" (f32.const 4242.4242)) (f32.const 4242.4242))
(assert_return (invoke "f32_load" (f32.const 0x1.fffffep+127)) (f32.const 0x1.fffffep+127))
(assert_return (invoke "f64_load" (f64.const -1)) (f64.const -1))
(assert_return (invoke "f64_load" (f64.const 123456789e-5)) (f64.const 123456789e-5))
(assert_return (invoke "f64_load" (f64.const 424242.424242)) (f64.const 424242.424242))
(assert_return (invoke "f64_load" (f64.const 0x1.fffffffffffffp+1023)) (f64.const 0x1.fffffffffffffp+1023))
(assert_return (invoke "i32_store16" (i32.const -1)) (i32.const 0xFFFF))
(assert_return (invoke "i32_store16" (i32.const -4242)) (i32.const 61294))
(assert_return (invoke "i32_store16" (i32.const 42)) (i32.const 42))
(assert_return (invoke "i32_store16" (i32.const 0xCAFE)) (i32.const 0xCAFE))
(assert_return (invoke "i32_store" (i32.const -1)) (i32.const -1))
(assert_return (invoke "i32_store" (i32.const -4242)) (i32.const -4242))
(assert_return (invoke "i32_store" (i32.const 42424242)) (i32.const 42424242))
(assert_return (invoke "i32_store" (i32.const 0xDEADCAFE)) (i32.const 0xDEADCAFE))
(assert_return (invoke "i64_store16" (i64.const -1)) (i64.const 0xFFFF))
(assert_return (invoke "i64_store16" (i64.const -4242)) (i64.const 61294))
(assert_return (invoke "i64_store16" (i64.const 42)) (i64.const 42))
(assert_return (invoke "i64_store16" (i64.const 0xCAFE)) (i64.const 0xCAFE))
(assert_return (invoke "i64_store32" (i64.const -1)) (i64.const 0xFFFFFFFF))
(assert_return (invoke "i64_store32" (i64.const -4242)) (i64.const 4294963054))
(assert_return (invoke "i64_store32" (i64.const 42424242)) (i64.const 42424242))
(assert_return (invoke "i64_store32" (i64.const 0xDEADCAFE)) (i64.const 0xDEADCAFE))
(assert_return (invoke "i64_store" (i64.const -1)) (i64.const -1))
(assert_return (invoke "i64_store" (i64.const -42424242)) (i64.const -42424242))
(assert_return (invoke "i64_store" (i64.const 0xABAD1DEA)) (i64.const 0xABAD1DEA))
(assert_return (invoke "i64_store" (i64.const 0xABADCAFEDEAD1DEA)) (i64.const 0xABADCAFEDEAD1DEA))
(assert_return (invoke "f32_store" (f32.const -1)) (f32.const -1))
(assert_return (invoke "f32_store" (f32.const 1234e-5)) (f32.const 1234e-5))
(assert_return (invoke "f32_store" (f32.const 4242.4242)) (f32.const 4242.4242))
(assert_return (invoke "f32_store" (f32.const 0x1.fffffep+127)) (f32.const 0x1.fffffep+127))
(assert_return (invoke "f64_store" (f64.const -1)) (f64.const -1))
(assert_return (invoke "f64_store" (f64.const 123456789e-5)) (f64.const 123456789e-5))
(assert_return (invoke "f64_store" (f64.const 424242.424242)) (f64.const 424242.424242))
(assert_return (invoke "f64_store" (f64.const 0x1.fffffffffffffp+1023)) (f64.const 0x1.fffffffffffffp+1023))