wardite 1.2.1 → 1.2.2
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 +12 -11
- data/benchmark/README.md +5 -5
- data/benchmark/call_cost_worker.rb +1 -1
- data/benchmark/compare.rb +2 -2
- data/benchmark/compare_engines.rb +1 -1
- data/benchmark/engine_phases.rb +1 -1
- data/benchmark/investigate_calls.rb +1 -1
- data/benchmark/optimization_worker.rb +1 -1
- data/benchmark/validate_m4.rb +1 -1
- data/docs/efflorescence-ja.md +5 -6
- data/docs/efflorescence.md +8 -7
- data/lib/wardite/cli/cli.rb +7 -4
- data/lib/wardite/load.rb +1 -1
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b9acbd0ed033b8f0c6da77501ec5fb8a5840133ab15cb2a1ac031aba04eb20d
|
|
4
|
+
data.tar.gz: 9820acbfc819c417edecc0fdbdea3cd5f35cec8965dd6b12bf45917a68c63707
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87567e5c58345ee263a6eecf8fc9fc2a76f136898d0a2a59a0010c1ea488c4e2e5c9a2c97d9a218dc03bdaf2696907c3db46fa1806f5815b58ce2ef8cc7e60c8
|
|
7
|
+
data.tar.gz: 0da3f82b16f3aa28ab74df0eb3ed16dfb46c1bea780de9f55b7e434bdd1e3c964f10e752fd0cad81def9f83212b9afa07962ca695ca38422174c99264e417ec4
|
data/README.md
CHANGED
|
@@ -60,18 +60,19 @@ $ wardite examples/test.wasm
|
|
|
60
60
|
#=> Test!
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
### Efflorescence register VM
|
|
63
|
+
### Efflorescence register VM
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
The CLI and Ruby API default to the MIR-based Efflorescence register VM. The
|
|
66
|
+
CRuby and Spinel CLIs still accept `--new-engine` for compatibility. Use
|
|
67
|
+
`--stack-engine` to select the legacy stack VM.
|
|
67
68
|
|
|
68
69
|
```sh
|
|
69
|
-
wardite --
|
|
70
|
+
wardite --no-wasi --invoke add test/add.wasm 100 200
|
|
70
71
|
# return value: I32(300)
|
|
71
72
|
```
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
`BinaryLoader.load_from_buffer`.
|
|
74
|
+
To select the legacy stack VM in Ruby, pass `engine: :stack` to `Wardite.new` or
|
|
75
|
+
`BinaryLoader.load_from_buffer`. Efflorescence reports unsupported instructions with an explicit
|
|
75
76
|
exception. See the [design, supported subset and tests](docs/efflorescence.md)
|
|
76
77
|
and [engine comparison benchmark](benchmark/README.md).
|
|
77
78
|
|
|
@@ -82,11 +83,11 @@ Use `--mir-disable NAME` to compare
|
|
|
82
83
|
individual features, `--mir-dump` to inspect MIR and `--mir-profile` for counters.
|
|
83
84
|
See [Phase 2](docs/efflorescence-phase2.md) ([日本語](docs/efflorescence-phase2-ja.md)).
|
|
84
85
|
|
|
85
|
-
On CRuby and Spinel, pass `--mir-cache DIR`
|
|
86
|
+
On CRuby and Spinel, pass `--mir-cache DIR` to reuse lowered
|
|
86
87
|
MIR across processes. Use a local directory you control. Each run still decodes
|
|
87
88
|
the Wasm, links imports, and initializes a fresh instance. `--mir-dump` and
|
|
88
|
-
`--mir-profile` build MIR normally. Ruby callers can pass `mir_cache: dir
|
|
89
|
-
|
|
89
|
+
`--mir-profile` build MIR normally. Ruby callers can pass `mir_cache: dir`.
|
|
90
|
+
CRuby and Spinel use different cache keys.
|
|
90
91
|
|
|
91
92
|
The default `--mir-cache-verify checksum` checks the payload size and samples
|
|
92
93
|
blocks. Use `--mir-cache-verify sha256` or Ruby's `mir_cache_verify: :sha256`
|
|
@@ -99,7 +100,7 @@ can go undetected in checksum mode, including changes that leave the MIR
|
|
|
99
100
|
structurally valid.
|
|
100
101
|
[MIR2 cache measurements](docs/efflorescence-mir2-cache.md)
|
|
101
102
|
|
|
102
|
-
For WASI commands, `--snapshot DIR` (with `--
|
|
103
|
+
For WASI commands, `--snapshot DIR` (with `--mir-cache DIR`) saves
|
|
103
104
|
the guest state just before its first WASI call that reads files or writes output,
|
|
104
105
|
and later runs with the same Wasm, arguments, environment, preopens and stdio
|
|
105
106
|
kinds resume from there. Clock values and random bytes read before that point
|
|
@@ -159,7 +160,7 @@ $ make spinel-test
|
|
|
159
160
|
|
|
160
161
|
The executable enables the shared WASI Preview 1 host by default. Use
|
|
161
162
|
`--no-wasi` to disable it. To boot a Ruby 4.0.9 WASI binary, run
|
|
162
|
-
`build/wardite --
|
|
163
|
+
`build/wardite -- "$ruby_wasm" --disable-gems -e 'puts 6*7'`.
|
|
163
164
|
See the [ruby.wasm verification record](docs/efflorescence-ruby-wasm-phase1.md)
|
|
164
165
|
for the build and file-loading commands. Vernier profiling is available in the
|
|
165
166
|
CRuby build. Ruby's dynamic export helpers (`instance.add(...)` and
|
data/benchmark/README.md
CHANGED
|
@@ -184,7 +184,7 @@ The report `build/benchmark/optimizations.json` contains raw samples, phase and
|
|
|
184
184
|
whole-process means, CRuby execution allocations and per-opcode counters.
|
|
185
185
|
Time measurement does not enable MIR counters. Both phase and CLI measurements
|
|
186
186
|
include the same Ruby-facing boxed return boundary. Spinel allocations are `n/a`.
|
|
187
|
-
The shared phase loader creates the
|
|
187
|
+
The shared phase loader creates the stack VM, then the selected MIR VM is
|
|
188
188
|
constructed in the MIR phase; the fixture has no start function. Phase timing
|
|
189
189
|
uses a separate executable, whose Spinel inference can differ from the CLI.
|
|
190
190
|
`SPINEL` and `SPINELFLAGS` choose the compiler/flags (default `-O2`).
|
|
@@ -323,11 +323,11 @@ Results include whole CLI process time and separate load, MIR translation and
|
|
|
323
323
|
execution times from `engine_phases.rb`, compiled unchanged by Spinel. Phase
|
|
324
324
|
timings come from a separate process per sample, with one call per process;
|
|
325
325
|
they include frame setup and the final Ruby-facing result box. The loader phase
|
|
326
|
-
creates the shared instance with the
|
|
326
|
+
creates the shared instance with the stack VM; the fixture has no start
|
|
327
327
|
function, so it executes no guest instructions. For Efflorescence, the next
|
|
328
328
|
phase constructs the selected VM from that instance (including a second, empty
|
|
329
329
|
Runtime setup for stack samples). End-to-end samples use the real
|
|
330
|
-
CLI
|
|
330
|
+
CLI and include engine selection, startup,
|
|
331
331
|
load, translation, execution and output. Warmups are separate processes, so YJIT
|
|
332
332
|
compiles anew for each sample. Native compilation is outside measurement.
|
|
333
333
|
Phase values are diagnostic and do not sum to the CLI time: they use a separate
|
|
@@ -409,8 +409,8 @@ YJIT support is required only when its runner is enabled.
|
|
|
409
409
|
|
|
410
410
|
| Engine | Execution configurations |
|
|
411
411
|
| --- | --- |
|
|
412
|
-
| Old VM (`Wardite::Runtime`) | CRuby (YJIT disabled), CRuby + YJIT, Spinel |
|
|
413
|
-
| New VM (`Wardite::Efflorescence::VM`) | CRuby (YJIT disabled), CRuby + YJIT, Spinel;
|
|
412
|
+
| Old VM (`Wardite::Runtime`) | CRuby (YJIT disabled), CRuby + YJIT, Spinel; `--stack-engine` |
|
|
413
|
+
| New VM (`Wardite::Efflorescence::VM`) | CRuby (YJIT disabled), CRuby + YJIT, Spinel; default engine and optimizations |
|
|
414
414
|
| iwasm / WAMR | Explicit interpreter mode (`--interp`) |
|
|
415
415
|
| Wasmtime (Pulley) | `--target pulley64 -C cache=n` |
|
|
416
416
|
| Wasmtime | Native compilation, `-C cache=n` |
|
|
@@ -13,7 +13,7 @@ disabled = ARGV.fetch(4, "").split(",").map { |name| name.to_sym }
|
|
|
13
13
|
profile = ARGV.fetch(5, "time") == "metrics"
|
|
14
14
|
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
15
15
|
instance = File.open(wasm, "rb") do |file|
|
|
16
|
-
Wardite::BinaryLoader.load_from_buffer(file, enable_wasi: false)
|
|
16
|
+
Wardite::BinaryLoader.load_from_buffer(file, enable_wasi: false, engine: :stack)
|
|
17
17
|
end
|
|
18
18
|
loaded = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
19
19
|
vm = Wardite::Efflorescence::VM.new(instance, disabled_optimizations: disabled, profile: profile)
|
data/benchmark/compare.rb
CHANGED
|
@@ -37,8 +37,8 @@ wardite_runners = {
|
|
|
37
37
|
}
|
|
38
38
|
runners = {}
|
|
39
39
|
wardite_runners.each do |runtime, command|
|
|
40
|
-
# runners["Old VM / #{runtime}"] = [:wardite, command]
|
|
41
|
-
runners["New VM / #{runtime}"] = [:wardite, command
|
|
40
|
+
# runners["Old VM / #{runtime}"] = [:wardite, command + ["--stack-engine"]]
|
|
41
|
+
runners["New VM / #{runtime}"] = [:wardite, command]
|
|
42
42
|
end
|
|
43
43
|
runners["iwasm (WAMR interpreter)"] = [:iwasm, ["iwasm", "--interp"]]
|
|
44
44
|
runners["Wasmtime (Pulley)"] = [:wasmtime, ["wasmtime", "run", "--target", "pulley64", "-C", "cache=n"]]
|
|
@@ -44,7 +44,7 @@ runtimes["CRuby + YJIT"] = [RbConfig.ruby, "--yjit", "-Ilib"] if yjit.success?
|
|
|
44
44
|
def cli_command(runner, engine, export, wasm, rounds, seed)
|
|
45
45
|
command = runner.dup
|
|
46
46
|
command << "exe/wardite" unless runner.first == "./build/wardite"
|
|
47
|
-
command << "--
|
|
47
|
+
command << "--stack-engine" if engine == "stack"
|
|
48
48
|
command + ["--no-wasi", "--invoke", export, "--", wasm, rounds.to_s, seed.to_s]
|
|
49
49
|
end
|
|
50
50
|
|
data/benchmark/engine_phases.rb
CHANGED
|
@@ -12,7 +12,7 @@ rounds = ARGV.fetch(3).to_i
|
|
|
12
12
|
seed = ARGV.fetch(4).to_i
|
|
13
13
|
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
14
14
|
instance = File.open(wasm, "rb") do |file|
|
|
15
|
-
Wardite::BinaryLoader.load_from_buffer(file, enable_wasi: false)
|
|
15
|
+
Wardite::BinaryLoader.load_from_buffer(file, enable_wasi: false, engine: :stack)
|
|
16
16
|
end
|
|
17
17
|
loaded = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
18
18
|
if engine == "efflorescence"
|
|
@@ -150,7 +150,7 @@ validation_worker = "#{output}/validate.rb"
|
|
|
150
150
|
File.write(validation_worker, <<~RUBY)
|
|
151
151
|
require "wardite"
|
|
152
152
|
wasm, rounds, seed = ARGV
|
|
153
|
-
instance = File.open(wasm, "rb") { |file| Wardite::BinaryLoader.load_from_buffer(file, enable_wasi: false) }
|
|
153
|
+
instance = File.open(wasm, "rb") { |file| Wardite::BinaryLoader.load_from_buffer(file, enable_wasi: false, engine: :stack) }
|
|
154
154
|
#{exports.inspect}.each { |name| puts "\#{name},\#{instance.runtime.call(name, [rounds.to_i, seed.to_i]).value}" }
|
|
155
155
|
RUBY
|
|
156
156
|
validation.each do |count, initial|
|
|
@@ -10,7 +10,7 @@ seed = ARGV.fetch(3).to_i
|
|
|
10
10
|
disabled = ARGV.fetch(4, "").split(",").map { |name| name.to_sym }
|
|
11
11
|
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
12
12
|
instance = File.open(wasm, "rb") do |file|
|
|
13
|
-
Wardite::BinaryLoader.load_from_buffer(file, enable_wasi: false)
|
|
13
|
+
Wardite::BinaryLoader.load_from_buffer(file, enable_wasi: false, engine: :stack)
|
|
14
14
|
end
|
|
15
15
|
loaded = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
16
16
|
vm = Wardite::Efflorescence::VM.new(instance, disabled_optimizations: disabled)
|
data/benchmark/validate_m4.rb
CHANGED
|
@@ -90,6 +90,6 @@ Dir.mktmpdir("wardite-m4-reference") do |dir|
|
|
|
90
90
|
WAT
|
|
91
91
|
compare(dir, "indirect", indirect, [["indirect", 0, MIN, MIN + 1], ["indirect", 1, MIN, "type"],
|
|
92
92
|
["legacy_wrapper", 1, MIN + 1]])
|
|
93
|
-
stack = Wardite.new(path: File.join(dir, "indirect.wasm"), enable_wasi: false).runtime
|
|
93
|
+
stack = Wardite.new(path: File.join(dir, "indirect.wasm"), enable_wasi: false, engine: :stack).runtime
|
|
94
94
|
abort "legacy wrapper mismatch" unless stack.call("legacy_wrapper", [1]).value_s == MIN + 1
|
|
95
95
|
end
|
data/docs/efflorescence-ja.md
CHANGED
|
@@ -10,17 +10,16 @@
|
|
|
10
10
|
[Phase 2の最適化](efflorescence-phase2-ja.md)がデフォルトで有効になります。
|
|
11
11
|
`--mir-disable all` で、最適化していないMIRをflatへ変換して実行します。
|
|
12
12
|
実行器はflatに統一され、flatを切り替える最適化フラグはありません。
|
|
13
|
-
Wardite全体のデフォルトは、引き続き既存のスタックVMです。
|
|
14
13
|
|
|
15
|
-
Efflorescence
|
|
16
|
-
|
|
14
|
+
Efflorescenceは、Warditeの既定のPure Ruby製レジスタ型インタプリタです。
|
|
15
|
+
従来のスタックVMは、CLIでは `--stack-engine`、Rubyでは `engine: :stack` で選択できます。
|
|
17
16
|
両エンジンはバイナリローダー、デコード済みのWasm命令、ストア、エクスポート情報を共有しますが、
|
|
18
17
|
実行処理は独立しています。
|
|
19
18
|
|
|
20
19
|
```sh
|
|
21
20
|
wasm-tools parse benchmark/i32_mix.wat -o build/i32_mix.wasm
|
|
22
|
-
ruby -Ilib exe/wardite --
|
|
23
|
-
ruby -Ilib exe/wardite --
|
|
21
|
+
ruby -Ilib exe/wardite --no-wasi --invoke inline_mix build/i32_mix.wasm 100000 123
|
|
22
|
+
ruby -Ilib exe/wardite --no-wasi --invoke call_mix build/i32_mix.wasm 100000 123
|
|
24
23
|
# どちらも: return value: I32(-424175775)
|
|
25
24
|
```
|
|
26
25
|
|
|
@@ -28,7 +27,7 @@ Ruby APIで同じ処理を行う場合は、次のように呼び出します。
|
|
|
28
27
|
|
|
29
28
|
```ruby
|
|
30
29
|
require "wardite"
|
|
31
|
-
instance = Wardite.new(path: "build/i32_mix.wasm", enable_wasi: false
|
|
30
|
+
instance = Wardite.new(path: "build/i32_mix.wasm", enable_wasi: false)
|
|
32
31
|
instance.runtime.call("call_mix", [100000, 123]) # Runtimeと同じくWardite::I32を返す
|
|
33
32
|
instance.runtime.call_unboxed("call_mix", [100000, 123]) # 3870791521 (Integer)
|
|
34
33
|
```
|
data/docs/efflorescence.md
CHANGED
|
@@ -10,16 +10,17 @@ The Phase 1 limitations below are historical.
|
|
|
10
10
|
|
|
11
11
|
This document records Phase 1 (`67fbfae`). Current Efflorescence enables the
|
|
12
12
|
[Phase 2 optimizations](efflorescence-phase2.md) by default; `--mir-disable all`
|
|
13
|
-
selects unoptimized MIR lowered to the same flat bytecode executor.
|
|
13
|
+
selects unoptimized MIR lowered to the same flat bytecode executor.
|
|
14
14
|
|
|
15
|
-
Efflorescence is Wardite's
|
|
16
|
-
|
|
17
|
-
loader, decoded Wasm instructions, store and
|
|
15
|
+
Efflorescence is Wardite's default pure Ruby register interpreter. Select the
|
|
16
|
+
legacy stack VM with `--stack-engine` in the CLI or `engine: :stack` in Ruby.
|
|
17
|
+
Both engines share the binary loader, decoded Wasm instructions, store and
|
|
18
|
+
exports. Each engine executes independently.
|
|
18
19
|
|
|
19
20
|
```sh
|
|
20
21
|
wasm-tools parse benchmark/i32_mix.wat -o build/i32_mix.wasm
|
|
21
|
-
ruby -Ilib exe/wardite --
|
|
22
|
-
ruby -Ilib exe/wardite --
|
|
22
|
+
ruby -Ilib exe/wardite --no-wasi --invoke inline_mix build/i32_mix.wasm 100000 123
|
|
23
|
+
ruby -Ilib exe/wardite --no-wasi --invoke call_mix build/i32_mix.wasm 100000 123
|
|
23
24
|
# Both: return value: I32(-424175775)
|
|
24
25
|
```
|
|
25
26
|
|
|
@@ -27,7 +28,7 @@ The equivalent Ruby API is:
|
|
|
27
28
|
|
|
28
29
|
```ruby
|
|
29
30
|
require "wardite"
|
|
30
|
-
instance = Wardite.new(path: "build/i32_mix.wasm", enable_wasi: false
|
|
31
|
+
instance = Wardite.new(path: "build/i32_mix.wasm", enable_wasi: false)
|
|
31
32
|
instance.runtime.call("call_mix", [100000, 123]) # Wardite::I32, same as Runtime
|
|
32
33
|
instance.runtime.call_unboxed("call_mix", [100000, 123]) # 3870791521 (Integer)
|
|
33
34
|
```
|
data/lib/wardite/cli/cli.rb
CHANGED
|
@@ -37,7 +37,7 @@ module Wardite
|
|
|
37
37
|
@invoke = @mapdir = nil
|
|
38
38
|
@wasi = true
|
|
39
39
|
@yjit = false
|
|
40
|
-
@new_engine =
|
|
40
|
+
@new_engine = true
|
|
41
41
|
@disabled_optimizations = []
|
|
42
42
|
@mir_dump = false
|
|
43
43
|
@mir_profile = false
|
|
@@ -61,9 +61,12 @@ module Wardite
|
|
|
61
61
|
opts.on("--no-wasi", "Disable WASI feature") {|_v|
|
|
62
62
|
@wasi = false
|
|
63
63
|
}
|
|
64
|
-
opts.on("--new-engine", "Use
|
|
64
|
+
opts.on("--new-engine", "Use Efflorescence (default; kept for compatibility)") {|_v|
|
|
65
65
|
@new_engine = true
|
|
66
66
|
}
|
|
67
|
+
opts.on("--stack-engine", "Use the legacy stack VM") {|_v|
|
|
68
|
+
@new_engine = false
|
|
69
|
+
}
|
|
67
70
|
opts.on("--mir-disable NAME", "Disable copy, immediate, branch, superinstruction, inline, frames, or all (repeatable)") {|v|
|
|
68
71
|
@disabled_optimizations << v.to_sym
|
|
69
72
|
}
|
|
@@ -88,10 +91,10 @@ module Wardite
|
|
|
88
91
|
end
|
|
89
92
|
options.parse!(args)
|
|
90
93
|
if !new_engine && (!disabled_optimizations.empty? || mir_dump || mir_profile || mir_cache)
|
|
91
|
-
raise "MIR options require
|
|
94
|
+
raise "MIR options require Efflorescence"
|
|
92
95
|
end
|
|
93
96
|
if snapshot && (!new_engine || !mir_cache || mir_dump || mir_profile)
|
|
94
|
-
raise "--snapshot requires --
|
|
97
|
+
raise "--snapshot requires --mir-cache and Efflorescence, without --mir-dump or --mir-profile"
|
|
95
98
|
end
|
|
96
99
|
@file = args[0] || raise("require file argument")
|
|
97
100
|
@args = (args[1..-1] || [])
|
data/lib/wardite/load.rb
CHANGED
|
@@ -395,7 +395,7 @@ module Wardite
|
|
|
395
395
|
# @rbs mir_cache_verify: Symbol
|
|
396
396
|
# @rbs mir_cache_eager: bool
|
|
397
397
|
# @rbs return: Instance
|
|
398
|
-
def self.load_from_buffer(buf, import_object: {}, enable_wasi: true, engine: :
|
|
398
|
+
def self.load_from_buffer(buf, import_object: {}, enable_wasi: true, engine: :efflorescence, disabled_optimizations: [], mir_profile: false, mir_cache: nil, mir_cache_verify: :checksum, mir_cache_eager: false)
|
|
399
399
|
start = Time.now.to_f #: Float
|
|
400
400
|
unless mir_cache_verify == :checksum || mir_cache_verify == :sha256
|
|
401
401
|
raise ArgumentError, "MIR cache verification must be checksum or sha256"
|
data/lib/wardite/version.rb
CHANGED
data/lib/wardite.rb
CHANGED
|
@@ -50,7 +50,7 @@ module Wardite
|
|
|
50
50
|
# @rbs mir_profile: bool
|
|
51
51
|
# @rbs mir_cache: Efflorescence::MIRCache?
|
|
52
52
|
# @rbs &blk: (Instance) -> void
|
|
53
|
-
def initialize(import_object, engine: :
|
|
53
|
+
def initialize(import_object, engine: :efflorescence, disabled_optimizations: [], mir_profile: false, mir_cache: nil, &blk)
|
|
54
54
|
@wasi = nil
|
|
55
55
|
|
|
56
56
|
blk.call(self)
|