wardite 1.2.2 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -15
  3. data/Rakefile +0 -177
  4. data/benchmark/README.md +10 -36
  5. data/benchmark/call_cost_worker.rb +3 -2
  6. data/benchmark/compare.rb +1 -2
  7. data/benchmark/compare_linear_memory_loads.py +144 -0
  8. data/benchmark/i32_memory.wat +5 -1
  9. data/benchmark/investigate_calls.rb +4 -4
  10. data/benchmark/linear_memory_loads.wat +52 -0
  11. data/benchmark/optimization_worker.rb +3 -2
  12. data/benchmark/patches/adr0017-spinel-signed64.patch +190 -0
  13. data/benchmark/patches/adr0017-wardite-split-load64.patch +70 -0
  14. data/benchmark/results/adr0019-startup.json +1687 -0
  15. data/benchmark/results/adr0020-i64.json +2034 -0
  16. data/benchmark/results/adr0021-optimizer.json +5798 -0
  17. data/benchmark/results/adr0022-lazy-mir.json +3057 -0
  18. data/benchmark/results/crc8-stream-repeat.csv +89 -0
  19. data/benchmark/results/crc8-stream.csv +89 -0
  20. data/benchmark/results/linear-memory-loads-a2aa05227.csv +793 -0
  21. data/benchmark/results/linear-memory-loads-stage-b.csv +353 -0
  22. data/benchmark/results/linear-memory-loads.csv +1057 -0
  23. data/benchmark/results/real-workloads-baseline-2026-11-18.json +1741 -0
  24. data/benchmark/results/spinel-072516af1.csv +149 -0
  25. data/benchmark/results/stack-vm-removal.json +334 -0
  26. data/benchmark/validate_m4.rb +0 -2
  27. data/docs/adr/0017-efflorescence-linear-memory-loads.md +90 -0
  28. data/docs/adr/0018-efflorescence-real-workload-measurement.md +126 -0
  29. data/docs/adr/0019-efflorescence-startup-quick-wins.md +85 -0
  30. data/docs/adr/0020-efflorescence-inline-i64-bit-operations.md +89 -0
  31. data/docs/adr/0021-efflorescence-optimize-real-functions.md +133 -0
  32. data/docs/adr/0022-efflorescence-lazy-function-build.md +111 -0
  33. data/docs/adr/0023-efflorescence-byte-sequences-and-copy-coalescing.md +56 -0
  34. data/docs/efflorescence-ja.md +3 -5
  35. data/docs/efflorescence-linear-memory-loads.md +134 -0
  36. data/docs/efflorescence-m6.md +1 -1
  37. data/docs/efflorescence-mir-generation-performance.md +58 -0
  38. data/docs/efflorescence-mir2-cache.md +7 -0
  39. data/docs/efflorescence-real-workloads.md +312 -0
  40. data/docs/efflorescence-spinel-linear-memory.md +2 -2
  41. data/docs/efflorescence.md +3 -5
  42. data/docs/stack-vm-removal.md +49 -0
  43. data/lib/wardite/cli/cli.rb +24 -24
  44. data/lib/wardite/efflorescence/byte_sequences.rb +80 -0
  45. data/lib/wardite/efflorescence/function_preparer.rb +64 -0
  46. data/lib/wardite/efflorescence/i64_arithmetic.rb +31 -0
  47. data/lib/wardite/efflorescence/inspection.rb +44 -12
  48. data/lib/wardite/efflorescence/ir.rb +33 -10
  49. data/lib/wardite/efflorescence/mir_cache.rb +10 -1
  50. data/lib/wardite/efflorescence/optimizer.rb +151 -42
  51. data/lib/wardite/efflorescence/store_access.rb +17 -0
  52. data/lib/wardite/efflorescence/translation_source.rb +50 -0
  53. data/lib/wardite/efflorescence/translator.rb +135 -19
  54. data/lib/wardite/efflorescence/vm.rb +116 -48
  55. data/lib/wardite/efflorescence.rb +3 -0
  56. data/lib/wardite/load.rb +46 -62
  57. data/lib/wardite/version.rb +1 -1
  58. data/lib/wardite.rb +21 -757
  59. data/scripts/build_spinel_zig.rb +29 -17
  60. data/sig/generated/wardite/cli/cli.rbs +4 -2
  61. data/sig/generated/wardite/efflorescence/byte_sequences.rbs +33 -0
  62. data/sig/generated/wardite/efflorescence/function_preparer.rbs +25 -0
  63. data/sig/generated/wardite/efflorescence/i64_arithmetic.rbs +19 -0
  64. data/sig/generated/wardite/efflorescence/inspection.rbs +8 -0
  65. data/sig/generated/wardite/efflorescence/ir.rbs +18 -2
  66. data/sig/generated/wardite/efflorescence/optimizer.rbs +41 -3
  67. data/sig/generated/wardite/efflorescence/store_access.rbs +5 -0
  68. data/sig/generated/wardite/efflorescence/translation_source.rbs +34 -0
  69. data/sig/generated/wardite/efflorescence/translator.rbs +28 -1
  70. data/sig/generated/wardite/efflorescence/vm.rbs +19 -9
  71. data/sig/generated/wardite/load.rbs +18 -18
  72. data/sig/generated/wardite.rbs +4 -155
  73. metadata +33 -17
  74. data/benchmark/compare_engines.rb +0 -119
  75. data/benchmark/engine_phases.rb +0 -30
  76. data/lib/wardite/alu_f32.generated.rb +0 -261
  77. data/lib/wardite/alu_f64.generated.rb +0 -261
  78. data/lib/wardite/alu_i32.generated.rb +0 -510
  79. data/lib/wardite/alu_i64.generated.rb +0 -572
  80. data/lib/wardite/convert.generated.rb +0 -340
  81. data/scripts/gen_alu.rb +0 -864
  82. data/scripts/gen_conv.rb +0 -86
  83. data/scripts/templates/alu_module.rb.tmpl +0 -20
  84. data/scripts/templates/conv_module.rb.tmpl +0 -20
  85. data/sig/generated/wardite/alu_f32.generated.rbs +0 -12
  86. data/sig/generated/wardite/alu_f64.generated.rbs +0 -12
  87. data/sig/generated/wardite/alu_i32.generated.rbs +0 -12
  88. data/sig/generated/wardite/alu_i64.generated.rbs +0 -12
  89. data/sig/generated/wardite/convert.generated.rbs +0 -12
@@ -1,572 +0,0 @@
1
- # rbs_inline: enabled
2
- require_relative "value"
3
-
4
- module Wardite
5
- module Evaluator
6
- # @rbs runtime: Runtime
7
- # @rbs frame: Frame
8
- # @rbs code: Symbol
9
- # @rbs operand: Array[operandItem]
10
- # @rbs return: bool?
11
- def self.i64_eval_insn(runtime, frame, code, operand)
12
- case code
13
-
14
- when :i64_load
15
- _align = operand[0] # TODO: alignment support?
16
- offset = operand[1]
17
- raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
18
-
19
- addr = runtime.stack.pop
20
- if !addr.is_a?(I32)
21
- raise EvalError, "maybe stack too short"
22
- end
23
-
24
- at = addr.value + offset
25
- data_end = at + I64.new.memsize / 8
26
- memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
27
- buf = if RUBY_ENGINE == "spinel"
28
- memory.read_bytes(at, data_end - at)
29
- else
30
- memory.data[at...data_end]
31
- end
32
- if !buf
33
- raise EvalError, "invalid memory range"
34
- end
35
- runtime.stack.push(I64.from_bytes(buf))
36
-
37
-
38
- when :i64_load8_s
39
- _align = operand[0] # TODO: alignment support?
40
- offset = operand[1]
41
- raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
42
-
43
- addr = runtime.stack.pop
44
- if !addr.is_a?(I32)
45
- raise EvalError, "maybe stack too short"
46
- end
47
-
48
- at = addr.value + offset
49
- data_end = at + 1
50
- memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
51
- buf = if RUBY_ENGINE == "spinel"
52
- memory.read_bytes(at, data_end - at)
53
- else
54
- memory.data[at...data_end]
55
- end
56
- if !buf
57
- raise EvalError, "invalid memory range"
58
- end
59
- runtime.stack.push(I64.from_bytes(buf, size: 8, signed: true))
60
-
61
-
62
- when :i64_load8_u
63
- _align = operand[0] # TODO: alignment support?
64
- offset = operand[1]
65
- raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
66
-
67
- addr = runtime.stack.pop
68
- if !addr.is_a?(I32)
69
- raise EvalError, "maybe stack too short"
70
- end
71
-
72
- at = addr.value + offset
73
- data_end = at + 1
74
- memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
75
- buf = if RUBY_ENGINE == "spinel"
76
- memory.read_bytes(at, data_end - at)
77
- else
78
- memory.data[at...data_end]
79
- end
80
- if !buf
81
- raise EvalError, "invalid memory range"
82
- end
83
- runtime.stack.push(I64.from_bytes(buf, size: 8, signed: false))
84
-
85
-
86
- when :i64_load16_s
87
- _align = operand[0] # TODO: alignment support?
88
- offset = operand[1]
89
- raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
90
-
91
- addr = runtime.stack.pop
92
- if !addr.is_a?(I32)
93
- raise EvalError, "maybe stack too short"
94
- end
95
-
96
- at = addr.value + offset
97
- data_end = at + 2
98
- memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
99
- buf = if RUBY_ENGINE == "spinel"
100
- memory.read_bytes(at, data_end - at)
101
- else
102
- memory.data[at...data_end]
103
- end
104
- if !buf
105
- raise EvalError, "invalid memory range"
106
- end
107
- runtime.stack.push(I64.from_bytes(buf, size: 16, signed: true))
108
-
109
-
110
- when :i64_load16_u
111
- _align = operand[0] # TODO: alignment support?
112
- offset = operand[1]
113
- raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
114
-
115
- addr = runtime.stack.pop
116
- if !addr.is_a?(I32)
117
- raise EvalError, "maybe stack too short"
118
- end
119
-
120
- at = addr.value + offset
121
- data_end = at + 2
122
- memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
123
- buf = if RUBY_ENGINE == "spinel"
124
- memory.read_bytes(at, data_end - at)
125
- else
126
- memory.data[at...data_end]
127
- end
128
- if !buf
129
- raise EvalError, "invalid memory range"
130
- end
131
- runtime.stack.push(I64.from_bytes(buf, size: 16, signed: false))
132
-
133
-
134
- when :i64_load32_s
135
- _align = operand[0] # TODO: alignment support?
136
- offset = operand[1]
137
- raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
138
-
139
- addr = runtime.stack.pop
140
- if !addr.is_a?(I32)
141
- raise EvalError, "maybe stack too short"
142
- end
143
-
144
- at = addr.value + offset
145
- data_end = at + 4
146
- memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
147
- buf = if RUBY_ENGINE == "spinel"
148
- memory.read_bytes(at, data_end - at)
149
- else
150
- memory.data[at...data_end]
151
- end
152
- if !buf
153
- raise EvalError, "invalid memory range"
154
- end
155
- runtime.stack.push(I64.from_bytes(buf, size: 32, signed: true))
156
-
157
-
158
- when :i64_load32_u
159
- _align = operand[0] # TODO: alignment support?
160
- offset = operand[1]
161
- raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
162
-
163
- addr = runtime.stack.pop
164
- if !addr.is_a?(I32)
165
- raise EvalError, "maybe stack too short"
166
- end
167
-
168
- at = addr.value + offset
169
- data_end = at + 4
170
- memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
171
- buf = if RUBY_ENGINE == "spinel"
172
- memory.read_bytes(at, data_end - at)
173
- else
174
- memory.data[at...data_end]
175
- end
176
- if !buf
177
- raise EvalError, "invalid memory range"
178
- end
179
- runtime.stack.push(I64.from_bytes(buf, size: 32, signed: false))
180
-
181
-
182
- when :i64_store
183
- _align = operand[0] # TODO: alignment support?
184
- offset = operand[1]
185
- raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
186
-
187
- value = runtime.stack.pop
188
- addr = runtime.stack.pop
189
- if !value.is_a?(I64) || !addr.is_a?(I32)
190
- raise EvalError, "maybe stack too short"
191
- end
192
-
193
- at = addr.value + offset
194
- data_end = at + value.packed.size
195
- memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
196
- if RUBY_ENGINE == "spinel"
197
- memory.write_bytes(at, value.packed)
198
- else
199
- memory.data[at...data_end] = value.packed
200
- end
201
-
202
-
203
- when :i64_store8
204
- _align = operand[0] # TODO: alignment support?
205
- offset = operand[1]
206
- raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
207
-
208
- value = runtime.stack.pop
209
- addr = runtime.stack.pop
210
- if !value.is_a?(I64) || !addr.is_a?(I32)
211
- raise EvalError, "maybe stack too short"
212
- end
213
-
214
- at = addr.value + offset
215
- data_end = at + 1
216
- memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
217
- if RUBY_ENGINE == "spinel"
218
- memory.write_bytes(at, value.packed(size: 8))
219
- else
220
- memory.data[at...data_end] = value.packed(size: 8)
221
- end
222
-
223
-
224
- when :i64_store16
225
- _align = operand[0] # TODO: alignment support?
226
- offset = operand[1]
227
- raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
228
-
229
- value = runtime.stack.pop
230
- addr = runtime.stack.pop
231
- if !value.is_a?(I64) || !addr.is_a?(I32)
232
- raise EvalError, "maybe stack too short"
233
- end
234
-
235
- at = addr.value + offset
236
- data_end = at + 2
237
- memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
238
- if RUBY_ENGINE == "spinel"
239
- memory.write_bytes(at, value.packed(size: 16))
240
- else
241
- memory.data[at...data_end] = value.packed(size: 16)
242
- end
243
-
244
-
245
- when :i64_store32
246
- _align = operand[0] # TODO: alignment support?
247
- offset = operand[1]
248
- raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
249
-
250
- value = runtime.stack.pop
251
- addr = runtime.stack.pop
252
- if !value.is_a?(I64) || !addr.is_a?(I32)
253
- raise EvalError, "maybe stack too short"
254
- end
255
-
256
- at = addr.value + offset
257
- data_end = at + 4
258
- memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
259
- if RUBY_ENGINE == "spinel"
260
- memory.write_bytes(at, value.packed(size: 32))
261
- else
262
- memory.data[at...data_end] = value.packed(size: 32)
263
- end
264
-
265
-
266
- when :i64_const
267
- const = operand[0]
268
- if !const.is_a?(Integer)
269
- raise EvalError, "invalid type of operand"
270
- end
271
- runtime.stack.push(I64(const))
272
-
273
-
274
- when :i64_eqz
275
- target = runtime.stack.pop
276
- if !target.is_a?(I64)
277
- raise EvalError, "maybe empty or invalid stack"
278
- end
279
- value = target.value.zero? ? 1 : 0
280
- runtime.stack.push(I32(value))
281
-
282
-
283
- when :i64_eq
284
- right, left = runtime.stack.pop, runtime.stack.pop
285
- if !right.is_a?(I64) || !left.is_a?(I64)
286
- raise EvalError, "maybe empty or invalid stack"
287
- end
288
- value = (left.value == right.value) ? 1 : 0
289
- runtime.stack.push(I32(value))
290
-
291
-
292
- when :i64_ne
293
- right, left = runtime.stack.pop, runtime.stack.pop
294
- if !right.is_a?(I64) || !left.is_a?(I64)
295
- raise EvalError, "maybe empty or invalid stack"
296
- end
297
- value = (left.value != right.value) ? 1 : 0
298
- runtime.stack.push(I32(value))
299
-
300
-
301
- when :i64_lts
302
- right, left = runtime.stack.pop, runtime.stack.pop
303
- if !right.is_a?(I64) || !left.is_a?(I64)
304
- raise EvalError, "maybe empty or invalid stack"
305
- end
306
- value = (left.value_s < right.value_s) ? 1 : 0
307
- runtime.stack.push(I32(value))
308
-
309
-
310
- when :i64_ltu
311
- right, left = runtime.stack.pop, runtime.stack.pop
312
- if !right.is_a?(I64) || !left.is_a?(I64)
313
- raise EvalError, "maybe empty or invalid stack"
314
- end
315
- value = (left.value < right.value) ? 1 : 0
316
- runtime.stack.push(I32(value))
317
-
318
-
319
- when :i64_gts
320
- right, left = runtime.stack.pop, runtime.stack.pop
321
- if !right.is_a?(I64) || !left.is_a?(I64)
322
- raise EvalError, "maybe empty or invalid stack"
323
- end
324
- value = (left.value_s > right.value_s) ? 1 : 0
325
- runtime.stack.push(I32(value))
326
-
327
-
328
- when :i64_gtu
329
- right, left = runtime.stack.pop, runtime.stack.pop
330
- if !right.is_a?(I64) || !left.is_a?(I64)
331
- raise EvalError, "maybe empty or invalid stack"
332
- end
333
- value = (left.value > right.value) ? 1 : 0
334
- runtime.stack.push(I32(value))
335
-
336
-
337
- when :i64_les
338
- right, left = runtime.stack.pop, runtime.stack.pop
339
- if !right.is_a?(I64) || !left.is_a?(I64)
340
- raise EvalError, "maybe empty or invalid stack"
341
- end
342
- value = (left.value_s <= right.value_s) ? 1 : 0
343
- runtime.stack.push(I32(value))
344
-
345
-
346
- when :i64_leu
347
- right, left = runtime.stack.pop, runtime.stack.pop
348
- if !right.is_a?(I64) || !left.is_a?(I64)
349
- raise EvalError, "maybe empty or invalid stack"
350
- end
351
- value = (left.value <= right.value) ? 1 : 0
352
- runtime.stack.push(I32(value))
353
-
354
-
355
- when :i64_ges
356
- right, left = runtime.stack.pop, runtime.stack.pop
357
- if !right.is_a?(I64) || !left.is_a?(I64)
358
- raise EvalError, "maybe empty or invalid stack"
359
- end
360
- value = (left.value_s >= right.value_s) ? 1 : 0
361
- runtime.stack.push(I32(value))
362
-
363
-
364
- when :i64_geu
365
- right, left = runtime.stack.pop, runtime.stack.pop
366
- if !right.is_a?(I64) || !left.is_a?(I64)
367
- raise EvalError, "maybe empty or invalid stack"
368
- end
369
- value = (left.value >= right.value) ? 1 : 0
370
- runtime.stack.push(I32(value))
371
-
372
-
373
- when :i64_clz
374
- target = runtime.stack.pop
375
- if !target.is_a?(I64)
376
- raise EvalError, "maybe empty or invalid stack"
377
- end
378
- start = target.memsize - 1
379
- count = 0
380
- while start > -1
381
- if (target.value >> start).zero?
382
- count += 1
383
- start -= 1
384
- else
385
- break
386
- end
387
- end
388
- runtime.stack.push(I64(count))
389
-
390
-
391
- when :i64_ctz
392
- target = runtime.stack.pop
393
- if !target.is_a?(I64)
394
- raise EvalError, "maybe empty or invalid stack"
395
- end
396
- finish = target.memsize
397
- count = 0
398
- while count < finish
399
- if target.value[count].zero?
400
- count += 1
401
- else
402
- break
403
- end
404
- end
405
- runtime.stack.push(I64(count))
406
-
407
-
408
- when :i64_popcnt
409
- target = runtime.stack.pop
410
- if !target.is_a?(I64)
411
- raise EvalError, "maybe empty or invalid stack"
412
- end
413
- digits = target.memsize
414
- count = 0
415
- digits.times do |i|
416
- if target.value[i].nonzero?
417
- count += 1
418
- end
419
- end
420
- runtime.stack.push(I64(count))
421
-
422
-
423
- when :i64_add
424
- right, left = runtime.stack.pop, runtime.stack.pop
425
- if !right.is_a?(I64) || !left.is_a?(I64)
426
- raise EvalError, "maybe empty or invalid stack"
427
- end
428
- runtime.stack.push(left.add(right))
429
-
430
-
431
- when :i64_sub
432
- right, left = runtime.stack.pop, runtime.stack.pop
433
- if !right.is_a?(I64) || !left.is_a?(I64)
434
- raise EvalError, "maybe empty or invalid stack"
435
- end
436
- runtime.stack.push(I64(left.value - right.value))
437
-
438
-
439
- when :i64_mul
440
- right, left = runtime.stack.pop, runtime.stack.pop
441
- if !right.is_a?(I64) || !left.is_a?(I64)
442
- raise EvalError, "maybe empty or invalid stack"
443
- end
444
- runtime.stack.push(left.multiply(right))
445
-
446
-
447
- when :i64_div_s
448
- right, left = runtime.stack.pop, runtime.stack.pop
449
- if !right.is_a?(I64) || !left.is_a?(I64)
450
- raise EvalError, "maybe empty or invalid stack"
451
- end
452
- dividend = left.value_s
453
- divisor = right.value_s
454
- signed_min = -(1 << (left.memsize - 2)) * 2
455
- if dividend == signed_min && divisor == -1
456
- raise IntegerOverflow, "integer overflow"
457
- end
458
- iresult = dividend / divisor
459
- # Ruby rounds integer division down; Wasm truncates toward zero.
460
- if (dividend < 0) != (divisor < 0) && dividend % divisor != 0
461
- iresult += 1
462
- end
463
- runtime.stack.push(I64(iresult))
464
-
465
-
466
- when :i64_div_u
467
- right, left = runtime.stack.pop, runtime.stack.pop
468
- if !right.is_a?(I64) || !left.is_a?(I64)
469
- raise EvalError, "maybe empty or invalid stack"
470
- end
471
- runtime.stack.push(I64(left.value / right.value))
472
-
473
-
474
- when :i64_rem_s
475
- right, left = runtime.stack.pop, runtime.stack.pop
476
- if !right.is_a?(I64) || !left.is_a?(I64)
477
- raise EvalError, "maybe empty or invalid stack"
478
- end
479
- result = left.value_s % right.value_s
480
- if result > 0 && left.value_s < 0
481
- result = result - right.value_s
482
- elsif result < 0 && left.value_s > 0
483
- result = result - right.value_s
484
- end
485
- runtime.stack.push(I64(result))
486
-
487
-
488
- when :i64_rem_u
489
- right, left = runtime.stack.pop, runtime.stack.pop
490
- if !right.is_a?(I64) || !left.is_a?(I64)
491
- raise EvalError, "maybe empty or invalid stack"
492
- end
493
- runtime.stack.push(I64(left.value % right.value))
494
-
495
-
496
- when :i64_and
497
- right, left = runtime.stack.pop, runtime.stack.pop
498
- if !right.is_a?(I64) || !left.is_a?(I64)
499
- raise EvalError, "maybe empty or invalid stack"
500
- end
501
- runtime.stack.push(I64(left.value & right.value))
502
-
503
-
504
- when :i64_or
505
- right, left = runtime.stack.pop, runtime.stack.pop
506
- if !right.is_a?(I64) || !left.is_a?(I64)
507
- raise EvalError, "maybe empty or invalid stack"
508
- end
509
- runtime.stack.push(I64(left.value | right.value))
510
-
511
-
512
- when :i64_xor
513
- right, left = runtime.stack.pop, runtime.stack.pop
514
- if !right.is_a?(I64) || !left.is_a?(I64)
515
- raise EvalError, "maybe empty or invalid stack"
516
- end
517
- runtime.stack.push(I64(left.value ^ right.value))
518
-
519
-
520
- when :i64_shl
521
- right, left = runtime.stack.pop, runtime.stack.pop
522
- if !right.is_a?(I64) || !left.is_a?(I64)
523
- raise EvalError, "maybe empty or invalid stack"
524
- end
525
- runtime.stack.push(left.shift_left(right.value % 64))
526
-
527
-
528
- when :i64_shr_s
529
- right, left = runtime.stack.pop, runtime.stack.pop
530
- if !right.is_a?(I64) || !left.is_a?(I64)
531
- raise EvalError, "maybe empty or invalid stack"
532
- end
533
- value = left.value_s >> (right.value % right.memsize)
534
- runtime.stack.push(I64(value))
535
-
536
-
537
- when :i64_shr_u
538
- right, left = runtime.stack.pop, runtime.stack.pop
539
- if !right.is_a?(I64) || !left.is_a?(I64)
540
- raise EvalError, "maybe empty or invalid stack"
541
- end
542
- value = left.value >> (right.value % right.memsize)
543
- runtime.stack.push(I64(value))
544
-
545
-
546
- when :i64_rotl
547
- right, left = runtime.stack.pop, runtime.stack.pop
548
- if !right.is_a?(I64) || !left.is_a?(I64)
549
- raise EvalError, "maybe empty or invalid stack"
550
- end
551
- k = right.value % 64
552
- value = left.shift_left(k).value | (left.value >> (64 - k))
553
- runtime.stack.push(I64(value))
554
-
555
-
556
- when :i64_rotr
557
- right, left = runtime.stack.pop, runtime.stack.pop
558
- if !right.is_a?(I64) || !left.is_a?(I64)
559
- raise EvalError, "maybe empty or invalid stack"
560
- end
561
- k = right.value % 64
562
- value = (left.value >> k) | left.shift_left((64 - k) % 64).value
563
- runtime.stack.push(I64(value))
564
-
565
-
566
- else
567
- return
568
- end
569
- return true
570
- end
571
- end
572
- end