wardite 0.9.0 → 1.1.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 +107 -2
- data/Rakefile +5 -0
- data/Steepfile +1 -0
- data/assets/wardite.svg +12 -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_mir_cache_verify.rb +58 -0
- data/benchmark/measure_ruby_wasm_cache_hit.rb +59 -0
- data/benchmark/measure_ruby_wasm_startup.rb +43 -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/efflorescence-mir2-cache-integrity.json +390 -0
- data/benchmark/results/efflorescence-unboxed-globals.json +3451 -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/adr/0007-efflorescence-ruby-wasm-phase1.md +75 -0
- data/docs/adr/0008-efflorescence-ruby-wasm-phase2.md +75 -0
- data/docs/adr/0009-efflorescence-mir2-cache-integrity-modes.md +77 -0
- data/docs/adr/0010-efflorescence-mir2-cache-function-restore.md +80 -0
- data/docs/adr/0011-efflorescence-unboxed-globals.md +89 -0
- data/docs/adr/0012-efflorescence-startup-snapshot.md +173 -0
- data/docs/adr/0013-efflorescence-frame-acquisition.md +114 -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 +410 -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-mir2-cache.md +123 -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-ruby-wasm-phase1.md +90 -0
- data/docs/efflorescence-spinel-linear-memory.md +72 -0
- data/docs/efflorescence-startup-snapshot.md +60 -0
- data/docs/efflorescence-unboxed-globals.md +61 -0
- data/docs/efflorescence.md +144 -0
- data/docs/spinel-string-aset-inplace-proposal.md +200 -0
- data/lib/wardite/alu_f32.generated.rb +11 -2
- data/lib/wardite/alu_f64.generated.rb +11 -2
- data/lib/wardite/alu_i32.generated.rb +54 -17
- data/lib/wardite/alu_i64.generated.rb +73 -31
- data/lib/wardite/cli/cli.rb +112 -29
- data/lib/wardite/const.rb +1 -0
- 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 +1164 -0
- data/lib/wardite/efflorescence/mir_cache.rb +657 -0
- data/lib/wardite/efflorescence/optimizer.rb +580 -0
- data/lib/wardite/efflorescence/register_validation.rb +362 -0
- data/lib/wardite/efflorescence/snapshot.rb +229 -0
- data/lib/wardite/efflorescence/store_access.rb +366 -0
- data/lib/wardite/efflorescence/translator.rb +866 -0
- data/lib/wardite/efflorescence/vm.rb +1170 -0
- data/lib/wardite/efflorescence/wasi.rb +52 -0
- data/lib/wardite/efflorescence.rb +17 -0
- data/lib/wardite/errors.rb +20 -0
- data/lib/wardite/float_bits.rb +46 -0
- data/lib/wardite/instruction.rb +35 -4
- data/lib/wardite/leb128.rb +33 -12
- data/lib/wardite/load.rb +292 -143
- 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/wasi/spinel.rb +41 -0
- data/lib/wardite/wasi.rb +483 -268
- data/lib/wardite/wasm_module.rb +6 -3
- data/lib/wardite.rb +360 -98
- data/rbs_collection.lock.yaml +36 -96
- data/scripts/gen_alu.rb +121 -21
- data/scripts/verify_ruby_wasm.rb +70 -0
- data/sig/generated/wardite/cli/cli.rbs +23 -6
- data/sig/generated/wardite/const.rbs +2 -0
- 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 +888 -0
- data/sig/generated/wardite/efflorescence/mir_cache.rbs +236 -0
- data/sig/generated/wardite/efflorescence/optimizer.rbs +189 -0
- data/sig/generated/wardite/efflorescence/register_validation.rbs +104 -0
- data/sig/generated/wardite/efflorescence/snapshot.rbs +83 -0
- data/sig/generated/wardite/efflorescence/store_access.rbs +145 -0
- data/sig/generated/wardite/efflorescence/translator.rbs +218 -0
- data/sig/generated/wardite/efflorescence/vm.rbs +240 -0
- data/sig/generated/wardite/efflorescence/wasi.rbs +34 -0
- data/sig/generated/wardite/errors.rbs +12 -0
- data/sig/generated/wardite/float_bits.rbs +30 -0
- data/sig/generated/wardite/instruction.rbs +22 -1
- data/sig/generated/wardite/leb128.rbs +3 -1
- data/sig/generated/wardite/load.rbs +59 -7
- data/sig/generated/wardite/value.rbs +70 -11
- data/sig/generated/wardite/wasi/consts.rbs +2 -0
- data/sig/generated/wardite/wasi/spinel.rbs +15 -0
- data/sig/generated/wardite/wasi.rbs +111 -4
- data/sig/generated/wardite.rbs +114 -13
- data/sig/mir_cache_stdlib.rbs +5 -0
- data/sig/vernier.rbs +2 -2
- data/spinel/README.md +30 -0
- data/spinel/bin/wardite.rb +6 -0
- data/spinel/patches/0001-io-buffer-string-view.patch +699 -0
- data/spinel/patches/0002-io-buffer-allocation-error.patch +47 -0
- data/spinel/spin.toml +7 -0
- metadata +154 -3
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
{
|
|
2
|
+
"provenance": "User supplied the matching console summary; raw hyperfine JSON was read before rebuilding the patched executable.",
|
|
3
|
+
"reported_inputs": "Not encoded by hyperfine command names; compare.rb defaults are 100000 rounds and seed 123456789.",
|
|
4
|
+
"hyperfine": {
|
|
5
|
+
"results": [
|
|
6
|
+
{
|
|
7
|
+
"command": "New VM / Spinel / inline_mix",
|
|
8
|
+
"mean": 0.009252258400000001,
|
|
9
|
+
"stddev": 0.00031352650594375543,
|
|
10
|
+
"median": 0.009355,
|
|
11
|
+
"user": 0.006943199999999999,
|
|
12
|
+
"system": 0.0013836,
|
|
13
|
+
"min": 0.008805209000000001,
|
|
14
|
+
"max": 0.009573,
|
|
15
|
+
"times": [
|
|
16
|
+
0.009573,
|
|
17
|
+
0.009463583000000001,
|
|
18
|
+
0.009064500000000001,
|
|
19
|
+
0.009355,
|
|
20
|
+
0.008805209000000001
|
|
21
|
+
],
|
|
22
|
+
"exit_codes": [
|
|
23
|
+
0,
|
|
24
|
+
0,
|
|
25
|
+
0,
|
|
26
|
+
0,
|
|
27
|
+
0
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"command": "iwasm (WAMR interpreter) / inline_mix",
|
|
32
|
+
"mean": 0.0053474416,
|
|
33
|
+
"stddev": 0.00021360778045825002,
|
|
34
|
+
"median": 0.005366542,
|
|
35
|
+
"user": 0.0028066,
|
|
36
|
+
"system": 0.0014921999999999997,
|
|
37
|
+
"min": 0.005115458000000001,
|
|
38
|
+
"max": 0.005565083,
|
|
39
|
+
"times": [
|
|
40
|
+
0.005565083,
|
|
41
|
+
0.005366542,
|
|
42
|
+
0.005143875,
|
|
43
|
+
0.005115458000000001,
|
|
44
|
+
0.00554625
|
|
45
|
+
],
|
|
46
|
+
"exit_codes": [
|
|
47
|
+
0,
|
|
48
|
+
0,
|
|
49
|
+
0,
|
|
50
|
+
0,
|
|
51
|
+
0
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"command": "Wasmtime (Pulley) / inline_mix",
|
|
56
|
+
"mean": 0.008522924800000001,
|
|
57
|
+
"stddev": 0.0003134739533927816,
|
|
58
|
+
"median": 0.008539792000000001,
|
|
59
|
+
"user": 0.0072959999999999995,
|
|
60
|
+
"system": 0.005533,
|
|
61
|
+
"min": 0.008224416,
|
|
62
|
+
"max": 0.008981375,
|
|
63
|
+
"times": [
|
|
64
|
+
0.008224416,
|
|
65
|
+
0.008539792000000001,
|
|
66
|
+
0.008631833,
|
|
67
|
+
0.008981375,
|
|
68
|
+
0.008237208000000001
|
|
69
|
+
],
|
|
70
|
+
"exit_codes": [
|
|
71
|
+
0,
|
|
72
|
+
0,
|
|
73
|
+
0,
|
|
74
|
+
0,
|
|
75
|
+
0
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"command": "Wasmtime / inline_mix",
|
|
80
|
+
"mean": 0.006842416800000001,
|
|
81
|
+
"stddev": 0.0004867220674231855,
|
|
82
|
+
"median": 0.006859250000000001,
|
|
83
|
+
"user": 0.005507799999999999,
|
|
84
|
+
"system": 0.0053441999999999995,
|
|
85
|
+
"min": 0.006371000000000001,
|
|
86
|
+
"max": 0.007595667,
|
|
87
|
+
"times": [
|
|
88
|
+
0.007595667,
|
|
89
|
+
0.006930875,
|
|
90
|
+
0.0064552920000000005,
|
|
91
|
+
0.006371000000000001,
|
|
92
|
+
0.006859250000000001
|
|
93
|
+
],
|
|
94
|
+
"exit_codes": [
|
|
95
|
+
0,
|
|
96
|
+
0,
|
|
97
|
+
0,
|
|
98
|
+
0,
|
|
99
|
+
0
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"command": "New VM / Spinel / call_mix",
|
|
104
|
+
"mean": 0.0094408164,
|
|
105
|
+
"stddev": 0.000399831475214621,
|
|
106
|
+
"median": 0.009319541,
|
|
107
|
+
"user": 0.0069394,
|
|
108
|
+
"system": 0.0014554,
|
|
109
|
+
"min": 0.009090208,
|
|
110
|
+
"max": 0.010111625,
|
|
111
|
+
"times": [
|
|
112
|
+
0.009319541,
|
|
113
|
+
0.009090208,
|
|
114
|
+
0.00921475,
|
|
115
|
+
0.010111625,
|
|
116
|
+
0.009467958
|
|
117
|
+
],
|
|
118
|
+
"exit_codes": [
|
|
119
|
+
0,
|
|
120
|
+
0,
|
|
121
|
+
0,
|
|
122
|
+
0,
|
|
123
|
+
0
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"command": "iwasm (WAMR interpreter) / call_mix",
|
|
128
|
+
"mean": 0.0060548916,
|
|
129
|
+
"stddev": 0.00042535221950966727,
|
|
130
|
+
"median": 0.005931167,
|
|
131
|
+
"user": 0.0033591999999999997,
|
|
132
|
+
"system": 0.0015902,
|
|
133
|
+
"min": 0.005570625,
|
|
134
|
+
"max": 0.006724625000000001,
|
|
135
|
+
"times": [
|
|
136
|
+
0.006724625000000001,
|
|
137
|
+
0.0061322500000000005,
|
|
138
|
+
0.005570625,
|
|
139
|
+
0.005915791,
|
|
140
|
+
0.005931167
|
|
141
|
+
],
|
|
142
|
+
"exit_codes": [
|
|
143
|
+
0,
|
|
144
|
+
0,
|
|
145
|
+
0,
|
|
146
|
+
0,
|
|
147
|
+
0
|
|
148
|
+
]
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"command": "Wasmtime (Pulley) / call_mix",
|
|
152
|
+
"mean": 0.010079600400000003,
|
|
153
|
+
"stddev": 0.0005076405645210986,
|
|
154
|
+
"median": 0.010160500000000001,
|
|
155
|
+
"user": 0.0088306,
|
|
156
|
+
"system": 0.0061084,
|
|
157
|
+
"min": 0.009343167000000001,
|
|
158
|
+
"max": 0.010559834,
|
|
159
|
+
"times": [
|
|
160
|
+
0.010510709,
|
|
161
|
+
0.009823792000000001,
|
|
162
|
+
0.009343167000000001,
|
|
163
|
+
0.010559834,
|
|
164
|
+
0.010160500000000001
|
|
165
|
+
],
|
|
166
|
+
"exit_codes": [
|
|
167
|
+
0,
|
|
168
|
+
0,
|
|
169
|
+
0,
|
|
170
|
+
0,
|
|
171
|
+
0
|
|
172
|
+
]
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"command": "Wasmtime / call_mix",
|
|
176
|
+
"mean": 0.0075008416000000005,
|
|
177
|
+
"stddev": 0.0002734630164058752,
|
|
178
|
+
"median": 0.007535792,
|
|
179
|
+
"user": 0.0061338,
|
|
180
|
+
"system": 0.0062098,
|
|
181
|
+
"min": 0.007208125,
|
|
182
|
+
"max": 0.007835541,
|
|
183
|
+
"times": [
|
|
184
|
+
0.007241875,
|
|
185
|
+
0.007208125,
|
|
186
|
+
0.007535792,
|
|
187
|
+
0.0076828750000000005,
|
|
188
|
+
0.007835541
|
|
189
|
+
],
|
|
190
|
+
"exit_codes": [
|
|
191
|
+
0,
|
|
192
|
+
0,
|
|
193
|
+
0,
|
|
194
|
+
0,
|
|
195
|
+
0
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
},
|
|
200
|
+
"setup": {
|
|
201
|
+
"spinel_branch": "master",
|
|
202
|
+
"spinel_commit": "6e7fc13556709bf7d7ba4af5bd1d12bebc00733e",
|
|
203
|
+
"saved_patch_commit": "6f1a2c259f99c9fe460ee6de1d6f18a05008ca8d",
|
|
204
|
+
"compiler_sha256": "accef97125716f36d9e953411958974907fc7fae6163e3790c9e739b556a4682",
|
|
205
|
+
"wardite_binary_sha256": "9de55acde45698bd19b1969b24ec88b1c1d7476b4407245a974e37ba7fcc5041",
|
|
206
|
+
"vm_source_sha256": "72c12862e9c3f83bd4418129a99c849710ec77fd74ad0a795d42cc57ca4feb99",
|
|
207
|
+
"native_flags": [
|
|
208
|
+
"-O2"
|
|
209
|
+
],
|
|
210
|
+
"codegen": {
|
|
211
|
+
"setjmps": 0,
|
|
212
|
+
"volatile_lines": 0,
|
|
213
|
+
"instruction_temporary_roots": 38,
|
|
214
|
+
"function_instruction_root": true
|
|
215
|
+
},
|
|
216
|
+
"performance_measurements": "Pending user measurement; no benchmark run in this stage.",
|
|
217
|
+
"generated_c_sha256": "d2d22a4ca092eab9a1889535468e3b9185a68342d182bacda5175116fe22f636",
|
|
218
|
+
"validation": {
|
|
219
|
+
"tests": 117,
|
|
220
|
+
"assertions": 10893,
|
|
221
|
+
"failures": 0,
|
|
222
|
+
"errors": 0,
|
|
223
|
+
"omissions": 0,
|
|
224
|
+
"typecheck": "passed",
|
|
225
|
+
"test_log": "/tmp/wardite-while-master-tests.log",
|
|
226
|
+
"typecheck_log": "/tmp/wardite-while-typecheck.log"
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
"binary_sha256": "9de55acde45698bd19b1969b24ec88b1c1d7476b4407245a974e37ba7fcc5041"
|
|
230
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Summarize an xctrace time-profile XML export, without third-party packages."""
|
|
2
|
+
|
|
3
|
+
import collections
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
import xml.etree.ElementTree as ET
|
|
7
|
+
|
|
8
|
+
root = ET.parse(sys.argv[1]).getroot()
|
|
9
|
+
references = {element.get("id"): element for element in root.iter() if element.get("id")}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def resolve(element):
|
|
13
|
+
if element is not None and element.get("ref"):
|
|
14
|
+
return references[element.get("ref")]
|
|
15
|
+
return element
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
self_time = collections.Counter()
|
|
19
|
+
inclusive_time = collections.Counter()
|
|
20
|
+
total = 0
|
|
21
|
+
missing = 0
|
|
22
|
+
samples = 0
|
|
23
|
+
for row in root.iter("row"):
|
|
24
|
+
stack = resolve(row.find("tagged-backtrace"))
|
|
25
|
+
weight = resolve(row.find("weight"))
|
|
26
|
+
if stack is None or weight is None:
|
|
27
|
+
missing += 1
|
|
28
|
+
continue
|
|
29
|
+
frames = [resolve(frame).get("name", "unknown") for frame in stack.findall("frame")]
|
|
30
|
+
if not frames:
|
|
31
|
+
missing += 1
|
|
32
|
+
continue
|
|
33
|
+
nanoseconds = int(weight.text)
|
|
34
|
+
samples += 1
|
|
35
|
+
total += nanoseconds
|
|
36
|
+
self_time[frames[0]] += nanoseconds
|
|
37
|
+
for name in set(frames):
|
|
38
|
+
inclusive_time[name] += nanoseconds
|
|
39
|
+
|
|
40
|
+
if not total:
|
|
41
|
+
raise SystemExit("No weighted stack samples found")
|
|
42
|
+
|
|
43
|
+
print(json.dumps({
|
|
44
|
+
"sampled_cpu_ms": total / 1e6,
|
|
45
|
+
"stack_samples": samples,
|
|
46
|
+
"missing_stack_rows": missing,
|
|
47
|
+
"note": "Inclusive percentages overlap; these are sampled CPU weights, not wall-clock attribution.",
|
|
48
|
+
"functions": [{
|
|
49
|
+
"name": name,
|
|
50
|
+
"self_ms": weight / 1e6,
|
|
51
|
+
"self_percent": weight * 100 / total,
|
|
52
|
+
"inclusive_percent": inclusive_time[name] * 100 / total,
|
|
53
|
+
} for name, weight in self_time.most_common()],
|
|
54
|
+
}, indent=2))
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Optional reference-engine validation; ordinary tests require only wasm-tools.
|
|
4
|
+
# Usage: bundle exec ruby -Ilib benchmark/validate_m1_eh.rb
|
|
5
|
+
require 'wardite'
|
|
6
|
+
require 'open3'
|
|
7
|
+
require 'tmpdir'
|
|
8
|
+
require_relative '../test/support/efflorescence_m1_cases'
|
|
9
|
+
|
|
10
|
+
puts Open3.capture2('wasmtime', '--version').first.strip
|
|
11
|
+
puts Open3.capture2('wasm-tools', '--version').first.strip
|
|
12
|
+
count = 0
|
|
13
|
+
Dir.mktmpdir('wardite-m1-reference') do |dir|
|
|
14
|
+
EfflorescenceM1Cases::EH_CASES.each_with_index do |(name, wat, calls), i|
|
|
15
|
+
source = File.join(dir, "#{i}.wat")
|
|
16
|
+
binary = File.join(dir, "#{i}.wasm")
|
|
17
|
+
File.write(source, wat)
|
|
18
|
+
[['wasm-tools', 'parse', source, '-o', binary], ['wasm-tools', 'validate', binary]].each do |command|
|
|
19
|
+
output, status = Open3.capture2e(*command)
|
|
20
|
+
abort output unless status.success?
|
|
21
|
+
end
|
|
22
|
+
vm = File.open(binary, 'rb') { |file| Wardite::BinaryLoader.load_from_buffer(file, engine: :efflorescence, enable_wasi: false).runtime }
|
|
23
|
+
calls.each do |export, args, expected|
|
|
24
|
+
output, error, status = Open3.capture3('wasmtime', 'run', '-W', 'exceptions=y', '--invoke', export, binary, *args.map(&:to_s))
|
|
25
|
+
abort "#{name}/#{export}: #{error}" unless status.success?
|
|
26
|
+
reference = Integer(output.strip) & 0xffffffff
|
|
27
|
+
actual = vm.call_unboxed(export, args)
|
|
28
|
+
abort "#{name}: expected #{expected}, Wasmtime #{reference}, MIR #{actual}" unless reference == expected && actual == expected
|
|
29
|
+
count += 1
|
|
30
|
+
end
|
|
31
|
+
puts "PASS #{name}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
puts "#{count} EH calls agree with fixed expectations and Wasmtime (-W exceptions=y)."
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Compare results and an order-sensitive checksum of every memory byte, page
|
|
4
|
+
# count and i32 global against Wasmtime. Unit/native tests additionally compare
|
|
5
|
+
# full snapshots and fixed expected mutations, including after traps.
|
|
6
|
+
require 'wardite'
|
|
7
|
+
require 'open3'
|
|
8
|
+
require 'tmpdir'
|
|
9
|
+
require_relative '../test/support/efflorescence_m2_cases'
|
|
10
|
+
|
|
11
|
+
C = EfflorescenceM2Cases
|
|
12
|
+
MASK = 0xffffffff
|
|
13
|
+
|
|
14
|
+
def checked(command)
|
|
15
|
+
output, status = Open3.capture2e(*command)
|
|
16
|
+
abort output unless status.success?
|
|
17
|
+
output
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def digest_function(memory, globals)
|
|
21
|
+
scan = memory ? <<~WAT : ''
|
|
22
|
+
block $done loop $scan
|
|
23
|
+
local.get $p memory.size i32.const 16 i32.shl i32.ge_u br_if $done
|
|
24
|
+
local.get $h local.get $p i32.load8_u i32.xor i32.const 16777619 i32.mul local.set $h
|
|
25
|
+
local.get $p i32.const 1 i32.add local.set $p br $scan
|
|
26
|
+
end end
|
|
27
|
+
WAT
|
|
28
|
+
pages = memory ? 'memory.size' : 'i32.const 0'
|
|
29
|
+
global_hash = globals.map { |i| "i32.const 16777619 i32.mul global.get #{i} i32.xor" }.join(' ')
|
|
30
|
+
"(func $__m2_digest (result i32) (local $h i32) (local $p i32) i32.const -2128831035 local.set $h #{scan} local.get $h #{pages} i32.xor #{global_hash})"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def state_hash(instance)
|
|
34
|
+
hash = 2166136261
|
|
35
|
+
memory = instance.store.memories[0]
|
|
36
|
+
memory&.data&.each_byte { |byte| hash = ((hash ^ byte) * 16777619) & MASK }
|
|
37
|
+
hash ^= memory ? memory.current : 0
|
|
38
|
+
instance.store.globals.each do |global|
|
|
39
|
+
hash = (((hash * 16777619) & MASK) ^ global.value.value) if global.type == :i32
|
|
40
|
+
end
|
|
41
|
+
hash & MASK
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
memory_wat = C::MEMORY_WAT.rstrip[0...-1] + '(data (i32.const 1) "\80\ff\01\80"))'
|
|
45
|
+
cases = [
|
|
46
|
+
[C::GLOBAL_WAT, 'get', [], 7], [C::GLOBAL_WAT, 'snapshot', [], MASK],
|
|
47
|
+
[C::GLOBAL_WAT, 'direct', [40], 7], [C::GLOBAL_WAT, 'recursive', [3], 24],
|
|
48
|
+
[memory_wat, 'load', [1], 0x8001ff80], [memory_wat, 'load8_s', [1], 0xffffff80], [memory_wat, 'load8_u', [1], 128],
|
|
49
|
+
[memory_wat, 'load16_s', [1], 0xffffff80], [memory_wat, 'load16_u', [1], 0xff80], [memory_wat, 'offset', [1], 128],
|
|
50
|
+
[memory_wat, 'store', [65532,0x89abcdef], nil], [memory_wat, 'store8', [65535,0x89abcdef], nil],
|
|
51
|
+
[memory_wat, 'store16', [65534,0x89abcdef], nil], [memory_wat, 'load', [65533], :trap],
|
|
52
|
+
[memory_wat, 'load8_u', [-1], :trap], [memory_wat, 'overflow', [1], :trap],
|
|
53
|
+
[memory_wat, 'store_overflow', [1], :trap],
|
|
54
|
+
[C::GROW_WAT, 'grow', [0], 1], [C::GROW_WAT, 'grow', [1], 1], [C::GROW_WAT, 'grow', [2], 1],
|
|
55
|
+
[C::GROW_WAT, 'grow', [3], MASK], [C::GROW_WAT, 'grow', [MASK], MASK], [C::GROW_WAT, 'callee', [], 53],
|
|
56
|
+
[C::BULK_WAT, 'init', [20,0,9], nil], [C::BULK_WAT, 'init', [65527,0,9], nil],
|
|
57
|
+
[C::BULK_WAT, 'init', [65536,9,0], nil], [C::BULK_WAT, 'init', [0,8,2], :trap], [C::BULK_WAT, 'active', [0,0,1], :trap],
|
|
58
|
+
[C::BULK_WAT, 'active', [65536,0,0], nil], [C::BULK_WAT, 'empty', [65536,0,0], nil],
|
|
59
|
+
[C::BULK_WAT, 'copy', [2,0,4], nil], [C::BULK_WAT, 'copy', [0,2,4], nil],
|
|
60
|
+
[C::BULK_WAT, 'copy', [0,0,65536], nil], [C::BULK_WAT, 'copy', [65536,65536,0], nil],
|
|
61
|
+
[C::BULK_WAT, 'copy', [65535,0,2], :trap], [C::BULK_WAT, 'copy', [0,65535,2], :trap],
|
|
62
|
+
[C::BULK_WAT, 'fill', [1,256,4], nil], [C::BULK_WAT, 'fill', [65535,MASK,1], nil],
|
|
63
|
+
[C::BULK_WAT, 'fill', [65536,42,0], nil], [C::BULK_WAT, 'fill', [65537,42,0], :trap],
|
|
64
|
+
[C::INTEGRATION_WAT, 'get', [], 5], [C::INTEGRATION_WAT, 'load', [0], 11],
|
|
65
|
+
[C::INTEGRATION_WAT, 'caught', [], 51], [C::INTEGRATION_WAT, 'snapshot', [], 0xffffffd8],
|
|
66
|
+
[C::INTEGRATION_WAT, 'reuse', [], 0], [C::INTEGRATION_WAT, 'pure', [], 42],
|
|
67
|
+
[C::INTEGRATION_WAT, 'trap', [], :trap], [C::INTEGRATION_WAT, 'uncaught', [], :exception]
|
|
68
|
+
]
|
|
69
|
+
puts checked(['wasmtime','--version']).strip
|
|
70
|
+
puts checked(['wasm-tools','--version']).strip
|
|
71
|
+
normal = traps = exceptions = 0
|
|
72
|
+
Dir.mktmpdir('wardite-m2-reference') do |dir|
|
|
73
|
+
cases.each_with_index do |(wat, name, args, expected), i|
|
|
74
|
+
source = File.join(dir, 'input.wat')
|
|
75
|
+
binary = File.join(dir, 'input.wasm')
|
|
76
|
+
File.write(source, wat)
|
|
77
|
+
checked(['wasm-tools','parse',source,'-o',binary])
|
|
78
|
+
checked(['wasm-tools','validate',binary])
|
|
79
|
+
instance = File.open(binary, 'rb') { |file| Wardite::BinaryLoader.load_from_buffer(file, enable_wasi: false, engine: :efflorescence) }
|
|
80
|
+
target = instance.export_section.exports.fetch(name)
|
|
81
|
+
globals = instance.store.globals.each_index.select { |index| instance.store.globals[index].type == :i32 }
|
|
82
|
+
arguments = args.map { |n| "i32.const #{(n & MASK) >= 2**31 ? (n & MASK) - 2**32 : (n & MASK)}" }.join(' ')
|
|
83
|
+
function = instance.store.funcs.fetch(target.index)
|
|
84
|
+
drop = function.retsig.empty? ? '' : 'drop'
|
|
85
|
+
wrapper = "(func (export \"__m2_probe\") (result i32) #{arguments} call #{target.index} #{drop} call $__m2_digest)"
|
|
86
|
+
probe_wat = wat.rstrip[0...-1] + digest_function(!instance.store.memories.empty?, globals) + wrapper + ')'
|
|
87
|
+
File.write(source, probe_wat)
|
|
88
|
+
checked(['wasm-tools','parse',source,'-o',binary])
|
|
89
|
+
checked(['wasm-tools','validate',binary])
|
|
90
|
+
output, error, status = Open3.capture3('wasmtime','run','-W','exceptions=y','--invoke','__m2_probe',binary)
|
|
91
|
+
if expected == :trap
|
|
92
|
+
begin
|
|
93
|
+
instance.runtime.call_unboxed(name,args)
|
|
94
|
+
abort "missing Wardite trap: #{name}"
|
|
95
|
+
rescue Wardite::EvalError
|
|
96
|
+
end
|
|
97
|
+
abort "missing Wasmtime memory trap: #{error}" unless !status.success? && error.include?('out of bounds memory access')
|
|
98
|
+
traps += 1
|
|
99
|
+
elsif expected == :exception
|
|
100
|
+
begin
|
|
101
|
+
instance.runtime.call_unboxed(name,args)
|
|
102
|
+
abort 'missing Wardite exception'
|
|
103
|
+
rescue Wardite::UncaughtWasmException => exception
|
|
104
|
+
abort 'lost exception payload' unless exception.payload == [17]
|
|
105
|
+
end
|
|
106
|
+
abort "missing Wasmtime exception: #{error}" unless !status.success? && error.match?(/exception/i)
|
|
107
|
+
exceptions += 1
|
|
108
|
+
else
|
|
109
|
+
actual = instance.runtime.call_unboxed(name,args)
|
|
110
|
+
abort "bad fixed result #{name}: #{actual} != #{expected}" unless actual == expected
|
|
111
|
+
abort "Wasmtime failed: #{error}" unless status.success?
|
|
112
|
+
hash = state_hash(instance)
|
|
113
|
+
abort "Store state differs: #{name} #{args}: #{output.strip} != #{hash}" unless (Integer(output.strip) & MASK) == hash
|
|
114
|
+
normal += 1
|
|
115
|
+
end
|
|
116
|
+
puts "PASS #{i + 1}: #{name} #{args}"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
puts "#{normal} full-memory/page/global checksum comparisons, #{traps} memory traps, #{exceptions} uncaught exception agree with Wasmtime."
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Usage: ruby -Ilib benchmark/validate_m3.rb
|
|
4
|
+
require "wardite"
|
|
5
|
+
require "open3"
|
|
6
|
+
require "tmpdir"
|
|
7
|
+
require_relative "../test/support/efflorescence_m3_cases"
|
|
8
|
+
|
|
9
|
+
puts Open3.capture2("wasmtime", "--version").first.strip
|
|
10
|
+
puts Open3.capture2("wasm-tools", "--version").first.strip
|
|
11
|
+
|
|
12
|
+
Dir.mktmpdir("wardite-m3-reference") do |dir|
|
|
13
|
+
wat = File.join(dir, "m3.wat")
|
|
14
|
+
wasm = File.join(dir, "m3.wasm")
|
|
15
|
+
File.write(wat, EfflorescenceM3Cases::REFERENCE_WAT)
|
|
16
|
+
[["wasm-tools", "parse", wat, "-o", wasm], ["wasm-tools", "validate", wasm]].each do |command|
|
|
17
|
+
output, status = Open3.capture2e(*command)
|
|
18
|
+
abort output unless status.success?
|
|
19
|
+
end
|
|
20
|
+
vm = Wardite.new(path: wasm, enable_wasi: false, engine: :efflorescence).runtime
|
|
21
|
+
|
|
22
|
+
[[0, 14], [1, 105]].each do |selector, expected|
|
|
23
|
+
out, err, status = Open3.capture3("wasmtime", "run", "-W", "exceptions=y", "--invoke", "run", wasm, selector.to_s, "5")
|
|
24
|
+
abort err unless status.success?
|
|
25
|
+
actual = vm.call_unboxed(:run, [selector, 5])
|
|
26
|
+
abort "selector #{selector}: expected #{expected}, Wasmtime #{out.strip}, MIR #{actual}" unless
|
|
27
|
+
actual == expected && Integer(out.strip) == expected
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
[[2, "indirect call type mismatch", "function type mismatch"],
|
|
31
|
+
[3, "uninitialized element", "null reference"],
|
|
32
|
+
[4, "out of bounds table access", "table index out of bounds"],
|
|
33
|
+
[-1, "out of bounds table access", "table index out of bounds"]].each do |selector, reference, expected|
|
|
34
|
+
_, err, status = Open3.capture3("wasmtime", "run", "-W", "exceptions=y", "--invoke", "run", wasm, selector.to_s, "5")
|
|
35
|
+
abort "selector #{selector}: expected Wasmtime #{reference}\n#{err}" if status.success? || !err.include?(reference)
|
|
36
|
+
begin
|
|
37
|
+
vm.call_unboxed(:run, [selector, 5])
|
|
38
|
+
abort "selector #{selector}: expected MIR #{expected}"
|
|
39
|
+
rescue Wardite::EvalError => error
|
|
40
|
+
abort error.message unless error.message.include?(expected)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
puts "Six indirect calls agree with Wasmtime (-W exceptions=y), including a caught throw and four traps."
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Usage: bundle exec ruby -Ilib benchmark/validate_m4.rb
|
|
4
|
+
require "wardite"
|
|
5
|
+
require "open3"
|
|
6
|
+
require "tmpdir"
|
|
7
|
+
require_relative "../test/support/efflorescence_m4_cases"
|
|
8
|
+
require_relative "../test/support/efflorescence_m4_alu_cases"
|
|
9
|
+
|
|
10
|
+
include EfflorescenceM4Cases
|
|
11
|
+
include EfflorescenceM4ALUCases
|
|
12
|
+
|
|
13
|
+
def capture!(*command)
|
|
14
|
+
output, error, status = Open3.capture3(*command)
|
|
15
|
+
abort "#{command.inspect}\n#{output}#{error}" unless status.success?
|
|
16
|
+
output.strip
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def compare(dir, name, wat, cases)
|
|
20
|
+
source = File.join(dir, "#{name}.wat")
|
|
21
|
+
binary = File.join(dir, "#{name}.wasm")
|
|
22
|
+
File.write(source, wat)
|
|
23
|
+
capture!("wasm-tools", "parse", source, "-o", binary)
|
|
24
|
+
capture!("wasm-tools", "validate", binary)
|
|
25
|
+
vm = Wardite.new(path: binary, engine: :efflorescence, enable_wasi: false).runtime
|
|
26
|
+
cases.each do |export, *args, expected|
|
|
27
|
+
reference_args = export.start_with?("i64.extend_i32_") ? args.map { |arg| signed_field(arg, 32) } : args
|
|
28
|
+
command = ["wasmtime", "run", "-W", "exceptions=y", "--invoke", export, "--", binary, *reference_args.map(&:to_s)]
|
|
29
|
+
if expected.is_a?(Integer)
|
|
30
|
+
result = Integer(capture!(*command))
|
|
31
|
+
result %= 2**32 if expected > 2**31 - 1 && result.negative?
|
|
32
|
+
actual = vm.call_unboxed(export, args)
|
|
33
|
+
abort "#{export} #{args}: #{expected} expected, #{result} Wasmtime, #{actual} Efflorescence" unless result == expected && actual == expected
|
|
34
|
+
else
|
|
35
|
+
_, error, status = Open3.capture3(*command)
|
|
36
|
+
trap = {
|
|
37
|
+
"zero" => "integer divide by zero",
|
|
38
|
+
"overflow" => "integer overflow",
|
|
39
|
+
"type" => "indirect call type mismatch",
|
|
40
|
+
"bounds" => "out of bounds memory access"
|
|
41
|
+
}.fetch(expected)
|
|
42
|
+
abort "#{command.inspect}\n#{error}" if status.success? || !error.include?(trap)
|
|
43
|
+
|
|
44
|
+
begin
|
|
45
|
+
vm.call_unboxed(export, args)
|
|
46
|
+
rescue Wardite::IntegerOverflow
|
|
47
|
+
raise unless expected == "overflow"
|
|
48
|
+
next
|
|
49
|
+
rescue Wardite::EvalError => failure
|
|
50
|
+
wardite_trap = expected == "type" ? "call_indirect function type mismatch" : trap
|
|
51
|
+
raise unless failure.message.include?(wardite_trap)
|
|
52
|
+
next
|
|
53
|
+
end
|
|
54
|
+
abort "#{export} #{args}: Efflorescence did not trap"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
puts "#{name}: #{cases.size} calls agree"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
puts capture!("wasmtime", "--version")
|
|
61
|
+
puts capture!("wasm-tools", "--version")
|
|
62
|
+
Dir.mktmpdir("wardite-m4-reference") do |dir|
|
|
63
|
+
functions, rows = alu_cases
|
|
64
|
+
# Exercise all 35 ALU/convert exports, keeping subprocess count bounded.
|
|
65
|
+
selected = rows.group_by(&:first).values.flat_map do |cases|
|
|
66
|
+
numeric, traps = cases.partition { |row| row.last.is_a?(Integer) }
|
|
67
|
+
[numeric.first, numeric.fetch(numeric.size / 2), numeric.last] + traps.uniq(&:last)
|
|
68
|
+
end
|
|
69
|
+
compare(dir, "alu", "(module #{functions})", selected)
|
|
70
|
+
compare(dir, "control", CONTROL_WAT, [
|
|
71
|
+
["recursive", 3, MIN, MIN], ["reset", MIN, 0],
|
|
72
|
+
["branch", 0, MIN], ["branch", 1, 1], ["select", MIN, 1, MIN]
|
|
73
|
+
])
|
|
74
|
+
compare(dir, "store_and_eh", STORE_EH_WAT, [
|
|
75
|
+
*STORE_EH_ROWS.take(7), ["offset_trap", -1, "bounds"], ["get", MIN], ["eh", MIN, MIN], ["eh", -1, -1]
|
|
76
|
+
])
|
|
77
|
+
|
|
78
|
+
indirect = <<~WAT
|
|
79
|
+
(module
|
|
80
|
+
(type $callee (func (param i32 i64) (result i64)))
|
|
81
|
+
(type $site (func (param i32 i64) (result i64)))
|
|
82
|
+
(table 2 funcref)
|
|
83
|
+
(elem (i32.const 0) func $f $wrong)
|
|
84
|
+
(func $f (type $callee) local.get 1 local.get 0 i64.extend_i32_u i64.xor)
|
|
85
|
+
(func $wrong (param i64 i64) (result i64) unreachable)
|
|
86
|
+
(func (export "indirect") (param i32 i64) (result i64)
|
|
87
|
+
i32.const 1 local.get 1 local.get 0 call_indirect (type $site))
|
|
88
|
+
(func (export "legacy_wrapper") (param i32) (result i64)
|
|
89
|
+
local.get 0 i64.const -9223372036854775808 call $f))
|
|
90
|
+
WAT
|
|
91
|
+
compare(dir, "indirect", indirect, [["indirect", 0, MIN, MIN + 1], ["indirect", 1, MIN, "type"],
|
|
92
|
+
["legacy_wrapper", 1, MIN + 1]])
|
|
93
|
+
stack = Wardite.new(path: File.join(dir, "indirect.wasm"), enable_wasi: false).runtime
|
|
94
|
+
abort "legacy wrapper mismatch" unless stack.call("legacy_wrapper", [1]).value_s == MIN + 1
|
|
95
|
+
end
|