Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
WASMで遊ぶ
Search
Akira Moroo
March 04, 2018
Programming
0
360
WASMで遊ぶ
Google V8 JavaScript EngineでのWebAssemblyのi32.addの実装を見てみたときのスライドです.
Akira Moroo
March 04, 2018
Tweet
Share
More Decks by Akira Moroo
See All by Akira Moroo
Exploring x86 MSR Space
retrage
0
1.3k
LLMでバイナリ解析支援
retrage
0
180
GitHub ActionsでDevSecOpsごっこ
retrage
0
45
Practical Rust (Hypervisor) Firmware
retrage
3
1.7k
Bypassing UEFI Secure Boot with Thin-Hypervisor
retrage
0
1.1k
Porting Linux to Nabla Containers
retrage
0
1.2k
Network Boot from Bell Labs
retrage
2
1.6k
Unikernelで始める自作OS/OS Development with Unikernel
retrage
1
570
LLVM Backend Development for EFI Byte Code
retrage
2
960
Other Decks in Programming
See All in Programming
rage against annotate_predecessor
junk0612
0
170
今から始めるClaude Code入門〜AIコーディングエージェントの歴史と導入〜
nokomoro3
0
130
Navigating Dependency Injection with Metro
zacsweers
3
260
HTMLの品質ってなんだっけ? “HTMLクライテリア”の設計と実践
unachang113
4
2.8k
Kiroで始めるAI-DLC
kaonash
2
580
Ruby×iOSアプリ開発 ~共に歩んだエコシステムの物語~
temoki
0
270
Namespace and Its Future
tagomoris
6
700
請來的 AI Agent 同事們在寫程式時,怎麼用 pytest 去除各種幻想與盲點
keitheis
0
120
時間軸から考えるTerraformを使う理由と留意点
fufuhu
16
4.8k
Cache Me If You Can
ryunen344
2
700
CJK and Unicode From a PHP Committer
youkidearitai
PRO
0
110
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
390
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
184
22k
GraphQLとの向き合い方2022年版
quramy
49
14k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
9
810
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
How STYLIGHT went responsive
nonsquared
100
5.8k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.8k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
126
53k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
Visualization
eitanlees
148
16k
Transcript
WASMで遊ぶ 2018/03/04 Dentoo.LT 19 @retrage
Recap: WebAssembly(wasm)とは • Web向けのbinary formatとそれを実行するVM • “wasm is a new
portable, size- and load-time-efficient” • VMはスタックマシンとして構成 • JavaScriptと連携して動作 • JSを置き換えるものではない • 主要なWebブラウザが既に対応 • Firefox, Google Chrome, Microsoft Edge, Safariなど 1
コード例 • 2つのパラメータ$lhsと$rhsをスタックにプッシュ • i32.addでそれらを加算 2 (module (func (param $lhs
i32) (param $rhs i32) (result i32) get_local $lhs get_local $rhs i32.add ) ) • ⇒Google V8 JavaScript Engineでのi32.addの実装
i32.addの実装 3 #define FOREACH_SIMPLE_BINOP(V) \ V(I32Add, uint32_t, +) \ #define
EXECUTE_SIMPLE_BINOP(name, ctype, op) \ case kExpr##name: { \ WasmValue rval = Pop(); \ WasmValue lval = Pop(); \ auto result = lval.to<ctype>() op rval.to<ctype>(); \ possible_nondeterminism_ |= has_nondeterminism(result); \ Push(WasmValue(result)); \ break; \ } FOREACH_SIMPLE_BINOP(EXECUTE_SIMPLE_BINOP)
大元をたどる 4 switch (orig) { case kExprNop: break; byte orig
= code->start[pc]; void Execute(InterpreterCode* code, pc_t pc, int max) { • EXECUTE_SIMPLE_BINOPの中はcase文 • 大元のswitchを探す • codeに命令列があり,pcにinstruction pointer
Pop(),Push()の実装 5 WasmValue Pop() { DCHECK_GT(frames_.size(), 0); DCHECK_GT(StackHeight(), frames_.back().llimit()); return
*--sp_; } void Push(WasmValue val) { DCHECK_NE(kWasmStmt, val.type()); DCHECK_LE(1, stack_limit_ - sp_); *sp_++ = val; } • 実質1行で実装されている
まとめ • wasmについて • binary formatとそれを実行するVM • 既に固まった仕様と実行環境が存在 • wasmの表現形式
• binary formatな.wasm形式 • text format な.wat形式 • wasmの実装 • Google V8 JavaScript Engineではナイーブな実装 • 確かにスタックマシンとして実装 6
参考文献 • https://webassembly.github.io/spec/core/index.ht ml • https://developer.mozilla.org/ja/docs/WebAssembl y/Understanding_the_text_format • https://github.com/v8/v8/blob/master/src/wasm/ wasm-interpreter.cc
7
話し(調べ)足りなかったこと • どのようにJSとやりとりを行なっているのか • 関数の実行がどのように行われているのか • global variableとlocal variableの扱いの違い •
wasmの今後(GCの実装など) • wasmの高速化 8