wardite 1.2.1 → 1.3.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/README.md +17 -16
- data/Rakefile +0 -177
- data/benchmark/README.md +11 -37
- data/benchmark/call_cost_worker.rb +3 -2
- data/benchmark/compare.rb +1 -2
- data/benchmark/compare_linear_memory_loads.py +144 -0
- data/benchmark/i32_memory.wat +5 -1
- data/benchmark/investigate_calls.rb +3 -3
- data/benchmark/linear_memory_loads.wat +52 -0
- data/benchmark/optimization_worker.rb +3 -2
- data/benchmark/patches/adr0017-spinel-signed64.patch +190 -0
- data/benchmark/patches/adr0017-wardite-split-load64.patch +70 -0
- data/benchmark/results/adr0019-startup.json +1687 -0
- data/benchmark/results/adr0020-i64.json +2034 -0
- data/benchmark/results/adr0021-optimizer.json +5798 -0
- data/benchmark/results/adr0022-lazy-mir.json +3057 -0
- data/benchmark/results/crc8-stream-repeat.csv +89 -0
- data/benchmark/results/crc8-stream.csv +89 -0
- data/benchmark/results/linear-memory-loads-a2aa05227.csv +793 -0
- data/benchmark/results/linear-memory-loads-stage-b.csv +353 -0
- data/benchmark/results/linear-memory-loads.csv +1057 -0
- data/benchmark/results/real-workloads-baseline-2026-11-18.json +1741 -0
- data/benchmark/results/stack-vm-removal.json +334 -0
- data/benchmark/validate_m4.rb +0 -2
- data/docs/adr/0017-efflorescence-linear-memory-loads.md +90 -0
- data/docs/adr/0018-efflorescence-real-workload-measurement.md +126 -0
- data/docs/adr/0019-efflorescence-startup-quick-wins.md +85 -0
- data/docs/adr/0020-efflorescence-inline-i64-bit-operations.md +89 -0
- data/docs/adr/0021-efflorescence-optimize-real-functions.md +133 -0
- data/docs/adr/0022-efflorescence-lazy-function-build.md +111 -0
- data/docs/adr/0023-efflorescence-byte-sequences-and-copy-coalescing.md +56 -0
- data/docs/efflorescence-ja.md +6 -9
- data/docs/efflorescence-linear-memory-loads.md +134 -0
- data/docs/efflorescence-m6.md +1 -1
- data/docs/efflorescence-mir2-cache.md +7 -0
- data/docs/efflorescence-real-workloads.md +312 -0
- data/docs/efflorescence-spinel-linear-memory.md +2 -2
- data/docs/efflorescence.md +7 -8
- data/docs/stack-vm-removal.md +49 -0
- data/lib/wardite/cli/cli.rb +24 -21
- data/lib/wardite/efflorescence/byte_sequences.rb +80 -0
- data/lib/wardite/efflorescence/function_preparer.rb +64 -0
- data/lib/wardite/efflorescence/i64_arithmetic.rb +31 -0
- data/lib/wardite/efflorescence/inspection.rb +44 -12
- data/lib/wardite/efflorescence/ir.rb +33 -10
- data/lib/wardite/efflorescence/mir_cache.rb +10 -1
- data/lib/wardite/efflorescence/optimizer.rb +151 -42
- data/lib/wardite/efflorescence/store_access.rb +17 -0
- data/lib/wardite/efflorescence/translation_source.rb +50 -0
- data/lib/wardite/efflorescence/translator.rb +43 -13
- data/lib/wardite/efflorescence/vm.rb +116 -48
- data/lib/wardite/efflorescence.rb +3 -0
- data/lib/wardite/load.rb +47 -63
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite.rb +21 -757
- data/scripts/build_spinel_zig.rb +1 -1
- data/sig/generated/wardite/cli/cli.rbs +4 -2
- data/sig/generated/wardite/efflorescence/byte_sequences.rbs +33 -0
- data/sig/generated/wardite/efflorescence/function_preparer.rbs +25 -0
- data/sig/generated/wardite/efflorescence/i64_arithmetic.rbs +19 -0
- data/sig/generated/wardite/efflorescence/inspection.rbs +8 -0
- data/sig/generated/wardite/efflorescence/ir.rbs +18 -2
- data/sig/generated/wardite/efflorescence/optimizer.rbs +41 -3
- data/sig/generated/wardite/efflorescence/store_access.rbs +5 -0
- data/sig/generated/wardite/efflorescence/translation_source.rbs +34 -0
- data/sig/generated/wardite/efflorescence/translator.rbs +11 -1
- data/sig/generated/wardite/efflorescence/vm.rbs +19 -9
- data/sig/generated/wardite/load.rbs +18 -18
- data/sig/generated/wardite.rbs +4 -155
- metadata +32 -17
- data/benchmark/compare_engines.rb +0 -119
- data/benchmark/engine_phases.rb +0 -30
- data/lib/wardite/alu_f32.generated.rb +0 -261
- data/lib/wardite/alu_f64.generated.rb +0 -261
- data/lib/wardite/alu_i32.generated.rb +0 -510
- data/lib/wardite/alu_i64.generated.rb +0 -572
- data/lib/wardite/convert.generated.rb +0 -340
- data/scripts/gen_alu.rb +0 -864
- data/scripts/gen_conv.rb +0 -86
- data/scripts/templates/alu_module.rb.tmpl +0 -20
- data/scripts/templates/conv_module.rb.tmpl +0 -20
- data/sig/generated/wardite/alu_f32.generated.rbs +0 -12
- data/sig/generated/wardite/alu_f64.generated.rbs +0 -12
- data/sig/generated/wardite/alu_i32.generated.rbs +0 -12
- data/sig/generated/wardite/alu_i64.generated.rbs +0 -12
- data/sig/generated/wardite/convert.generated.rbs +0 -12
|
@@ -193,6 +193,7 @@ module Wardite
|
|
|
193
193
|
f64_load: Opcode::F64_LOAD, f64_store: Opcode::F64_STORE }.freeze
|
|
194
194
|
STORE_CODES = (MEMORY_WIDTHS.keys + %i[global_get global_set memory_size memory_grow memory_init memory_copy memory_fill]).freeze
|
|
195
195
|
|
|
196
|
+
# @rbs @source: Wardite::Efflorescence::Translator::ModuleSource
|
|
196
197
|
# @rbs @instance: Wardite::Instance
|
|
197
198
|
# @rbs @entries: Array[Wardite::Efflorescence::FunctionEntry]
|
|
198
199
|
# @rbs @stack: Array[Integer]
|
|
@@ -207,10 +208,13 @@ module Wardite
|
|
|
207
208
|
# @rbs @handler_depth: Integer
|
|
208
209
|
|
|
209
210
|
# @rbs instance: Wardite::Instance
|
|
210
|
-
|
|
211
|
+
# @rbs source: ModuleSource
|
|
212
|
+
def initialize(instance, source = ModuleSource.new(instance))
|
|
213
|
+
@source = source
|
|
211
214
|
@instance = instance
|
|
212
215
|
@entries = []
|
|
213
|
-
@stack, @controls
|
|
216
|
+
@stack, @controls = [], []
|
|
217
|
+
@constants = {}
|
|
214
218
|
@i64_constants = nil
|
|
215
219
|
@f32_constants = nil
|
|
216
220
|
@f64_constants = nil
|
|
@@ -260,6 +264,26 @@ module Wardite
|
|
|
260
264
|
IR.new(functions, entries: @entries, hosts: linked.hosts)
|
|
261
265
|
end
|
|
262
266
|
|
|
267
|
+
# Replay the original declarations without re-linking host functions,
|
|
268
|
+
# executing start, or consulting live global/memory/table slots.
|
|
269
|
+
# @rbs linked: IR
|
|
270
|
+
# @rbs bytes: String
|
|
271
|
+
# @rbs return: IR
|
|
272
|
+
def translate_source(linked, bytes)
|
|
273
|
+
@entries = linked.entries
|
|
274
|
+
bodies = BinaryLoader.decode_code_section(bytes).func_codes
|
|
275
|
+
types = @source.block_types
|
|
276
|
+
functions = [] #: Array[Wardite::Efflorescence::Function]
|
|
277
|
+
linked.entries.each_with_index do |entry, index|
|
|
278
|
+
next unless entry.kind == :defined
|
|
279
|
+
body = bodies.fetch(entry.defined_index)
|
|
280
|
+
body.check_features(types)
|
|
281
|
+
wasm = Wardite::WasmFunction.new(entry.parameter_types, entry.result_types, body)
|
|
282
|
+
functions << translate_function(wasm, index, functions.size)
|
|
283
|
+
end
|
|
284
|
+
IR.new(functions, entries: linked.entries, hosts: linked.hosts)
|
|
285
|
+
end
|
|
286
|
+
|
|
263
287
|
# @rbs wasm: Wardite::WasmFunction
|
|
264
288
|
# @rbs index: Integer
|
|
265
289
|
# @rbs pool_index: Integer
|
|
@@ -272,7 +296,8 @@ module Wardite
|
|
|
272
296
|
locals = [] #: Array[Symbol]
|
|
273
297
|
wasm.locals_type.each_with_index { |type, i| wasm.locals_count.fetch(i).times { locals << type } }
|
|
274
298
|
@function = Function.new(index, wasm.callsig, wasm.retsig, locals.size, local_types: locals, pool_index: pool_index)
|
|
275
|
-
@stack, @controls
|
|
299
|
+
@stack, @controls = [], []
|
|
300
|
+
@constants = {}
|
|
276
301
|
@i64_constants = nil
|
|
277
302
|
@f32_constants = nil
|
|
278
303
|
@f64_constants = nil
|
|
@@ -365,7 +390,7 @@ module Wardite
|
|
|
365
390
|
@stack << dst
|
|
366
391
|
when :global_get, :global_set
|
|
367
392
|
index = integer_operand(operands[0])
|
|
368
|
-
type = @
|
|
393
|
+
type = @source.globals.fetch(index).type
|
|
369
394
|
@function.uses_i64 = true if type == :i64
|
|
370
395
|
@function.uses_float = true if FloatBits.float_type?(type)
|
|
371
396
|
if code == :global_get
|
|
@@ -495,9 +520,8 @@ module Wardite
|
|
|
495
520
|
type_index = integer_operand(operands[0])
|
|
496
521
|
table_index = integer_operand(operands[1])
|
|
497
522
|
raise UnsupportedFeature, context("only call_indirect through table 0 is supported") unless table_index == 0
|
|
498
|
-
table
|
|
499
|
-
|
|
500
|
-
type = @instance.types[type_index] if type_index >= 0
|
|
523
|
+
fail_translation("call_indirect requires funcref table 0") unless @source.funcref_table
|
|
524
|
+
type = @source.types[type_index] if type_index >= 0
|
|
501
525
|
fail_translation("invalid indirect call type index #{type_index}") unless type
|
|
502
526
|
FunctionEntry.check_signature(type.callsig, type.retsig, "type #{type_index}")
|
|
503
527
|
@function.uses_dynamic_calls = true
|
|
@@ -564,7 +588,7 @@ module Wardite
|
|
|
564
588
|
@function.uses_store = true
|
|
565
589
|
if code == :global_get || code == :global_set
|
|
566
590
|
index = integer_operand(operands[0])
|
|
567
|
-
global = index >= 0 ? @
|
|
591
|
+
global = index >= 0 ? @source.globals[index] : nil
|
|
568
592
|
fail_translation("invalid global index #{index}") unless global
|
|
569
593
|
case global.type
|
|
570
594
|
when :i32
|
|
@@ -581,7 +605,7 @@ module Wardite
|
|
|
581
605
|
fail_translation("global.set on immutable global #{index}") if code == :global_set && !global.mutable
|
|
582
606
|
return
|
|
583
607
|
end
|
|
584
|
-
fail_translation("memory instruction requires memory 0")
|
|
608
|
+
fail_translation("memory instruction requires memory 0") unless @source.has_memory
|
|
585
609
|
alignment = MEMORY_WIDTHS[code]
|
|
586
610
|
if alignment
|
|
587
611
|
hint = integer_operand(operands[0])
|
|
@@ -590,8 +614,8 @@ module Wardite
|
|
|
590
614
|
fail_translation("invalid memory offset") unless offset >= 0 && offset <= 0xffffffff
|
|
591
615
|
elsif code == :memory_init
|
|
592
616
|
data_index = integer_operand(operands[0])
|
|
593
|
-
fail_translation("memory.init requires data count") unless @
|
|
594
|
-
count = @
|
|
617
|
+
fail_translation("memory.init requires data count") unless @source.has_data_count
|
|
618
|
+
count = @source.data_segments
|
|
595
619
|
fail_translation("invalid data index #{data_index}") unless data_index >= 0 && data_index < count
|
|
596
620
|
check_memory_index(integer_operand(operands[1]))
|
|
597
621
|
elsif code == :memory_copy
|
|
@@ -631,7 +655,13 @@ module Wardite
|
|
|
631
655
|
when :f64 then @f64_constants ||= {} #: Hash[Integer, Integer]
|
|
632
656
|
else @constants
|
|
633
657
|
end
|
|
634
|
-
|
|
658
|
+
# Keep the lookup on the original integer-keyed table in Spinel.
|
|
659
|
+
bits = Integer(value)
|
|
660
|
+
cached = constants[bits]
|
|
661
|
+
return cached if cached
|
|
662
|
+
slot = @function.allocate_constant(bits, type: type)
|
|
663
|
+
constants[bits] = slot
|
|
664
|
+
slot
|
|
635
665
|
end
|
|
636
666
|
|
|
637
667
|
# @rbs kind: Symbol
|
|
@@ -768,7 +798,7 @@ module Wardite
|
|
|
768
798
|
# @rbs return: Wardite::Efflorescence::Tag
|
|
769
799
|
def tag_at(index)
|
|
770
800
|
fail_translation("invalid tag index #{index}") if index < 0
|
|
771
|
-
@
|
|
801
|
+
@source.tags[index] || raise(TranslationError, context("invalid tag index #{index}"))
|
|
772
802
|
end
|
|
773
803
|
|
|
774
804
|
# Catch labels resolve before pushing the try_table's own label.
|
|
@@ -5,13 +5,14 @@ module Wardite
|
|
|
5
5
|
module Efflorescence
|
|
6
6
|
class VM
|
|
7
7
|
attr_reader :instance #: Wardite::Instance
|
|
8
|
-
|
|
8
|
+
# @rbs @preparer: FunctionPreparer?
|
|
9
9
|
attr_reader :metrics #: Wardite::Efflorescence::Metrics
|
|
10
10
|
attr_reader :mir_cache_hit #: bool
|
|
11
11
|
attr_reader :mir_cache #: Wardite::Efflorescence::MIRCache?
|
|
12
12
|
# Records a startup snapshot before the first WASI call outside its allowlist.
|
|
13
13
|
attr_accessor :snapshot #: Wardite::Efflorescence::Snapshot?
|
|
14
14
|
|
|
15
|
+
# @rbs @inspection_links: Wardite::Efflorescence::IR?
|
|
15
16
|
# @rbs @semantic_ir: Wardite::Efflorescence::IR?
|
|
16
17
|
# @rbs @optimized_ir: Wardite::Efflorescence::IR?
|
|
17
18
|
# @rbs @global_bits: Array[Integer]
|
|
@@ -21,8 +22,10 @@ module Wardite
|
|
|
21
22
|
# @rbs profile: bool
|
|
22
23
|
# @rbs mir_cache: Wardite::Efflorescence::MIRCache?
|
|
23
24
|
# @rbs cached_functions: Array[Function]?
|
|
25
|
+
# @rbs source_code: String?
|
|
26
|
+
# @rbs eager_mir: bool
|
|
24
27
|
# @rbs cache_checked: bool
|
|
25
|
-
def initialize(instance, disabled_optimizations: [], profile: false, mir_cache: nil, cached_functions: nil, cache_checked: false)
|
|
28
|
+
def initialize(instance, disabled_optimizations: [], profile: false, mir_cache: nil, cached_functions: nil, cache_checked: false, source_code: nil, eager_mir: false)
|
|
26
29
|
@instance = instance
|
|
27
30
|
@store_access = StoreAccess.new(instance.store)
|
|
28
31
|
@global_bits = []
|
|
@@ -44,16 +47,24 @@ module Wardite
|
|
|
44
47
|
@snapshot = nil
|
|
45
48
|
@active_frames = [] #: Array[Wardite::Efflorescence::Frame]
|
|
46
49
|
@depth = 0
|
|
47
|
-
|
|
50
|
+
@module_source = Translator::ModuleSource.new(instance, source_code)
|
|
51
|
+
translator = Translator.new(instance, @module_source)
|
|
48
52
|
linked = translator.link
|
|
53
|
+
@inspection_links = source_code ? linked.copy : nil
|
|
49
54
|
if mir_cache && !profile && !cache_checked
|
|
50
55
|
cached_functions = mir_cache.read_functions(instance)
|
|
51
56
|
end
|
|
52
57
|
@mir_cache_hit = !cached_functions.nil?
|
|
58
|
+
@preparer = nil
|
|
53
59
|
@ir = if cached_functions
|
|
54
60
|
IR.new(cached_functions, entries: linked.entries, hosts: linked.hosts)
|
|
61
|
+
elsif eager_mir || mir_cache || @module_source.code.nil?
|
|
62
|
+
build_mir(translator.translate(linked), profile, @module_source.code.nil?)
|
|
55
63
|
else
|
|
56
|
-
|
|
64
|
+
translator.translate(linked)
|
|
65
|
+
end
|
|
66
|
+
if cached_functions || (!eager_mir && !mir_cache && @module_source.code)
|
|
67
|
+
@preparer = FunctionPreparer.new(@ir, @configuration, @module_source.tags, profile, mir_cache)
|
|
57
68
|
end
|
|
58
69
|
if mir_cache && !profile && !@mir_cache_hit
|
|
59
70
|
mir_cache.write_ir(instance, @ir)
|
|
@@ -68,8 +79,21 @@ module Wardite
|
|
|
68
79
|
end
|
|
69
80
|
end
|
|
70
81
|
|
|
71
|
-
#
|
|
72
|
-
#
|
|
82
|
+
# Inspecting the executable IR requests every uncached function body.
|
|
83
|
+
# MIR2 consumers can still inspect pending cache slots individually.
|
|
84
|
+
# @rbs return: Wardite::Efflorescence::IR
|
|
85
|
+
def ir
|
|
86
|
+
prepare_all unless @mir_cache_hit
|
|
87
|
+
@ir
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# @rbs return: void
|
|
91
|
+
def prepare_all
|
|
92
|
+
preparer = @preparer
|
|
93
|
+
@ir.functions.each { |function| preparer.prepare(function) } if preparer
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Build both inspection views on first access. Execution keeps its own IR.
|
|
73
97
|
# @rbs return: Wardite::Efflorescence::IR
|
|
74
98
|
def semantic_ir
|
|
75
99
|
restore_inspection_ir unless @semantic_ir
|
|
@@ -89,7 +113,7 @@ module Wardite
|
|
|
89
113
|
!!export && export.kind == 0
|
|
90
114
|
end
|
|
91
115
|
|
|
92
|
-
#
|
|
116
|
+
# Box the result once, at the Ruby boundary.
|
|
93
117
|
# @rbs name: String|Symbol
|
|
94
118
|
# @rbs arguments: Array[Object]
|
|
95
119
|
# @rbs return: Wardite::wasmValue?
|
|
@@ -153,26 +177,34 @@ module Wardite
|
|
|
153
177
|
|
|
154
178
|
private
|
|
155
179
|
|
|
156
|
-
# @rbs
|
|
157
|
-
# @rbs linked: Wardite::Efflorescence::IR
|
|
180
|
+
# @rbs semantic: Wardite::Efflorescence::IR
|
|
158
181
|
# @rbs profile: bool
|
|
182
|
+
# @rbs inspect: bool
|
|
159
183
|
# @rbs return: Wardite::Efflorescence::IR
|
|
160
|
-
def build_mir(
|
|
161
|
-
|
|
162
|
-
optimized =
|
|
163
|
-
optimized.functions.each
|
|
184
|
+
def build_mir(semantic, profile, inspect)
|
|
185
|
+
optimizer = Optimizer.new(@configuration)
|
|
186
|
+
optimized = inspect ? optimizer.optimize(semantic) : optimizer.optimize_in_place(semantic)
|
|
187
|
+
optimized.functions.each do |function|
|
|
188
|
+
RegisterValidation.new.validate(function, optimized, tags: @module_source.tags)
|
|
189
|
+
optimizer.fuse_byte_sequences(function)
|
|
190
|
+
end
|
|
164
191
|
ir = profile ? Instrumentation.new.instrument(optimized) : optimized
|
|
165
192
|
Lowerer.new.compile(ir)
|
|
166
|
-
|
|
167
|
-
|
|
193
|
+
if inspect
|
|
194
|
+
@semantic_ir = semantic
|
|
195
|
+
@optimized_ir = optimized
|
|
196
|
+
end
|
|
168
197
|
ir
|
|
169
198
|
end
|
|
170
199
|
|
|
171
200
|
# @rbs return: void
|
|
172
201
|
def restore_inspection_ir
|
|
173
202
|
@mir_cache&.restore_all
|
|
174
|
-
linked = IR.new([], entries: @ir.entries, hosts: @ir.hosts)
|
|
175
|
-
|
|
203
|
+
linked = @inspection_links || IR.new([], entries: @ir.entries, hosts: @ir.hosts).copy
|
|
204
|
+
translator = Translator.new(@instance, @module_source)
|
|
205
|
+
bytes = @module_source.code
|
|
206
|
+
semantic = bytes ? translator.translate_source(linked, bytes) : translator.translate(linked)
|
|
207
|
+
build_mir(semantic, @profiling, true)
|
|
176
208
|
end
|
|
177
209
|
|
|
178
210
|
# @rbs name: String|Symbol
|
|
@@ -486,7 +518,7 @@ module Wardite
|
|
|
486
518
|
# @rbs return: Array[Wardite::Efflorescence::FramePool]
|
|
487
519
|
def new_pools
|
|
488
520
|
pools = [] #: Array[Wardite::Efflorescence::FramePool]
|
|
489
|
-
@ir.functions.each { |function| pools << FramePool.new(function, @reuse_frames, @
|
|
521
|
+
@ir.functions.each { |function| pools << FramePool.new(function, @reuse_frames, @preparer) }
|
|
490
522
|
pools
|
|
491
523
|
end
|
|
492
524
|
|
|
@@ -662,6 +694,41 @@ module Wardite
|
|
|
662
694
|
# Integer literal labels let Spinel emit a C switch. Keep the
|
|
663
695
|
# Opcode comments in sync; the dispatch contract test checks them.
|
|
664
696
|
case opcode
|
|
697
|
+
when 195 # Opcode::I32_TABLE_STORE8
|
|
698
|
+
address = (registers[instructions.fetch(pc + 2)] + registers[instructions.fetch(pc + 3)]) & 0xffffffff
|
|
699
|
+
registers[a] = address
|
|
700
|
+
byte = @store_access.load8_u(address, instructions.fetch(pc + 7))
|
|
701
|
+
registers[instructions.fetch(pc + 5)] = byte
|
|
702
|
+
@store_access.store(registers[instructions.fetch(pc + 10)], instructions.fetch(pc + 11), 1, byte)
|
|
703
|
+
registers[instructions.fetch(pc + 13)] = (registers[instructions.fetch(pc + 14)] + instructions.fetch(pc + 15)) & 0xffffffff
|
|
704
|
+
pc += 3 * Lowerer::WIDTH
|
|
705
|
+
when 196 # Opcode::I64_BYTE_LOOKUP
|
|
706
|
+
address = (registers[instructions.fetch(pc + 2)] + instructions.fetch(pc + 3)) & 0xffffffff
|
|
707
|
+
registers[a] = address
|
|
708
|
+
byte = @store_access.load8_u(address, 0)
|
|
709
|
+
registers[instructions.fetch(pc + 5)] = byte
|
|
710
|
+
table_address = (registers[instructions.fetch(pc + 10)] + byte) & 0xffffffff
|
|
711
|
+
registers[instructions.fetch(pc + 9)] = table_address
|
|
712
|
+
registers[instructions.fetch(pc + 13)] = @store_access.load8_u(table_address, 0)
|
|
713
|
+
pc += 3 * Lowerer::WIDTH
|
|
714
|
+
when 197 # Opcode::I32_BYTE_MUL_ADD
|
|
715
|
+
address = (registers[instructions.fetch(pc + 2)] + instructions.fetch(pc + 3)) & 0xffffffff
|
|
716
|
+
registers[a] = address
|
|
717
|
+
byte = @store_access.load8_u(address, 0)
|
|
718
|
+
registers[instructions.fetch(pc + 5)] = byte
|
|
719
|
+
# An unsigned byte times an unsigned i32 fits in Spinel's signed word.
|
|
720
|
+
product = (byte * instructions.fetch(pc + 11)) & 0xffffffff
|
|
721
|
+
registers[instructions.fetch(pc + 9)] = product
|
|
722
|
+
registers[instructions.fetch(pc + 13)] = (registers[instructions.fetch(pc + 14)] + product) & 0xffffffff
|
|
723
|
+
pc += 3 * Lowerer::WIDTH
|
|
724
|
+
when 198 # Opcode::I32_BYTE_ADD_STORE
|
|
725
|
+
byte = @store_access.load8_u(registers[instructions.fetch(pc + 2)], 0)
|
|
726
|
+
registers[a] = byte
|
|
727
|
+
sum = (byte + registers[instructions.fetch(pc + 7)]) & 0xffffffff
|
|
728
|
+
registers[instructions.fetch(pc + 5)] = sum
|
|
729
|
+
@store_access.store(registers[instructions.fetch(pc + 10)], 0, 1, sum)
|
|
730
|
+
registers[instructions.fetch(pc + 13)] = (registers[instructions.fetch(pc + 14)] + instructions.fetch(pc + 15)) & 0xffffffff
|
|
731
|
+
pc += 3 * Lowerer::WIDTH
|
|
665
732
|
when 0 # Opcode::COPY
|
|
666
733
|
b = instructions.fetch(pc + 2)
|
|
667
734
|
registers[a] = registers[b]
|
|
@@ -736,19 +803,20 @@ module Wardite
|
|
|
736
803
|
c = instructions.fetch(pc + 3)
|
|
737
804
|
value = registers[b]
|
|
738
805
|
registers[a] = (value ^ (value << c)) & 0xffffffff
|
|
806
|
+
# Spinel infers nullable operands. Keep branch targets and the loop PC integers.
|
|
739
807
|
when 8 # Opcode::BR
|
|
740
|
-
pc = a
|
|
808
|
+
pc = Integer(a)
|
|
741
809
|
next
|
|
742
810
|
when 9 # Opcode::BR_IF
|
|
743
811
|
b = instructions.fetch(pc + 2)
|
|
744
812
|
if registers[a] != 0
|
|
745
|
-
pc = b
|
|
813
|
+
pc = Integer(b)
|
|
746
814
|
next
|
|
747
815
|
end
|
|
748
816
|
when 19 # Opcode::BR_IF_ZERO
|
|
749
817
|
b = instructions.fetch(pc + 2)
|
|
750
818
|
if registers[a] == 0
|
|
751
|
-
pc = b
|
|
819
|
+
pc = Integer(b)
|
|
752
820
|
next
|
|
753
821
|
end
|
|
754
822
|
when 10 # Opcode::CALL
|
|
@@ -930,7 +998,7 @@ module Wardite
|
|
|
930
998
|
when 56 # Opcode::I32_LOAD8_U
|
|
931
999
|
b = instructions.fetch(pc + 2)
|
|
932
1000
|
c = instructions.fetch(pc + 3)
|
|
933
|
-
registers[a] = @store_access.
|
|
1001
|
+
registers[a] = @store_access.load8_u(registers[b], c)
|
|
934
1002
|
when 57 # Opcode::I32_LOAD16_S
|
|
935
1003
|
b = instructions.fetch(pc + 2)
|
|
936
1004
|
c = instructions.fetch(pc + 3)
|
|
@@ -964,50 +1032,50 @@ module Wardite
|
|
|
964
1032
|
@store_access.bulk(66, frame.function.memory_site(a), registers)
|
|
965
1033
|
when 69 # Opcode::I64_EQZ
|
|
966
1034
|
b = instructions.fetch(pc + 2)
|
|
967
|
-
registers[a] =
|
|
1035
|
+
registers[a] = registers.fetch(b) == 0 ? 1 : 0
|
|
968
1036
|
when 70 # Opcode::I32_WRAP_I64
|
|
969
1037
|
b = instructions.fetch(pc + 2)
|
|
970
|
-
registers[a] =
|
|
1038
|
+
registers[a] = registers.fetch(b) & 0xffffffff
|
|
971
1039
|
when 71 # Opcode::I64_EQ
|
|
972
1040
|
b = instructions.fetch(pc + 2)
|
|
973
1041
|
c = instructions.fetch(pc + 3)
|
|
974
|
-
registers[a] =
|
|
1042
|
+
registers[a] = registers.fetch(b) == registers.fetch(c) ? 1 : 0
|
|
975
1043
|
when 72 # Opcode::I64_NE
|
|
976
1044
|
b = instructions.fetch(pc + 2)
|
|
977
1045
|
c = instructions.fetch(pc + 3)
|
|
978
|
-
registers[a] =
|
|
1046
|
+
registers[a] = registers.fetch(b) != registers.fetch(c) ? 1 : 0
|
|
979
1047
|
when 73 # Opcode::I64_LTS
|
|
980
1048
|
b = instructions.fetch(pc + 2)
|
|
981
1049
|
c = instructions.fetch(pc + 3)
|
|
982
|
-
registers[a] =
|
|
1050
|
+
registers[a] = registers.fetch(b) < registers.fetch(c) ? 1 : 0
|
|
983
1051
|
when 74 # Opcode::I64_LTU
|
|
984
1052
|
b = instructions.fetch(pc + 2)
|
|
985
1053
|
c = instructions.fetch(pc + 3)
|
|
986
|
-
registers[a] =
|
|
1054
|
+
registers[a] = (registers.fetch(b) ^ I64Arithmetic::MIN) < (registers.fetch(c) ^ I64Arithmetic::MIN) ? 1 : 0
|
|
987
1055
|
when 75 # Opcode::I64_GTS
|
|
988
1056
|
b = instructions.fetch(pc + 2)
|
|
989
1057
|
c = instructions.fetch(pc + 3)
|
|
990
|
-
registers[a] =
|
|
1058
|
+
registers[a] = registers.fetch(b) > registers.fetch(c) ? 1 : 0
|
|
991
1059
|
when 76 # Opcode::I64_GTU
|
|
992
1060
|
b = instructions.fetch(pc + 2)
|
|
993
1061
|
c = instructions.fetch(pc + 3)
|
|
994
|
-
registers[a] =
|
|
1062
|
+
registers[a] = (registers.fetch(b) ^ I64Arithmetic::MIN) > (registers.fetch(c) ^ I64Arithmetic::MIN) ? 1 : 0
|
|
995
1063
|
when 77 # Opcode::I64_LES
|
|
996
1064
|
b = instructions.fetch(pc + 2)
|
|
997
1065
|
c = instructions.fetch(pc + 3)
|
|
998
|
-
registers[a] =
|
|
1066
|
+
registers[a] = registers.fetch(b) <= registers.fetch(c) ? 1 : 0
|
|
999
1067
|
when 78 # Opcode::I64_LEU
|
|
1000
1068
|
b = instructions.fetch(pc + 2)
|
|
1001
1069
|
c = instructions.fetch(pc + 3)
|
|
1002
|
-
registers[a] =
|
|
1070
|
+
registers[a] = (registers.fetch(b) ^ I64Arithmetic::MIN) <= (registers.fetch(c) ^ I64Arithmetic::MIN) ? 1 : 0
|
|
1003
1071
|
when 79 # Opcode::I64_GES
|
|
1004
1072
|
b = instructions.fetch(pc + 2)
|
|
1005
1073
|
c = instructions.fetch(pc + 3)
|
|
1006
|
-
registers[a] =
|
|
1074
|
+
registers[a] = registers.fetch(b) >= registers.fetch(c) ? 1 : 0
|
|
1007
1075
|
when 80 # Opcode::I64_GEU
|
|
1008
1076
|
b = instructions.fetch(pc + 2)
|
|
1009
1077
|
c = instructions.fetch(pc + 3)
|
|
1010
|
-
registers[a] =
|
|
1078
|
+
registers[a] = (registers.fetch(b) ^ I64Arithmetic::MIN) >= (registers.fetch(c) ^ I64Arithmetic::MIN) ? 1 : 0
|
|
1011
1079
|
when 81 # Opcode::I64_CLZ
|
|
1012
1080
|
b = instructions.fetch(pc + 2)
|
|
1013
1081
|
registers[a] = I64Arithmetic.calculate(81, registers[b], 0)
|
|
@@ -1019,51 +1087,51 @@ module Wardite
|
|
|
1019
1087
|
registers[a] = I64Arithmetic.calculate(83, registers[b], 0)
|
|
1020
1088
|
when 84 # Opcode::I64_EXTEND8_S
|
|
1021
1089
|
b = instructions.fetch(pc + 2)
|
|
1022
|
-
registers[a] =
|
|
1090
|
+
registers[a] = ((registers.fetch(b) & 0xff) ^ 0x80) - 0x80
|
|
1023
1091
|
when 85 # Opcode::I64_EXTEND16_S
|
|
1024
1092
|
b = instructions.fetch(pc + 2)
|
|
1025
|
-
registers[a] =
|
|
1093
|
+
registers[a] = ((registers.fetch(b) & 0xffff) ^ 0x8000) - 0x8000
|
|
1026
1094
|
when 86 # Opcode::I64_EXTEND32_S
|
|
1027
1095
|
b = instructions.fetch(pc + 2)
|
|
1028
|
-
registers[a] =
|
|
1096
|
+
registers[a] = ((registers.fetch(b) & 0xffffffff) ^ 0x80000000) - 0x80000000
|
|
1029
1097
|
when 87 # Opcode::I64_EXTEND_I32_S
|
|
1030
1098
|
b = instructions.fetch(pc + 2)
|
|
1031
|
-
registers[a] =
|
|
1099
|
+
registers[a] = ((registers.fetch(b) & 0xffffffff) ^ 0x80000000) - 0x80000000
|
|
1032
1100
|
when 88 # Opcode::I64_EXTEND_I32_U
|
|
1033
1101
|
b = instructions.fetch(pc + 2)
|
|
1034
|
-
registers[a] =
|
|
1102
|
+
registers[a] = registers.fetch(b)
|
|
1035
1103
|
when 89 # Opcode::I64_AND
|
|
1036
1104
|
b = instructions.fetch(pc + 2)
|
|
1037
1105
|
c = instructions.fetch(pc + 3)
|
|
1038
|
-
registers[a] =
|
|
1106
|
+
registers[a] = registers.fetch(b) & registers.fetch(c)
|
|
1039
1107
|
when 90 # Opcode::I64_OR
|
|
1040
1108
|
b = instructions.fetch(pc + 2)
|
|
1041
1109
|
c = instructions.fetch(pc + 3)
|
|
1042
|
-
registers[a] =
|
|
1110
|
+
registers[a] = registers.fetch(b) | registers.fetch(c)
|
|
1043
1111
|
when 91 # Opcode::I64_XOR
|
|
1044
1112
|
b = instructions.fetch(pc + 2)
|
|
1045
1113
|
c = instructions.fetch(pc + 3)
|
|
1046
|
-
registers[a] =
|
|
1114
|
+
registers[a] = registers.fetch(b) ^ registers.fetch(c)
|
|
1047
1115
|
when 92 # Opcode::I64_SHL
|
|
1048
1116
|
b = instructions.fetch(pc + 2)
|
|
1049
1117
|
c = instructions.fetch(pc + 3)
|
|
1050
|
-
registers[a] = I64Arithmetic.
|
|
1118
|
+
registers[a] = I64Arithmetic.flat_shl(Integer(registers.fetch(b)), registers.fetch(c) & 63)
|
|
1051
1119
|
when 93 # Opcode::I64_SHR_S
|
|
1052
1120
|
b = instructions.fetch(pc + 2)
|
|
1053
1121
|
c = instructions.fetch(pc + 3)
|
|
1054
|
-
registers[a] =
|
|
1122
|
+
registers[a] = registers.fetch(b) >> (registers.fetch(c) & 63)
|
|
1055
1123
|
when 94 # Opcode::I64_SHR_U
|
|
1056
1124
|
b = instructions.fetch(pc + 2)
|
|
1057
1125
|
c = instructions.fetch(pc + 3)
|
|
1058
|
-
registers[a] = I64Arithmetic.
|
|
1126
|
+
registers[a] = I64Arithmetic.flat_shr_u(Integer(registers.fetch(b)), registers.fetch(c) & 63)
|
|
1059
1127
|
when 95 # Opcode::I64_ROTL
|
|
1060
1128
|
b = instructions.fetch(pc + 2)
|
|
1061
1129
|
c = instructions.fetch(pc + 3)
|
|
1062
|
-
registers[a] = I64Arithmetic.
|
|
1130
|
+
registers[a] = I64Arithmetic.flat_rotl(Integer(registers.fetch(b)), registers.fetch(c) & 63)
|
|
1063
1131
|
when 96 # Opcode::I64_ROTR
|
|
1064
1132
|
b = instructions.fetch(pc + 2)
|
|
1065
1133
|
c = instructions.fetch(pc + 3)
|
|
1066
|
-
registers[a] = I64Arithmetic.
|
|
1134
|
+
registers[a] = I64Arithmetic.flat_rotl(Integer(registers.fetch(b)), (-(registers.fetch(c) & 63)) & 63)
|
|
1067
1135
|
when 97 # Opcode::I64_ADD
|
|
1068
1136
|
b = instructions.fetch(pc + 2)
|
|
1069
1137
|
c = instructions.fetch(pc + 3)
|
|
@@ -1103,7 +1171,7 @@ module Wardite
|
|
|
1103
1171
|
when 106 # Opcode::I64_LOAD8_U
|
|
1104
1172
|
b = instructions.fetch(pc + 2)
|
|
1105
1173
|
c = instructions.fetch(pc + 3)
|
|
1106
|
-
registers[a] = @store_access.
|
|
1174
|
+
registers[a] = @store_access.load8_u(registers[b], c)
|
|
1107
1175
|
when 107 # Opcode::I64_LOAD16_S
|
|
1108
1176
|
b = instructions.fetch(pc + 2)
|
|
1109
1177
|
c = instructions.fetch(pc + 3)
|
|
@@ -5,10 +5,13 @@ require_relative "efflorescence/float_arithmetic"
|
|
|
5
5
|
require_relative "efflorescence/ir"
|
|
6
6
|
require_relative "efflorescence/store_access"
|
|
7
7
|
require_relative "efflorescence/translator"
|
|
8
|
+
require_relative "efflorescence/byte_sequences"
|
|
8
9
|
require_relative "efflorescence/optimizer"
|
|
9
10
|
require_relative "efflorescence/register_validation"
|
|
10
11
|
require_relative "efflorescence/inspection"
|
|
11
12
|
require_relative "efflorescence/vm"
|
|
13
|
+
require_relative "efflorescence/translation_source"
|
|
14
|
+
require_relative "efflorescence/function_preparer"
|
|
12
15
|
|
|
13
16
|
# Spinel initializes the cache tables at startup, after Opcode is defined.
|
|
14
17
|
if RUBY_ENGINE == "spinel"
|