wardite 0.8.2 → 1.0.0
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.
- checksums.yaml +4 -4
- data/LICENSE +191 -0
- data/Makefile +14 -0
- data/README.md +80 -1
- data/Rakefile +5 -0
- data/benchmark/README.md +500 -0
- data/benchmark/build_call_profile.rb +42 -0
- data/benchmark/call_cost_worker.rb +27 -0
- data/benchmark/compare.rb +93 -0
- data/benchmark/compare_call_types.rb +212 -0
- data/benchmark/compare_dispatch.rb +123 -0
- data/benchmark/compare_engines.rb +119 -0
- data/benchmark/compare_optimizations.rb +139 -0
- data/benchmark/engine_phases.rb +30 -0
- data/benchmark/figures/README.md +35 -0
- data/benchmark/figures/plot_spinel_comparison.py +137 -0
- data/benchmark/figures/spinel_new_vm_candlestick.png +0 -0
- data/benchmark/figures/spinel_new_vm_candlestick.svg +7615 -0
- data/benchmark/figures/spinel_new_vm_summary.csv +9 -0
- data/benchmark/figures/spinel_new_vm_summary.json +82 -0
- data/benchmark/float_m5.wat +42 -0
- data/benchmark/i32_call_arities.wat +89 -0
- data/benchmark/i32_calls.wat +174 -0
- data/benchmark/i32_memory.wat +58 -0
- data/benchmark/i32_mix.wat +80 -0
- data/benchmark/i64_m4.wat +55 -0
- data/benchmark/investigate_calls.rb +231 -0
- data/benchmark/investigate_generated_guards.rb +218 -0
- data/benchmark/m3_call_worker.rb +38 -0
- data/benchmark/measure_m1.rb +51 -0
- data/benchmark/measure_m2.rb +55 -0
- data/benchmark/measure_m3_calls.rb +89 -0
- data/benchmark/measure_m4.rb +134 -0
- data/benchmark/measure_m5_boundary.rb +41 -0
- data/benchmark/measure_wasi_write.rb +75 -0
- data/benchmark/optimization_worker.rb +23 -0
- data/benchmark/results/call_arities_exploratory_2026-11-04.json +4320 -0
- data/benchmark/results/call_arities_spinel_2026-11-04.json +1200 -0
- data/benchmark/results/call_cost_spinel_2026-11-04.json +2392 -0
- data/benchmark/results/call_protocol_exploratory_2026-11-04.json +3947 -0
- data/benchmark/results/call_protocol_profile_2026-11-04.json +383 -0
- data/benchmark/results/call_protocol_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/call_protocol_spinel_2026-11-04.json +913 -0
- data/benchmark/results/call_types_ruby_2026-11-04.json +1212 -0
- data/benchmark/results/call_types_spinel_2026-11-04.json +923 -0
- data/benchmark/results/efflorescence-m1-cruby.json +799 -0
- data/benchmark/results/efflorescence-m1-spinel.json +799 -0
- data/benchmark/results/efflorescence-m2-bulk-loop.json +820 -0
- data/benchmark/results/efflorescence-m2-i32-cruby.json +799 -0
- data/benchmark/results/efflorescence-m2-i32-spinel.json +799 -0
- data/benchmark/results/efflorescence-m2-memory.json +408 -0
- data/benchmark/results/generated_guards_exploratory_2026-11-04.json +1225 -0
- data/benchmark/results/generated_guards_profile_2026-11-04.json +592 -0
- data/benchmark/results/generated_guards_spinel_2026-11-04.json +1650 -0
- data/benchmark/results/generated_guards_validation_2026-11-04.json +256 -0
- data/benchmark/results/inlining_engines_2026-11-04.json +241 -0
- data/benchmark/results/inlining_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/inlining_spinel_2026-11-04.json +893 -0
- data/benchmark/results/operand_decode_exploratory_2026-11-04.json +1319 -0
- data/benchmark/results/operand_decode_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/operand_decode_spinel_2026-11-04.json +924 -0
- data/benchmark/results/selective_reset_spinel_2026-11-04.json +454 -0
- data/benchmark/results/selective_reset_spinel_2026-11-04_exploratory.json +2679 -0
- data/benchmark/results/spinel_fetch_root_patch_2026-11-04.json +4523 -0
- data/benchmark/results/while_final_compiler_comparison_2026-11-04.json +324 -0
- data/benchmark/results/while_patched_external_2026-11-04.json +220 -0
- data/benchmark/results/while_user_unpatched_2026-11-04.json +230 -0
- data/benchmark/summarize_call_profile.py +54 -0
- data/benchmark/validate_m1_eh.rb +34 -0
- data/benchmark/validate_m2.rb +119 -0
- data/benchmark/validate_m3.rb +44 -0
- data/benchmark/validate_m4.rb +95 -0
- data/benchmark/validate_m5.rb +108 -0
- data/docs/adr/0001-efflorescence-m1-control-and-eh.md +319 -0
- data/docs/adr/0002-efflorescence-m2-memory-and-globals.md +185 -0
- data/docs/adr/0003-efflorescence-m3-host-and-indirect-calls.md +228 -0
- data/docs/adr/0004-efflorescence-m4-i64.md +202 -0
- data/docs/adr/0005-efflorescence-m5-floating-point.md +127 -0
- data/docs/adr/0006-efflorescence-m6-coverage-parity.md +101 -0
- data/docs/efflorescence-call-arities.md +115 -0
- data/docs/efflorescence-call-investigation.md +155 -0
- data/docs/efflorescence-call-transfer.md +128 -0
- data/docs/efflorescence-call-types.md +102 -0
- data/docs/efflorescence-coverage-ja.md +351 -0
- data/docs/efflorescence-generated-c-guards.md +405 -0
- data/docs/efflorescence-inlining.md +165 -0
- data/docs/efflorescence-ja.md +155 -0
- data/docs/efflorescence-m1.md +160 -0
- data/docs/efflorescence-m2.md +233 -0
- data/docs/efflorescence-m3.md +131 -0
- data/docs/efflorescence-m4.md +88 -0
- data/docs/efflorescence-m5.md +82 -0
- data/docs/efflorescence-m6.md +95 -0
- data/docs/efflorescence-operand-decoding.md +105 -0
- data/docs/efflorescence-phase2-ja.md +225 -0
- data/docs/efflorescence-phase2.md +240 -0
- data/docs/efflorescence-register-initialization.md +75 -0
- data/docs/efflorescence.md +144 -0
- data/docs/spinel-string-aset-inplace-proposal.md +200 -0
- data/examples/load_perf.rb +24 -0
- data/lib/wardite/alu_f32.generated.rb +13 -10
- data/lib/wardite/alu_f64.generated.rb +13 -10
- data/lib/wardite/alu_i32.generated.rb +38 -31
- data/lib/wardite/alu_i64.generated.rb +48 -48
- data/lib/wardite/cli/cli.rb +73 -22
- data/lib/wardite/const.rb +1 -0
- data/lib/wardite/convert.generated.rb +7 -5
- data/lib/wardite/efflorescence/float_arithmetic.rb +216 -0
- data/lib/wardite/efflorescence/i64_arithmetic.rb +257 -0
- data/lib/wardite/efflorescence/inspection.rb +165 -0
- data/lib/wardite/efflorescence/ir.rb +1151 -0
- data/lib/wardite/efflorescence/optimizer.rb +580 -0
- data/lib/wardite/efflorescence/register_validation.rb +290 -0
- data/lib/wardite/efflorescence/store_access.rb +271 -0
- data/lib/wardite/efflorescence/translator.rb +859 -0
- data/lib/wardite/efflorescence/vm.rb +1006 -0
- data/lib/wardite/efflorescence/wasi.rb +108 -0
- data/lib/wardite/efflorescence.rb +11 -0
- data/lib/wardite/errors.rb +20 -0
- data/lib/wardite/float_bits.rb +46 -0
- data/lib/wardite/instruction.rb +460 -69
- data/lib/wardite/leb128.rb +35 -17
- data/lib/wardite/load.rb +260 -159
- data/lib/wardite/revisitor.rb +12 -4
- data/lib/wardite/value.rb +169 -175
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite/wasi/consts.rb +1 -0
- data/lib/wardite/wasm_module.rb +6 -3
- data/lib/wardite.rb +220 -105
- data/rbs_collection.lock.yaml +36 -96
- data/scripts/gen_alu.rb +90 -34
- data/scripts/templates/alu_module.rb.tmpl +7 -5
- data/scripts/templates/conv_module.rb.tmpl +7 -5
- data/sig/generated/wardite/alu_f32.generated.rbs +4 -3
- data/sig/generated/wardite/alu_f64.generated.rbs +4 -3
- data/sig/generated/wardite/alu_i32.generated.rbs +4 -3
- data/sig/generated/wardite/alu_i64.generated.rbs +4 -3
- data/sig/generated/wardite/cli/cli.rbs +13 -6
- data/sig/generated/wardite/const.rbs +2 -0
- data/sig/generated/wardite/convert.generated.rbs +4 -3
- data/sig/generated/wardite/efflorescence/float_arithmetic.rbs +65 -0
- data/sig/generated/wardite/efflorescence/i64_arithmetic.rbs +99 -0
- data/sig/generated/wardite/efflorescence/inspection.rbs +64 -0
- data/sig/generated/wardite/efflorescence/ir.rbs +881 -0
- data/sig/generated/wardite/efflorescence/optimizer.rbs +189 -0
- data/sig/generated/wardite/efflorescence/register_validation.rbs +76 -0
- data/sig/generated/wardite/efflorescence/store_access.rbs +134 -0
- data/sig/generated/wardite/efflorescence/translator.rbs +214 -0
- data/sig/generated/wardite/efflorescence/vm.rbs +179 -0
- data/sig/generated/wardite/efflorescence/wasi.rbs +47 -0
- data/sig/generated/wardite/errors.rbs +12 -0
- data/sig/generated/wardite/float_bits.rbs +30 -0
- data/sig/generated/wardite/instruction.rbs +35 -10
- data/sig/generated/wardite/leb128.rbs +3 -1
- data/sig/generated/wardite/load.rbs +38 -13
- data/sig/generated/wardite/value.rbs +70 -11
- data/sig/generated/wardite/wasi/consts.rbs +2 -0
- data/sig/generated/wardite.rbs +55 -18
- data/sig/vernier.rbs +3 -0
- data/spinel/README.md +30 -0
- data/spinel/bin/wardite.rb +6 -0
- data/spinel/spin.toml +7 -0
- metadata +128 -3
|
@@ -0,0 +1,1006 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
module Wardite
|
|
5
|
+
module Efflorescence
|
|
6
|
+
class VM
|
|
7
|
+
attr_reader :instance #: Wardite::Instance
|
|
8
|
+
attr_reader :ir #: Wardite::Efflorescence::IR
|
|
9
|
+
attr_reader :semantic_ir #: Wardite::Efflorescence::IR
|
|
10
|
+
attr_reader :optimized_ir #: Wardite::Efflorescence::IR
|
|
11
|
+
attr_reader :metrics #: Wardite::Efflorescence::Metrics
|
|
12
|
+
|
|
13
|
+
# @rbs instance: Wardite::Instance
|
|
14
|
+
# @rbs disabled_optimizations: Array[Symbol]
|
|
15
|
+
# @rbs profile: bool
|
|
16
|
+
def initialize(instance, disabled_optimizations: [], profile: false)
|
|
17
|
+
@instance = instance
|
|
18
|
+
@store_access = StoreAccess.new(instance.store)
|
|
19
|
+
@function_indices = {} #: Hash[Integer, Integer]
|
|
20
|
+
# Retain the original objects so IDs stay valid even if a host edits
|
|
21
|
+
# Store.funcs. Spinel cannot use an identity Hash for these objects.
|
|
22
|
+
@indirect_functions = [] #: Array[Wardite::WasmFunction | Wardite::ExternalFunction]
|
|
23
|
+
unless instance.store.tables.empty?
|
|
24
|
+
@indirect_functions = instance.store.funcs.dup
|
|
25
|
+
@indirect_functions.each_with_index { |function, index| @function_indices[function.object_id] = index }
|
|
26
|
+
end
|
|
27
|
+
configuration = Configuration.new(disabled_optimizations)
|
|
28
|
+
@reuse_frames = configuration.enabled?(:frames)
|
|
29
|
+
@profiling = profile
|
|
30
|
+
@metrics = Metrics.new
|
|
31
|
+
@semantic_ir = Translator.new(instance).translate
|
|
32
|
+
@optimized_ir = Optimizer.new(configuration).optimize(@semantic_ir)
|
|
33
|
+
@optimized_ir.functions.each { |function| RegisterValidation.new.validate(function, @optimized_ir, tags: instance.tags) }
|
|
34
|
+
@ir = profile ? Instrumentation.new.instrument(@optimized_ir) : @optimized_ir
|
|
35
|
+
Lowerer.new.compile(@ir)
|
|
36
|
+
start = instance.start_section
|
|
37
|
+
if start
|
|
38
|
+
entry = @ir.entry_at(start.func_index)
|
|
39
|
+
unless entry.parameter_types.empty? && entry.result_types.empty?
|
|
40
|
+
raise Wardite::LoadError, "start function must have no parameters or results"
|
|
41
|
+
end
|
|
42
|
+
execute(entry, [])
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @rbs name: String|Symbol
|
|
47
|
+
# @rbs return: bool
|
|
48
|
+
def callable?(name)
|
|
49
|
+
export = @instance.export_section.exports[name.to_s]
|
|
50
|
+
!!export && export.kind == 0
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Compatible with Runtime.call: boxing happens once, at the Ruby boundary.
|
|
54
|
+
# @rbs name: String|Symbol
|
|
55
|
+
# @rbs arguments: Array[Object]
|
|
56
|
+
# @rbs return: Wardite::wasmValue?
|
|
57
|
+
def call(name, arguments)
|
|
58
|
+
entry = export_entry(name)
|
|
59
|
+
result = execute_public(entry, arguments)
|
|
60
|
+
return nil if result.nil?
|
|
61
|
+
box_result(entry.result_types.fetch(0), result)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Integers retain their register representation. Floats cross as Ruby Float.
|
|
65
|
+
# @rbs name: String|Symbol
|
|
66
|
+
# @rbs arguments: Array[Object]
|
|
67
|
+
# @rbs return: (Integer | Float)?
|
|
68
|
+
def call_unboxed(name, arguments)
|
|
69
|
+
entry = export_entry(name)
|
|
70
|
+
result = execute_public(entry, arguments)
|
|
71
|
+
return nil if result.nil?
|
|
72
|
+
unbox_result(entry.result_types.fetch(0), result)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# @rbs name: Symbol
|
|
76
|
+
# @rbs *arguments: Object
|
|
77
|
+
# @rbs return: Wardite::wasmValue?
|
|
78
|
+
def method_missing(name, *arguments)
|
|
79
|
+
callable?(name) ? call(name, arguments) : super
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# @rbs name: String|Symbol
|
|
83
|
+
# @rbs include_private: bool
|
|
84
|
+
# @rbs return: bool
|
|
85
|
+
def respond_to_missing?(name, include_private = false)
|
|
86
|
+
callable?(name) || super
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# @rbs return: String
|
|
90
|
+
def dump_mir
|
|
91
|
+
inspection = Inspection.new
|
|
92
|
+
"Semantic MIR (#{inspection.statistics(@semantic_ir)})\n#{inspection.disassemble(@semantic_ir)}\n" \
|
|
93
|
+
"Optimized MIR (#{inspection.statistics(@optimized_ir)})\n#{inspection.disassemble(@optimized_ir)}"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
|
|
98
|
+
# @rbs name: String|Symbol
|
|
99
|
+
# @rbs return: Wardite::Efflorescence::FunctionEntry
|
|
100
|
+
def export_entry(name)
|
|
101
|
+
export = @instance.export_section.exports[name.to_s]
|
|
102
|
+
raise ::NoMethodError, "function #{name} not found" unless export
|
|
103
|
+
raise ::NoMethodError, "#{name} is not a function" unless export.kind == 0
|
|
104
|
+
@ir.entry_at(export.index)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# @rbs entry: Wardite::Efflorescence::FunctionEntry
|
|
108
|
+
# @rbs arguments: Array[Object]
|
|
109
|
+
# @rbs return: Integer?
|
|
110
|
+
def execute_public(entry, arguments)
|
|
111
|
+
unless arguments.size == entry.parameter_types.size
|
|
112
|
+
raise Wardite::ArgumentError, "unmatch arg size"
|
|
113
|
+
end
|
|
114
|
+
values = [] #: Array[Integer]
|
|
115
|
+
arguments.each_with_index do |value, i|
|
|
116
|
+
type = entry.parameter_types.fetch(i)
|
|
117
|
+
if FloatBits.float_type?(type)
|
|
118
|
+
bits = float_argument(type, value)
|
|
119
|
+
raise Wardite::ArgumentError, "type mismatch: #{type}(#{value})" if bits.nil?
|
|
120
|
+
values << bits
|
|
121
|
+
elsif type == :i64 && value.is_a?(Wardite::I64)
|
|
122
|
+
values << value.value_s
|
|
123
|
+
elsif value.is_a?(Integer)
|
|
124
|
+
values << (type == :i64 ? I64Arithmetic.normalize(value) : value & 0xffffffff)
|
|
125
|
+
else
|
|
126
|
+
raise Wardite::ArgumentError, "type mismatch: #{type}(#{value})"
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
execute(entry, values)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# @rbs type: Symbol
|
|
133
|
+
# @rbs value: Object?
|
|
134
|
+
# @rbs return: Integer?
|
|
135
|
+
def float_argument(type, value)
|
|
136
|
+
return FloatBits.from_float(type, value) if value.is_a?(Float)
|
|
137
|
+
if type == :f32 && value.is_a?(Wardite::F32)
|
|
138
|
+
value.raw_bits
|
|
139
|
+
elsif type == :f64 && value.is_a?(Wardite::F64)
|
|
140
|
+
value.raw_bits
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# @rbs type: Symbol
|
|
145
|
+
# @rbs bits: Integer
|
|
146
|
+
# @rbs return: Integer | Float
|
|
147
|
+
def unbox_result(type, bits)
|
|
148
|
+
FloatBits.float_type?(type) ? FloatBits.to_float(type, bits) : bits
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# @rbs type: Symbol
|
|
152
|
+
# @rbs bits: Integer
|
|
153
|
+
# @rbs return: Wardite::wasmValue
|
|
154
|
+
def box_result(type, bits)
|
|
155
|
+
case type
|
|
156
|
+
when :i64 then Wardite::I64(bits)
|
|
157
|
+
when :f32 then Wardite::F32.from_bits(bits)
|
|
158
|
+
when :f64 then Wardite::F64.from_bits(bits)
|
|
159
|
+
else Wardite::I32.new(bits)
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# A concrete return type breaks the inference cycle between the current
|
|
164
|
+
# frame and the array it is restored from after every internal RETURN.
|
|
165
|
+
# @rbs return: Wardite::Efflorescence::Frame
|
|
166
|
+
def current_frame(frames)
|
|
167
|
+
frames.last || raise(Wardite::EvalError, "missing MIR caller")
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# @rbs value: Integer
|
|
171
|
+
# @rbs return: Integer
|
|
172
|
+
def signed(value)
|
|
173
|
+
value >= 0x80000000 ? value - 0x100000000 : value
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Cold/new ALU paths stay outside the established hot-loop operations.
|
|
177
|
+
# @rbs opcode: Integer
|
|
178
|
+
# @rbs left: Integer
|
|
179
|
+
# @rbs right: Integer
|
|
180
|
+
# @rbs return: Integer
|
|
181
|
+
def calculate(opcode, left, right)
|
|
182
|
+
case opcode
|
|
183
|
+
when Opcode::I32_EQ then left == right ? 1 : 0
|
|
184
|
+
when Opcode::I32_NE then left != right ? 1 : 0
|
|
185
|
+
when Opcode::I32_LTS then signed(left) < signed(right) ? 1 : 0
|
|
186
|
+
when Opcode::I32_LTU then left < right ? 1 : 0
|
|
187
|
+
when Opcode::I32_GTS then signed(left) > signed(right) ? 1 : 0
|
|
188
|
+
when Opcode::I32_GTU then left > right ? 1 : 0
|
|
189
|
+
when Opcode::I32_LES then signed(left) <= signed(right) ? 1 : 0
|
|
190
|
+
when Opcode::I32_LEU then left <= right ? 1 : 0
|
|
191
|
+
when Opcode::I32_GES then signed(left) >= signed(right) ? 1 : 0
|
|
192
|
+
when Opcode::I32_GEU then left >= right ? 1 : 0
|
|
193
|
+
when Opcode::I32_CLZ
|
|
194
|
+
count = 32
|
|
195
|
+
while left != 0
|
|
196
|
+
left >>= 1
|
|
197
|
+
count -= 1
|
|
198
|
+
end
|
|
199
|
+
count
|
|
200
|
+
when Opcode::I32_CTZ
|
|
201
|
+
return 32 if left == 0
|
|
202
|
+
count = 0
|
|
203
|
+
while (left & 1) == 0
|
|
204
|
+
left >>= 1
|
|
205
|
+
count += 1
|
|
206
|
+
end
|
|
207
|
+
count
|
|
208
|
+
when Opcode::I32_POPCNT
|
|
209
|
+
count = 0
|
|
210
|
+
while left != 0
|
|
211
|
+
left &= left - 1
|
|
212
|
+
count += 1
|
|
213
|
+
end
|
|
214
|
+
count
|
|
215
|
+
when Opcode::I32_DIV_S, Opcode::I32_REM_S
|
|
216
|
+
raise Wardite::EvalError, "integer divide by zero" if right == 0
|
|
217
|
+
a, b = signed(left), signed(right)
|
|
218
|
+
if opcode == Opcode::I32_DIV_S && a == -2147483648 && b == -1
|
|
219
|
+
raise Wardite::IntegerOverflow, "integer division overflow"
|
|
220
|
+
end
|
|
221
|
+
quotient = a.abs / b.abs
|
|
222
|
+
quotient = -quotient if (a < 0) != (b < 0)
|
|
223
|
+
(opcode == Opcode::I32_DIV_S ? quotient : a - quotient * b) & 0xffffffff
|
|
224
|
+
when Opcode::I32_DIV_U, Opcode::I32_REM_U
|
|
225
|
+
raise Wardite::EvalError, "integer divide by zero" if right == 0
|
|
226
|
+
opcode == Opcode::I32_DIV_U ? left / right : left % right
|
|
227
|
+
when Opcode::I32_AND then left & right
|
|
228
|
+
when Opcode::I32_OR then left | right
|
|
229
|
+
when Opcode::I32_SHR_S then (signed(left) >> (right & 31)) & 0xffffffff
|
|
230
|
+
when Opcode::I32_ROTL, Opcode::I32_ROTR
|
|
231
|
+
shift = right & 31
|
|
232
|
+
shift = (32 - shift) & 31 if opcode == Opcode::I32_ROTR
|
|
233
|
+
((left << shift) | (left >> ((32 - shift) & 31))) & 0xffffffff
|
|
234
|
+
when Opcode::I32_EXTEND8_S
|
|
235
|
+
value = left & 255
|
|
236
|
+
(value >= 128 ? value - 256 : value) & 0xffffffff
|
|
237
|
+
when Opcode::I32_EXTEND16_S
|
|
238
|
+
value = left & 65535
|
|
239
|
+
(value >= 32768 ? value - 65536 : value) & 0xffffffff
|
|
240
|
+
else
|
|
241
|
+
raise Wardite::EvalError, "invalid i32 opcode"
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
# The pending value owns its payload before any frame is released. No
|
|
246
|
+
# Ruby raise/rescue is used to unwind the explicit Wasm call stack.
|
|
247
|
+
# @rbs value: Wardite::Efflorescence::ExceptionValue
|
|
248
|
+
# @rbs frames: Array[Wardite::Efflorescence::Frame]
|
|
249
|
+
# @rbs pools: Array[Wardite::Efflorescence::FramePool]
|
|
250
|
+
# @rbs return: Wardite::Efflorescence::Frame
|
|
251
|
+
def propagate(value, frames, pools)
|
|
252
|
+
until frames.empty?
|
|
253
|
+
frame = current_frame(frames)
|
|
254
|
+
until frame.handlers.empty?
|
|
255
|
+
id = frame.handlers.pop || raise(Wardite::EvalError, "missing handler")
|
|
256
|
+
descriptors = frame.function.flat_handlers
|
|
257
|
+
descriptors.fetch(id).clauses.each do |clause|
|
|
258
|
+
if clause.tag_index < 0 || @instance.tags.fetch(clause.tag_index).equal?(value.tag)
|
|
259
|
+
frame.trim_handlers(clause.handler_depth)
|
|
260
|
+
clause.payload_registers.each_with_index do |register, i|
|
|
261
|
+
frame.registers[register] = value.payload_bits.fetch(i)
|
|
262
|
+
end
|
|
263
|
+
frame.exception_registers[clause.reference_register] = value if clause.reference_register >= 0
|
|
264
|
+
frame.pc = Integer(clause.target_pc)
|
|
265
|
+
return frame
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
frames.pop
|
|
270
|
+
pool_at(pools, frame.pool_index).release(frame)
|
|
271
|
+
end
|
|
272
|
+
raise Wardite::UncaughtWasmException, value
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# @rbs frame: Wardite::Efflorescence::Frame
|
|
276
|
+
# @rbs id: Integer
|
|
277
|
+
# @rbs return: Wardite::Efflorescence::ExceptionValue
|
|
278
|
+
def exception_at(frame, id)
|
|
279
|
+
site = frame.function.throw_sites.fetch(id)
|
|
280
|
+
payload = site.payload_registers.map { |register| frame.registers[register] }
|
|
281
|
+
ExceptionValue.new(@instance.tags.fetch(site.tag_index), payload)
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
# @rbs pools: Array[Wardite::Efflorescence::FramePool]
|
|
285
|
+
# @rbs index: Integer
|
|
286
|
+
# @rbs return: Wardite::Efflorescence::FramePool
|
|
287
|
+
def pool_at(pools, index)
|
|
288
|
+
pools[index] || raise(Wardite::EvalError, "missing MIR frame pool")
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
# @rbs host_index: Integer
|
|
292
|
+
# @rbs arguments: Array[Integer]
|
|
293
|
+
# @rbs metrics: Wardite::Efflorescence::Metrics
|
|
294
|
+
# @rbs return: Integer?
|
|
295
|
+
# @rbs sources: Array[Integer]?
|
|
296
|
+
def invoke_host(host_index, arguments, metrics, sources = nil)
|
|
297
|
+
host = @ir.hosts[host_index] || raise(Wardite::EvalError, "missing MIR host function")
|
|
298
|
+
metrics.host_calls += 1 if @profiling
|
|
299
|
+
if RUBY_ENGINE != "spinel"
|
|
300
|
+
wasi = host.unboxed_wasi
|
|
301
|
+
return wasi.call(@instance.store, arguments, sources) if wasi
|
|
302
|
+
end
|
|
303
|
+
return invoke_typed_host(host, arguments, sources) if host.typed_abi
|
|
304
|
+
|
|
305
|
+
boxed = [] #: Array[Wardite::wasmValue]
|
|
306
|
+
if sources
|
|
307
|
+
sources.each { |register| boxed << Wardite::I32.new(arguments[register]) }
|
|
308
|
+
else
|
|
309
|
+
arguments.each { |value| boxed << Wardite::I32.new(value) }
|
|
310
|
+
end
|
|
311
|
+
result = host.callable.call(@instance.store, boxed)
|
|
312
|
+
if host.entry.result_types.empty?
|
|
313
|
+
return nil if result.nil?
|
|
314
|
+
elsif result.is_a?(Integer)
|
|
315
|
+
return result & 0xffffffff
|
|
316
|
+
elsif result.is_a?(Wardite::I32)
|
|
317
|
+
return result.value & 0xffffffff
|
|
318
|
+
end
|
|
319
|
+
raise Wardite::EvalError, "host ABI result mismatch for #{host.external.name}"
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# @rbs host: Wardite::Efflorescence::HostFunction
|
|
323
|
+
# @rbs arguments: Array[Integer]
|
|
324
|
+
# @rbs sources: Array[Integer]?
|
|
325
|
+
# @rbs return: Integer?
|
|
326
|
+
def invoke_typed_host(host, arguments, sources)
|
|
327
|
+
boxed = [] #: Array[Wardite::wasmValue]
|
|
328
|
+
host.entry.parameter_types.each_with_index do |type, i|
|
|
329
|
+
index = sources ? sources.fetch(i) : i
|
|
330
|
+
value = arguments.fetch(index)
|
|
331
|
+
boxed << box_result(type, value)
|
|
332
|
+
end
|
|
333
|
+
result = host.callable.call(@instance.store, boxed)
|
|
334
|
+
type = host.entry.result_types[0]
|
|
335
|
+
case type
|
|
336
|
+
when nil
|
|
337
|
+
return nil if result.nil?
|
|
338
|
+
when :i64
|
|
339
|
+
return result.value_s if result.is_a?(Wardite::I64)
|
|
340
|
+
return I64Arithmetic.normalize(result) if result.is_a?(Integer)
|
|
341
|
+
when :f32, :f64
|
|
342
|
+
bits = float_argument(type, result)
|
|
343
|
+
return bits unless bits.nil?
|
|
344
|
+
when :i32
|
|
345
|
+
return result.value & 0xffffffff if result.is_a?(Wardite::I32)
|
|
346
|
+
return result & 0xffffffff if result.is_a?(Integer)
|
|
347
|
+
end
|
|
348
|
+
raise Wardite::EvalError, "host ABI result mismatch for #{host.external.name}"
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
# Each public entry owns its frames, pools and counters, including when a
|
|
352
|
+
# host callback re-enters the VM. Store mutations are shared immediately.
|
|
353
|
+
# @rbs entry: Wardite::Efflorescence::FunctionEntry
|
|
354
|
+
# @rbs arguments: Array[Integer]
|
|
355
|
+
# @rbs return: Integer?
|
|
356
|
+
def execute(entry, arguments)
|
|
357
|
+
metrics = @profiling ? Metrics.new : @metrics
|
|
358
|
+
pools = [] #: Array[Wardite::Efflorescence::FramePool]
|
|
359
|
+
active_frames = [] #: Array[Wardite::Efflorescence::Frame]
|
|
360
|
+
return invoke_host(entry.host_index, arguments, metrics) if entry.kind == :host
|
|
361
|
+
|
|
362
|
+
@ir.functions.each { |function| pools << FramePool.new(function, @reuse_frames) }
|
|
363
|
+
frame = pool_at(pools, entry.defined_index).acquire(-1)
|
|
364
|
+
active_frames << frame
|
|
365
|
+
metrics.root_defined_entries = 1 if @profiling
|
|
366
|
+
arguments.each_with_index { |value, i| frame.registers[i] = value }
|
|
367
|
+
result = execute_flat(frame, pools, active_frames, metrics)
|
|
368
|
+
entry.result_types.empty? ? nil : result
|
|
369
|
+
ensure
|
|
370
|
+
active_frames.each { |active| pool_at(pools, active.pool_index).release(active) }
|
|
371
|
+
if @profiling
|
|
372
|
+
created = 0
|
|
373
|
+
pools.each { |pool| created += pool.created }
|
|
374
|
+
metrics.frames_created = created
|
|
375
|
+
@metrics = metrics
|
|
376
|
+
end
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
# @rbs frame: Wardite::Efflorescence::Frame
|
|
380
|
+
# @rbs site: Wardite::Efflorescence::DynamicCallSite
|
|
381
|
+
# @rbs host_index: Integer
|
|
382
|
+
# @rbs destination: Integer
|
|
383
|
+
# @rbs metrics: Wardite::Efflorescence::Metrics
|
|
384
|
+
# @rbs return: void
|
|
385
|
+
def execute_host_site(frame, site, host_index, destination, metrics)
|
|
386
|
+
registers = frame.registers
|
|
387
|
+
result = invoke_host(host_index, registers, metrics, site.arguments)
|
|
388
|
+
registers[destination] = result if destination >= 0 && result
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
# @rbs site: Wardite::Efflorescence::DynamicCallSite
|
|
392
|
+
# @rbs selector: Integer
|
|
393
|
+
# @rbs return: Wardite::Efflorescence::FunctionEntry
|
|
394
|
+
def indirect_entry(site, selector)
|
|
395
|
+
table = @instance.store.tables[site.table_index]
|
|
396
|
+
raise Wardite::EvalError, "call_indirect requires funcref table 0" unless table && table.type == :funcref
|
|
397
|
+
index = selector & 0xffffffff
|
|
398
|
+
raise Wardite::EvalError, "call_indirect table index out of bounds: #{index}" if index >= table.current
|
|
399
|
+
function = table.refs[index]
|
|
400
|
+
raise Wardite::EvalError, "call_indirect null reference" if function.nil?
|
|
401
|
+
function_index = @function_indices[function.object_id]
|
|
402
|
+
unless function_index && @indirect_functions[function_index].equal?(function)
|
|
403
|
+
raise Wardite::EvalError, "call_indirect unknown function reference"
|
|
404
|
+
end
|
|
405
|
+
entry = @ir.entry_at(function_index)
|
|
406
|
+
unless entry.parameter_types == site.parameter_types && entry.result_types == site.result_types
|
|
407
|
+
raise Wardite::EvalError, "call_indirect function type mismatch"
|
|
408
|
+
end
|
|
409
|
+
entry
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
# @rbs frame: Wardite::Efflorescence::Frame
|
|
413
|
+
# @rbs site_id: Integer
|
|
414
|
+
# @rbs destination: Integer
|
|
415
|
+
# @rbs metrics: Wardite::Efflorescence::Metrics
|
|
416
|
+
# @rbs return: void
|
|
417
|
+
def execute_direct_host(frame, site_id, destination, metrics)
|
|
418
|
+
site = frame.function.dynamic_site(site_id)
|
|
419
|
+
execute_host_site(frame, site, site.host_index, destination, metrics)
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
# Keep table resolution and the additional call locals off the hot path.
|
|
423
|
+
# @rbs frame: Wardite::Efflorescence::Frame
|
|
424
|
+
# @rbs pools: Array[Wardite::Efflorescence::FramePool]
|
|
425
|
+
# @rbs frames: Array[Wardite::Efflorescence::Frame]
|
|
426
|
+
# @rbs destination: Integer
|
|
427
|
+
# @rbs site_id: Integer
|
|
428
|
+
# @rbs selector: Integer
|
|
429
|
+
# @rbs metrics: Wardite::Efflorescence::Metrics
|
|
430
|
+
# @rbs return: Wardite::Efflorescence::Frame
|
|
431
|
+
def execute_indirect(frame, pools, frames, destination, site_id, selector, metrics)
|
|
432
|
+
site = frame.function.dynamic_site(site_id)
|
|
433
|
+
registers = frame.registers
|
|
434
|
+
entry = indirect_entry(site, registers[selector])
|
|
435
|
+
if entry.kind == :host
|
|
436
|
+
execute_host_site(frame, site, entry.host_index, destination, metrics)
|
|
437
|
+
frame
|
|
438
|
+
else
|
|
439
|
+
next_frame = pool_at(pools, entry.defined_index).acquire(destination)
|
|
440
|
+
frames << next_frame
|
|
441
|
+
target = next_frame.registers
|
|
442
|
+
site.arguments.each_with_index { |register, i| target[i] = registers[register] }
|
|
443
|
+
metrics.enter_indirect_defined(site.arguments.size) if @profiling
|
|
444
|
+
next_frame
|
|
445
|
+
end
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
# Float instructions use the same flat words and integer registers.
|
|
449
|
+
# Their dispatch stays outside the main integer switch.
|
|
450
|
+
# @rbs opcode: Integer
|
|
451
|
+
# @rbs instructions: Array[Integer]
|
|
452
|
+
# @rbs pc: Integer
|
|
453
|
+
# @rbs a: Integer
|
|
454
|
+
# @rbs registers: Array[Integer]
|
|
455
|
+
# @rbs return: void
|
|
456
|
+
def execute_float(opcode, instructions, pc, a, registers)
|
|
457
|
+
b = instructions.fetch(pc + 2)
|
|
458
|
+
if opcode >= Opcode::F32_EQ && opcode <= Opcode::F64_COPYSIGN
|
|
459
|
+
types = Opcode::FLOAT_ALU_TYPES.fetch(opcode)
|
|
460
|
+
right = types.size == 3 ? registers[instructions.fetch(pc + 3)] : 0
|
|
461
|
+
registers[a] = FloatArithmetic.calculate(opcode, registers[b], right)
|
|
462
|
+
elsif opcode >= Opcode::I32_TRUNC_F32_S && opcode <= Opcode::F64_PROMOTE_F32
|
|
463
|
+
registers[a] = FloatArithmetic.convert(opcode, registers[b])
|
|
464
|
+
elsif opcode >= Opcode::I32_REINTERPRET_F32 && opcode <= Opcode::F64_REINTERPRET_I64
|
|
465
|
+
registers[a] = registers[b]
|
|
466
|
+
else
|
|
467
|
+
case opcode
|
|
468
|
+
when Opcode::F32_LOAD
|
|
469
|
+
offset = instructions.fetch(pc + 3)
|
|
470
|
+
registers[a] = @store_access.load(registers[b], offset, 4, false)
|
|
471
|
+
when Opcode::F64_LOAD
|
|
472
|
+
offset = instructions.fetch(pc + 3)
|
|
473
|
+
registers[a] = @store_access.load_i64(registers[b], offset, 8, false)
|
|
474
|
+
when Opcode::F32_STORE
|
|
475
|
+
offset = instructions.fetch(pc + 3)
|
|
476
|
+
@store_access.store(registers[b], offset, 4, registers[a])
|
|
477
|
+
when Opcode::F64_STORE
|
|
478
|
+
offset = instructions.fetch(pc + 3)
|
|
479
|
+
@store_access.store(registers[b], offset, 8, registers[a])
|
|
480
|
+
when Opcode::F32_GLOBAL_GET
|
|
481
|
+
registers[a] = @store_access.global_get_float(b, :f32)
|
|
482
|
+
when Opcode::F64_GLOBAL_GET
|
|
483
|
+
registers[a] = @store_access.global_get_float(b, :f64)
|
|
484
|
+
when Opcode::F32_GLOBAL_SET
|
|
485
|
+
@store_access.global_set_float(a, :f32, registers[b])
|
|
486
|
+
when Opcode::F64_GLOBAL_SET
|
|
487
|
+
@store_access.global_set_float(a, :f64, registers[b])
|
|
488
|
+
else
|
|
489
|
+
raise Wardite::EvalError, "Efflorescence: invalid MIR opcode #{opcode}"
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
# @rbs frame: Wardite::Efflorescence::Frame
|
|
495
|
+
# @rbs pools: Array[Wardite::Efflorescence::FramePool]
|
|
496
|
+
# @rbs active_frames: Array[Wardite::Efflorescence::Frame]
|
|
497
|
+
# @rbs return: Integer
|
|
498
|
+
# @rbs metrics: Wardite::Efflorescence::Metrics
|
|
499
|
+
def execute_flat(frame, pools, active_frames, metrics)
|
|
500
|
+
frames = active_frames
|
|
501
|
+
registers = frame.registers
|
|
502
|
+
instructions = frame.function.bytecode
|
|
503
|
+
pc = 0
|
|
504
|
+
# Avoid Kernel#loop's StopIteration handler in the native hot loop.
|
|
505
|
+
while true
|
|
506
|
+
opcode = instructions.fetch(pc)
|
|
507
|
+
a = instructions.fetch(pc + 1)
|
|
508
|
+
# PCs still advance by four words, but short instructions do not
|
|
509
|
+
# read their unused b/c padding. Control transfers skip the increment.
|
|
510
|
+
# Integer literal labels let Spinel emit a C switch. Keep the
|
|
511
|
+
# Opcode comments in sync; the dispatch contract test checks them.
|
|
512
|
+
case opcode
|
|
513
|
+
when 0 # Opcode::COPY
|
|
514
|
+
b = instructions.fetch(pc + 2)
|
|
515
|
+
registers[a] = registers[b]
|
|
516
|
+
when 1 # Opcode::I32_ADD
|
|
517
|
+
b = instructions.fetch(pc + 2)
|
|
518
|
+
c = instructions.fetch(pc + 3)
|
|
519
|
+
registers[a] = (registers[b] + registers[c]) & 0xffffffff
|
|
520
|
+
when 2 # Opcode::I32_SUB
|
|
521
|
+
b = instructions.fetch(pc + 2)
|
|
522
|
+
c = instructions.fetch(pc + 3)
|
|
523
|
+
registers[a] = (registers[b] - registers[c]) & 0xffffffff
|
|
524
|
+
when 3 # Opcode::I32_MUL
|
|
525
|
+
b = instructions.fetch(pc + 2)
|
|
526
|
+
c = instructions.fetch(pc + 3)
|
|
527
|
+
# A full unsigned i32 product can overflow Spinel's native signed
|
|
528
|
+
# word. Split into 16-bit limbs; all intermediates fit in 49 bits.
|
|
529
|
+
left = registers[b]
|
|
530
|
+
right = registers[c]
|
|
531
|
+
low = (left & 0xffff) * right
|
|
532
|
+
high = (((left >> 16) * right) & 0xffff) << 16
|
|
533
|
+
registers[a] = (low + high) & 0xffffffff
|
|
534
|
+
when 4 # Opcode::I32_XOR
|
|
535
|
+
b = instructions.fetch(pc + 2)
|
|
536
|
+
c = instructions.fetch(pc + 3)
|
|
537
|
+
registers[a] = registers[b] ^ registers[c]
|
|
538
|
+
when 5 # Opcode::I32_SHL
|
|
539
|
+
b = instructions.fetch(pc + 2)
|
|
540
|
+
c = instructions.fetch(pc + 3)
|
|
541
|
+
registers[a] = (registers[b] << (registers[c] & 31)) & 0xffffffff
|
|
542
|
+
when 6 # Opcode::I32_SHR_U
|
|
543
|
+
b = instructions.fetch(pc + 2)
|
|
544
|
+
c = instructions.fetch(pc + 3)
|
|
545
|
+
registers[a] = registers[b] >> (registers[c] & 31)
|
|
546
|
+
when 7 # Opcode::I32_EQZ
|
|
547
|
+
b = instructions.fetch(pc + 2)
|
|
548
|
+
registers[a] = registers[b] == 0 ? 1 : 0
|
|
549
|
+
when 13 # Opcode::I32_ADD_IMM
|
|
550
|
+
b = instructions.fetch(pc + 2)
|
|
551
|
+
c = instructions.fetch(pc + 3)
|
|
552
|
+
registers[a] = (registers[b] + c) & 0xffffffff
|
|
553
|
+
when 14 # Opcode::I32_SUB_IMM
|
|
554
|
+
b = instructions.fetch(pc + 2)
|
|
555
|
+
c = instructions.fetch(pc + 3)
|
|
556
|
+
registers[a] = (registers[b] - c) & 0xffffffff
|
|
557
|
+
when 15 # Opcode::I32_MUL_IMM
|
|
558
|
+
b = instructions.fetch(pc + 2)
|
|
559
|
+
c = instructions.fetch(pc + 3)
|
|
560
|
+
left = registers[b]
|
|
561
|
+
right = c
|
|
562
|
+
low = (left & 0xffff) * right
|
|
563
|
+
high = (((left >> 16) * right) & 0xffff) << 16
|
|
564
|
+
registers[a] = (low + high) & 0xffffffff
|
|
565
|
+
when 16 # Opcode::I32_XOR_IMM
|
|
566
|
+
b = instructions.fetch(pc + 2)
|
|
567
|
+
c = instructions.fetch(pc + 3)
|
|
568
|
+
registers[a] = registers[b] ^ c
|
|
569
|
+
when 17 # Opcode::I32_SHL_IMM
|
|
570
|
+
b = instructions.fetch(pc + 2)
|
|
571
|
+
c = instructions.fetch(pc + 3)
|
|
572
|
+
registers[a] = (registers[b] << (c & 31)) & 0xffffffff
|
|
573
|
+
when 18 # Opcode::I32_SHR_U_IMM
|
|
574
|
+
b = instructions.fetch(pc + 2)
|
|
575
|
+
c = instructions.fetch(pc + 3)
|
|
576
|
+
registers[a] = registers[b] >> (c & 31)
|
|
577
|
+
when 20 # Opcode::I32_XOR_SHR_U_IMM
|
|
578
|
+
b = instructions.fetch(pc + 2)
|
|
579
|
+
c = instructions.fetch(pc + 3)
|
|
580
|
+
value = registers[b]
|
|
581
|
+
registers[a] = value ^ (value >> c)
|
|
582
|
+
when 21 # Opcode::I32_XOR_SHL_IMM
|
|
583
|
+
b = instructions.fetch(pc + 2)
|
|
584
|
+
c = instructions.fetch(pc + 3)
|
|
585
|
+
value = registers[b]
|
|
586
|
+
registers[a] = (value ^ (value << c)) & 0xffffffff
|
|
587
|
+
when 8 # Opcode::BR
|
|
588
|
+
pc = a
|
|
589
|
+
next
|
|
590
|
+
when 9 # Opcode::BR_IF
|
|
591
|
+
b = instructions.fetch(pc + 2)
|
|
592
|
+
if registers[a] != 0
|
|
593
|
+
pc = b
|
|
594
|
+
next
|
|
595
|
+
end
|
|
596
|
+
when 19 # Opcode::BR_IF_ZERO
|
|
597
|
+
b = instructions.fetch(pc + 2)
|
|
598
|
+
if registers[a] == 0
|
|
599
|
+
pc = b
|
|
600
|
+
next
|
|
601
|
+
end
|
|
602
|
+
when 10 # Opcode::CALL
|
|
603
|
+
b = instructions.fetch(pc + 2)
|
|
604
|
+
c = instructions.fetch(pc + 3)
|
|
605
|
+
frame.pc = pc + Lowerer::WIDTH
|
|
606
|
+
site = frame.function.call_site(b)
|
|
607
|
+
pool = pools[site.pool_index]
|
|
608
|
+
raise Wardite::EvalError, "missing MIR frame pool" unless pool
|
|
609
|
+
next_frame = pool.acquire(a)
|
|
610
|
+
if c >= 0
|
|
611
|
+
next_frame.registers[0] = registers[c]
|
|
612
|
+
else
|
|
613
|
+
site.copy_arguments(next_frame.registers, registers)
|
|
614
|
+
end
|
|
615
|
+
frames << next_frame
|
|
616
|
+
frame = next_frame
|
|
617
|
+
registers = frame.registers
|
|
618
|
+
instructions = frame.function.bytecode
|
|
619
|
+
pc = 0
|
|
620
|
+
next
|
|
621
|
+
when 67 # Opcode::CALL_HOST
|
|
622
|
+
execute_direct_host(frame, instructions.fetch(pc + 2), a, metrics)
|
|
623
|
+
when 68 # Opcode::CALL_INDIRECT
|
|
624
|
+
b = instructions.fetch(pc + 2)
|
|
625
|
+
c = instructions.fetch(pc + 3)
|
|
626
|
+
frame.pc = pc + Lowerer::WIDTH
|
|
627
|
+
frame = execute_indirect(frame, pools, frames, a, b, c, metrics)
|
|
628
|
+
registers = frame.registers
|
|
629
|
+
instructions = frame.function.bytecode
|
|
630
|
+
pc = Integer(frame.pc)
|
|
631
|
+
next
|
|
632
|
+
when 11 # Opcode::RETURN
|
|
633
|
+
# Verified RETURN reads an initialized integer. Keep its native type
|
|
634
|
+
# separate from the nullable array reads used by the ALU cases.
|
|
635
|
+
return_value = a < 0 ? 0 : Integer(registers[a])
|
|
636
|
+
destination = frame.return_register
|
|
637
|
+
frames.pop
|
|
638
|
+
pool = pools[frame.pool_index]
|
|
639
|
+
raise Wardite::EvalError, "missing MIR frame pool" unless pool
|
|
640
|
+
pool.release(frame)
|
|
641
|
+
return return_value if frames.empty?
|
|
642
|
+
frame = current_frame(frames)
|
|
643
|
+
registers = frame.registers
|
|
644
|
+
registers[destination] = return_value if destination >= 0
|
|
645
|
+
instructions = frame.function.bytecode
|
|
646
|
+
pc = Integer(frame.pc)
|
|
647
|
+
next
|
|
648
|
+
when 12 # Opcode::TRAP
|
|
649
|
+
raise Wardite::Unreachable, "unreachable op"
|
|
650
|
+
when 23 # Opcode::I32_EQ
|
|
651
|
+
b = instructions.fetch(pc + 2)
|
|
652
|
+
c = instructions.fetch(pc + 3)
|
|
653
|
+
registers[a] = calculate(23, registers[b], registers[c])
|
|
654
|
+
when 24 # Opcode::I32_NE
|
|
655
|
+
b = instructions.fetch(pc + 2)
|
|
656
|
+
c = instructions.fetch(pc + 3)
|
|
657
|
+
registers[a] = calculate(24, registers[b], registers[c])
|
|
658
|
+
when 25 # Opcode::I32_LTS
|
|
659
|
+
b = instructions.fetch(pc + 2)
|
|
660
|
+
c = instructions.fetch(pc + 3)
|
|
661
|
+
registers[a] = calculate(25, registers[b], registers[c])
|
|
662
|
+
when 26 # Opcode::I32_LTU
|
|
663
|
+
b = instructions.fetch(pc + 2)
|
|
664
|
+
c = instructions.fetch(pc + 3)
|
|
665
|
+
registers[a] = calculate(26, registers[b], registers[c])
|
|
666
|
+
when 27 # Opcode::I32_GTS
|
|
667
|
+
b = instructions.fetch(pc + 2)
|
|
668
|
+
c = instructions.fetch(pc + 3)
|
|
669
|
+
registers[a] = calculate(27, registers[b], registers[c])
|
|
670
|
+
when 28 # Opcode::I32_GTU
|
|
671
|
+
b = instructions.fetch(pc + 2)
|
|
672
|
+
c = instructions.fetch(pc + 3)
|
|
673
|
+
registers[a] = calculate(28, registers[b], registers[c])
|
|
674
|
+
when 29 # Opcode::I32_LES
|
|
675
|
+
b = instructions.fetch(pc + 2)
|
|
676
|
+
c = instructions.fetch(pc + 3)
|
|
677
|
+
registers[a] = calculate(29, registers[b], registers[c])
|
|
678
|
+
when 30 # Opcode::I32_LEU
|
|
679
|
+
b = instructions.fetch(pc + 2)
|
|
680
|
+
c = instructions.fetch(pc + 3)
|
|
681
|
+
registers[a] = calculate(30, registers[b], registers[c])
|
|
682
|
+
when 31 # Opcode::I32_GES
|
|
683
|
+
b = instructions.fetch(pc + 2)
|
|
684
|
+
c = instructions.fetch(pc + 3)
|
|
685
|
+
registers[a] = calculate(31, registers[b], registers[c])
|
|
686
|
+
when 32 # Opcode::I32_GEU
|
|
687
|
+
b = instructions.fetch(pc + 2)
|
|
688
|
+
c = instructions.fetch(pc + 3)
|
|
689
|
+
registers[a] = calculate(32, registers[b], registers[c])
|
|
690
|
+
when 33 # Opcode::I32_CLZ
|
|
691
|
+
b = instructions.fetch(pc + 2)
|
|
692
|
+
registers[a] = calculate(33, registers[b], 0)
|
|
693
|
+
when 34 # Opcode::I32_CTZ
|
|
694
|
+
b = instructions.fetch(pc + 2)
|
|
695
|
+
registers[a] = calculate(34, registers[b], 0)
|
|
696
|
+
when 35 # Opcode::I32_POPCNT
|
|
697
|
+
b = instructions.fetch(pc + 2)
|
|
698
|
+
registers[a] = calculate(35, registers[b], 0)
|
|
699
|
+
when 36 # Opcode::I32_DIV_S
|
|
700
|
+
b = instructions.fetch(pc + 2)
|
|
701
|
+
c = instructions.fetch(pc + 3)
|
|
702
|
+
registers[a] = calculate(36, registers[b], registers[c])
|
|
703
|
+
when 37 # Opcode::I32_DIV_U
|
|
704
|
+
b = instructions.fetch(pc + 2)
|
|
705
|
+
c = instructions.fetch(pc + 3)
|
|
706
|
+
registers[a] = calculate(37, registers[b], registers[c])
|
|
707
|
+
when 38 # Opcode::I32_REM_S
|
|
708
|
+
b = instructions.fetch(pc + 2)
|
|
709
|
+
c = instructions.fetch(pc + 3)
|
|
710
|
+
registers[a] = calculate(38, registers[b], registers[c])
|
|
711
|
+
when 39 # Opcode::I32_REM_U
|
|
712
|
+
b = instructions.fetch(pc + 2)
|
|
713
|
+
c = instructions.fetch(pc + 3)
|
|
714
|
+
registers[a] = calculate(39, registers[b], registers[c])
|
|
715
|
+
when 40 # Opcode::I32_AND
|
|
716
|
+
b = instructions.fetch(pc + 2)
|
|
717
|
+
c = instructions.fetch(pc + 3)
|
|
718
|
+
registers[a] = calculate(40, registers[b], registers[c])
|
|
719
|
+
when 41 # Opcode::I32_OR
|
|
720
|
+
b = instructions.fetch(pc + 2)
|
|
721
|
+
c = instructions.fetch(pc + 3)
|
|
722
|
+
registers[a] = calculate(41, registers[b], registers[c])
|
|
723
|
+
when 42 # Opcode::I32_SHR_S
|
|
724
|
+
b = instructions.fetch(pc + 2)
|
|
725
|
+
c = instructions.fetch(pc + 3)
|
|
726
|
+
registers[a] = calculate(42, registers[b], registers[c])
|
|
727
|
+
when 43 # Opcode::I32_ROTL
|
|
728
|
+
b = instructions.fetch(pc + 2)
|
|
729
|
+
c = instructions.fetch(pc + 3)
|
|
730
|
+
registers[a] = calculate(43, registers[b], registers[c])
|
|
731
|
+
when 44 # Opcode::I32_ROTR
|
|
732
|
+
b = instructions.fetch(pc + 2)
|
|
733
|
+
c = instructions.fetch(pc + 3)
|
|
734
|
+
registers[a] = calculate(44, registers[b], registers[c])
|
|
735
|
+
when 45 # Opcode::I32_EXTEND8_S
|
|
736
|
+
b = instructions.fetch(pc + 2)
|
|
737
|
+
registers[a] = calculate(45, registers[b], 0)
|
|
738
|
+
when 46 # Opcode::I32_EXTEND16_S
|
|
739
|
+
b = instructions.fetch(pc + 2)
|
|
740
|
+
registers[a] = calculate(46, registers[b], 0)
|
|
741
|
+
when 47 # Opcode::COPY_REF
|
|
742
|
+
b = instructions.fetch(pc + 2)
|
|
743
|
+
frame.exception_registers[a] = frame.exception_registers[b]
|
|
744
|
+
when 48 # Opcode::EH_ENTER
|
|
745
|
+
frame.handlers << a
|
|
746
|
+
when 49 # Opcode::EH_TRIM
|
|
747
|
+
frame.trim_handlers(a)
|
|
748
|
+
when 50 # Opcode::THROW
|
|
749
|
+
value_ref = exception_at(frame, a)
|
|
750
|
+
frame = propagate(value_ref, frames, pools)
|
|
751
|
+
registers = frame.registers
|
|
752
|
+
instructions = frame.function.bytecode
|
|
753
|
+
pc = Integer(frame.pc)
|
|
754
|
+
next
|
|
755
|
+
when 51 # Opcode::THROW_REF
|
|
756
|
+
value_ref = frame.exception_registers[a]
|
|
757
|
+
raise Wardite::EvalError, "throw_ref null" unless value_ref
|
|
758
|
+
frame = propagate(value_ref, frames, pools)
|
|
759
|
+
registers = frame.registers
|
|
760
|
+
instructions = frame.function.bytecode
|
|
761
|
+
pc = Integer(frame.pc)
|
|
762
|
+
next
|
|
763
|
+
when 52 # Opcode::GLOBAL_GET
|
|
764
|
+
b = instructions.fetch(pc + 2)
|
|
765
|
+
registers[a] = @store_access.global_get(b)
|
|
766
|
+
when 53 # Opcode::GLOBAL_SET
|
|
767
|
+
b = instructions.fetch(pc + 2)
|
|
768
|
+
@store_access.global_set(a, registers[b])
|
|
769
|
+
when 54 # Opcode::I32_LOAD
|
|
770
|
+
b = instructions.fetch(pc + 2)
|
|
771
|
+
c = instructions.fetch(pc + 3)
|
|
772
|
+
registers[a] = @store_access.load(registers[b], c, 4, false)
|
|
773
|
+
when 55 # Opcode::I32_LOAD8_S
|
|
774
|
+
b = instructions.fetch(pc + 2)
|
|
775
|
+
c = instructions.fetch(pc + 3)
|
|
776
|
+
registers[a] = @store_access.load(registers[b], c, 1, true)
|
|
777
|
+
when 56 # Opcode::I32_LOAD8_U
|
|
778
|
+
b = instructions.fetch(pc + 2)
|
|
779
|
+
c = instructions.fetch(pc + 3)
|
|
780
|
+
registers[a] = @store_access.load(registers[b], c, 1, false)
|
|
781
|
+
when 57 # Opcode::I32_LOAD16_S
|
|
782
|
+
b = instructions.fetch(pc + 2)
|
|
783
|
+
c = instructions.fetch(pc + 3)
|
|
784
|
+
registers[a] = @store_access.load(registers[b], c, 2, true)
|
|
785
|
+
when 58 # Opcode::I32_LOAD16_U
|
|
786
|
+
b = instructions.fetch(pc + 2)
|
|
787
|
+
c = instructions.fetch(pc + 3)
|
|
788
|
+
registers[a] = @store_access.load(registers[b], c, 2, false)
|
|
789
|
+
when 59 # Opcode::I32_STORE
|
|
790
|
+
b = instructions.fetch(pc + 2)
|
|
791
|
+
c = instructions.fetch(pc + 3)
|
|
792
|
+
@store_access.store(registers[b], c, 4, registers[a])
|
|
793
|
+
when 60 # Opcode::I32_STORE8
|
|
794
|
+
b = instructions.fetch(pc + 2)
|
|
795
|
+
c = instructions.fetch(pc + 3)
|
|
796
|
+
@store_access.store(registers[b], c, 1, registers[a])
|
|
797
|
+
when 61 # Opcode::I32_STORE16
|
|
798
|
+
b = instructions.fetch(pc + 2)
|
|
799
|
+
c = instructions.fetch(pc + 3)
|
|
800
|
+
@store_access.store(registers[b], c, 2, registers[a])
|
|
801
|
+
when 62 # Opcode::MEMORY_SIZE
|
|
802
|
+
registers[a] = @store_access.size
|
|
803
|
+
when 63 # Opcode::MEMORY_GROW
|
|
804
|
+
b = instructions.fetch(pc + 2)
|
|
805
|
+
registers[a] = @store_access.grow(registers[b])
|
|
806
|
+
when 64 # Opcode::MEMORY_INIT
|
|
807
|
+
@store_access.bulk(64, frame.function.memory_site(a), registers)
|
|
808
|
+
when 65 # Opcode::MEMORY_COPY
|
|
809
|
+
@store_access.bulk(65, frame.function.memory_site(a), registers)
|
|
810
|
+
when 66 # Opcode::MEMORY_FILL
|
|
811
|
+
@store_access.bulk(66, frame.function.memory_site(a), registers)
|
|
812
|
+
when 69 # Opcode::I64_EQZ
|
|
813
|
+
b = instructions.fetch(pc + 2)
|
|
814
|
+
registers[a] = I64Arithmetic.calculate(69, registers[b], 0)
|
|
815
|
+
when 70 # Opcode::I32_WRAP_I64
|
|
816
|
+
b = instructions.fetch(pc + 2)
|
|
817
|
+
registers[a] = I64Arithmetic.calculate(70, registers[b], 0)
|
|
818
|
+
when 71 # Opcode::I64_EQ
|
|
819
|
+
b = instructions.fetch(pc + 2)
|
|
820
|
+
c = instructions.fetch(pc + 3)
|
|
821
|
+
registers[a] = I64Arithmetic.calculate(71, registers[b], registers[c])
|
|
822
|
+
when 72 # Opcode::I64_NE
|
|
823
|
+
b = instructions.fetch(pc + 2)
|
|
824
|
+
c = instructions.fetch(pc + 3)
|
|
825
|
+
registers[a] = I64Arithmetic.calculate(72, registers[b], registers[c])
|
|
826
|
+
when 73 # Opcode::I64_LTS
|
|
827
|
+
b = instructions.fetch(pc + 2)
|
|
828
|
+
c = instructions.fetch(pc + 3)
|
|
829
|
+
registers[a] = I64Arithmetic.calculate(73, registers[b], registers[c])
|
|
830
|
+
when 74 # Opcode::I64_LTU
|
|
831
|
+
b = instructions.fetch(pc + 2)
|
|
832
|
+
c = instructions.fetch(pc + 3)
|
|
833
|
+
registers[a] = I64Arithmetic.calculate(74, registers[b], registers[c])
|
|
834
|
+
when 75 # Opcode::I64_GTS
|
|
835
|
+
b = instructions.fetch(pc + 2)
|
|
836
|
+
c = instructions.fetch(pc + 3)
|
|
837
|
+
registers[a] = I64Arithmetic.calculate(75, registers[b], registers[c])
|
|
838
|
+
when 76 # Opcode::I64_GTU
|
|
839
|
+
b = instructions.fetch(pc + 2)
|
|
840
|
+
c = instructions.fetch(pc + 3)
|
|
841
|
+
registers[a] = I64Arithmetic.calculate(76, registers[b], registers[c])
|
|
842
|
+
when 77 # Opcode::I64_LES
|
|
843
|
+
b = instructions.fetch(pc + 2)
|
|
844
|
+
c = instructions.fetch(pc + 3)
|
|
845
|
+
registers[a] = I64Arithmetic.calculate(77, registers[b], registers[c])
|
|
846
|
+
when 78 # Opcode::I64_LEU
|
|
847
|
+
b = instructions.fetch(pc + 2)
|
|
848
|
+
c = instructions.fetch(pc + 3)
|
|
849
|
+
registers[a] = I64Arithmetic.calculate(78, registers[b], registers[c])
|
|
850
|
+
when 79 # Opcode::I64_GES
|
|
851
|
+
b = instructions.fetch(pc + 2)
|
|
852
|
+
c = instructions.fetch(pc + 3)
|
|
853
|
+
registers[a] = I64Arithmetic.calculate(79, registers[b], registers[c])
|
|
854
|
+
when 80 # Opcode::I64_GEU
|
|
855
|
+
b = instructions.fetch(pc + 2)
|
|
856
|
+
c = instructions.fetch(pc + 3)
|
|
857
|
+
registers[a] = I64Arithmetic.calculate(80, registers[b], registers[c])
|
|
858
|
+
when 81 # Opcode::I64_CLZ
|
|
859
|
+
b = instructions.fetch(pc + 2)
|
|
860
|
+
registers[a] = I64Arithmetic.calculate(81, registers[b], 0)
|
|
861
|
+
when 82 # Opcode::I64_CTZ
|
|
862
|
+
b = instructions.fetch(pc + 2)
|
|
863
|
+
registers[a] = I64Arithmetic.calculate(82, registers[b], 0)
|
|
864
|
+
when 83 # Opcode::I64_POPCNT
|
|
865
|
+
b = instructions.fetch(pc + 2)
|
|
866
|
+
registers[a] = I64Arithmetic.calculate(83, registers[b], 0)
|
|
867
|
+
when 84 # Opcode::I64_EXTEND8_S
|
|
868
|
+
b = instructions.fetch(pc + 2)
|
|
869
|
+
registers[a] = I64Arithmetic.calculate(84, registers[b], 0)
|
|
870
|
+
when 85 # Opcode::I64_EXTEND16_S
|
|
871
|
+
b = instructions.fetch(pc + 2)
|
|
872
|
+
registers[a] = I64Arithmetic.calculate(85, registers[b], 0)
|
|
873
|
+
when 86 # Opcode::I64_EXTEND32_S
|
|
874
|
+
b = instructions.fetch(pc + 2)
|
|
875
|
+
registers[a] = I64Arithmetic.calculate(86, registers[b], 0)
|
|
876
|
+
when 87 # Opcode::I64_EXTEND_I32_S
|
|
877
|
+
b = instructions.fetch(pc + 2)
|
|
878
|
+
registers[a] = I64Arithmetic.calculate(87, registers[b], 0)
|
|
879
|
+
when 88 # Opcode::I64_EXTEND_I32_U
|
|
880
|
+
b = instructions.fetch(pc + 2)
|
|
881
|
+
registers[a] = I64Arithmetic.calculate(88, registers[b], 0)
|
|
882
|
+
when 89 # Opcode::I64_AND
|
|
883
|
+
b = instructions.fetch(pc + 2)
|
|
884
|
+
c = instructions.fetch(pc + 3)
|
|
885
|
+
registers[a] = I64Arithmetic.calculate(89, registers[b], registers[c])
|
|
886
|
+
when 90 # Opcode::I64_OR
|
|
887
|
+
b = instructions.fetch(pc + 2)
|
|
888
|
+
c = instructions.fetch(pc + 3)
|
|
889
|
+
registers[a] = I64Arithmetic.calculate(90, registers[b], registers[c])
|
|
890
|
+
when 91 # Opcode::I64_XOR
|
|
891
|
+
b = instructions.fetch(pc + 2)
|
|
892
|
+
c = instructions.fetch(pc + 3)
|
|
893
|
+
registers[a] = I64Arithmetic.calculate(91, registers[b], registers[c])
|
|
894
|
+
when 92 # Opcode::I64_SHL
|
|
895
|
+
b = instructions.fetch(pc + 2)
|
|
896
|
+
c = instructions.fetch(pc + 3)
|
|
897
|
+
registers[a] = I64Arithmetic.calculate(92, registers[b], registers[c])
|
|
898
|
+
when 93 # Opcode::I64_SHR_S
|
|
899
|
+
b = instructions.fetch(pc + 2)
|
|
900
|
+
c = instructions.fetch(pc + 3)
|
|
901
|
+
registers[a] = I64Arithmetic.calculate(93, registers[b], registers[c])
|
|
902
|
+
when 94 # Opcode::I64_SHR_U
|
|
903
|
+
b = instructions.fetch(pc + 2)
|
|
904
|
+
c = instructions.fetch(pc + 3)
|
|
905
|
+
registers[a] = I64Arithmetic.calculate(94, registers[b], registers[c])
|
|
906
|
+
when 95 # Opcode::I64_ROTL
|
|
907
|
+
b = instructions.fetch(pc + 2)
|
|
908
|
+
c = instructions.fetch(pc + 3)
|
|
909
|
+
registers[a] = I64Arithmetic.calculate(95, registers[b], registers[c])
|
|
910
|
+
when 96 # Opcode::I64_ROTR
|
|
911
|
+
b = instructions.fetch(pc + 2)
|
|
912
|
+
c = instructions.fetch(pc + 3)
|
|
913
|
+
registers[a] = I64Arithmetic.calculate(96, registers[b], registers[c])
|
|
914
|
+
when 97 # Opcode::I64_ADD
|
|
915
|
+
b = instructions.fetch(pc + 2)
|
|
916
|
+
c = instructions.fetch(pc + 3)
|
|
917
|
+
registers[a] = I64Arithmetic.calculate(97, registers[b], registers[c])
|
|
918
|
+
when 98 # Opcode::I64_SUB
|
|
919
|
+
b = instructions.fetch(pc + 2)
|
|
920
|
+
c = instructions.fetch(pc + 3)
|
|
921
|
+
registers[a] = I64Arithmetic.calculate(98, registers[b], registers[c])
|
|
922
|
+
when 99 # Opcode::I64_MUL
|
|
923
|
+
b = instructions.fetch(pc + 2)
|
|
924
|
+
c = instructions.fetch(pc + 3)
|
|
925
|
+
registers[a] = I64Arithmetic.calculate(99, registers[b], registers[c])
|
|
926
|
+
when 100 # Opcode::I64_DIV_S
|
|
927
|
+
b = instructions.fetch(pc + 2)
|
|
928
|
+
c = instructions.fetch(pc + 3)
|
|
929
|
+
registers[a] = I64Arithmetic.calculate(100, registers[b], registers[c])
|
|
930
|
+
when 101 # Opcode::I64_DIV_U
|
|
931
|
+
b = instructions.fetch(pc + 2)
|
|
932
|
+
c = instructions.fetch(pc + 3)
|
|
933
|
+
registers[a] = I64Arithmetic.calculate(101, registers[b], registers[c])
|
|
934
|
+
when 102 # Opcode::I64_REM_S
|
|
935
|
+
b = instructions.fetch(pc + 2)
|
|
936
|
+
c = instructions.fetch(pc + 3)
|
|
937
|
+
registers[a] = I64Arithmetic.calculate(102, registers[b], registers[c])
|
|
938
|
+
when 103 # Opcode::I64_REM_U
|
|
939
|
+
b = instructions.fetch(pc + 2)
|
|
940
|
+
c = instructions.fetch(pc + 3)
|
|
941
|
+
registers[a] = I64Arithmetic.calculate(103, registers[b], registers[c])
|
|
942
|
+
when 104 # Opcode::I64_LOAD
|
|
943
|
+
b = instructions.fetch(pc + 2)
|
|
944
|
+
c = instructions.fetch(pc + 3)
|
|
945
|
+
registers[a] = @store_access.load_i64(registers[b], c, 8, false)
|
|
946
|
+
when 105 # Opcode::I64_LOAD8_S
|
|
947
|
+
b = instructions.fetch(pc + 2)
|
|
948
|
+
c = instructions.fetch(pc + 3)
|
|
949
|
+
registers[a] = @store_access.load_i64(registers[b], c, 1, true)
|
|
950
|
+
when 106 # Opcode::I64_LOAD8_U
|
|
951
|
+
b = instructions.fetch(pc + 2)
|
|
952
|
+
c = instructions.fetch(pc + 3)
|
|
953
|
+
registers[a] = @store_access.load_i64(registers[b], c, 1, false)
|
|
954
|
+
when 107 # Opcode::I64_LOAD16_S
|
|
955
|
+
b = instructions.fetch(pc + 2)
|
|
956
|
+
c = instructions.fetch(pc + 3)
|
|
957
|
+
registers[a] = @store_access.load_i64(registers[b], c, 2, true)
|
|
958
|
+
when 108 # Opcode::I64_LOAD16_U
|
|
959
|
+
b = instructions.fetch(pc + 2)
|
|
960
|
+
c = instructions.fetch(pc + 3)
|
|
961
|
+
registers[a] = @store_access.load_i64(registers[b], c, 2, false)
|
|
962
|
+
when 109 # Opcode::I64_LOAD32_S
|
|
963
|
+
b = instructions.fetch(pc + 2)
|
|
964
|
+
c = instructions.fetch(pc + 3)
|
|
965
|
+
registers[a] = @store_access.load_i64(registers[b], c, 4, true)
|
|
966
|
+
when 110 # Opcode::I64_LOAD32_U
|
|
967
|
+
b = instructions.fetch(pc + 2)
|
|
968
|
+
c = instructions.fetch(pc + 3)
|
|
969
|
+
registers[a] = @store_access.load_i64(registers[b], c, 4, false)
|
|
970
|
+
when 111 # Opcode::I64_STORE
|
|
971
|
+
b = instructions.fetch(pc + 2)
|
|
972
|
+
c = instructions.fetch(pc + 3)
|
|
973
|
+
@store_access.store(registers[b], c, 8, registers[a])
|
|
974
|
+
when 112 # Opcode::I64_STORE8
|
|
975
|
+
b = instructions.fetch(pc + 2)
|
|
976
|
+
c = instructions.fetch(pc + 3)
|
|
977
|
+
@store_access.store(registers[b], c, 1, registers[a])
|
|
978
|
+
when 113 # Opcode::I64_STORE16
|
|
979
|
+
b = instructions.fetch(pc + 2)
|
|
980
|
+
c = instructions.fetch(pc + 3)
|
|
981
|
+
@store_access.store(registers[b], c, 2, registers[a])
|
|
982
|
+
when 114 # Opcode::I64_STORE32
|
|
983
|
+
b = instructions.fetch(pc + 2)
|
|
984
|
+
c = instructions.fetch(pc + 3)
|
|
985
|
+
@store_access.store(registers[b], c, 4, registers[a])
|
|
986
|
+
when 115 # Opcode::I64_GLOBAL_GET
|
|
987
|
+
b = instructions.fetch(pc + 2)
|
|
988
|
+
registers[a] = @store_access.global_get_i64(b)
|
|
989
|
+
when 116 # Opcode::I64_GLOBAL_SET
|
|
990
|
+
b = instructions.fetch(pc + 2)
|
|
991
|
+
@store_access.global_set_i64(a, registers[b])
|
|
992
|
+
when 22 # Opcode::PROFILE
|
|
993
|
+
b = instructions.fetch(pc + 2)
|
|
994
|
+
c = instructions.fetch(pc + 3)
|
|
995
|
+
metrics.record(a, b, c)
|
|
996
|
+
else
|
|
997
|
+
execute_float(opcode, instructions, pc, a, registers)
|
|
998
|
+
end
|
|
999
|
+
pc += Lowerer::WIDTH
|
|
1000
|
+
end
|
|
1001
|
+
# Steep treats while as possibly nil; execution always returns or raises.
|
|
1002
|
+
raise Wardite::EvalError, "Efflorescence: MIR execution ended without RETURN"
|
|
1003
|
+
end
|
|
1004
|
+
end
|
|
1005
|
+
end
|
|
1006
|
+
end
|