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
350
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
170
GitHub ActionsでDevSecOpsごっこ
retrage
0
43
Practical Rust (Hypervisor) Firmware
retrage
3
1.6k
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
560
LLVM Backend Development for EFI Byte Code
retrage
2
940
Other Decks in Programming
See All in Programming
効率的な開発手段として VRTを活用する
ishkawa
0
150
AI時代のソフトウェア開発を考える(2025/07版) / Agentic Software Engineering Findy 2025-07 Edition
twada
PRO
96
33k
What's new in AppKit on macOS 26
1024jp
0
130
iOS 26にアップデートすると実機でのHot Reloadができない?
umigishiaoi
0
130
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
270
テスト駆動Kaggle
isax1015
1
480
High-Level Programming Languages in AI Era -Human Thought and Mind-
hayat01sh1da
PRO
0
830
Porting a visionOS App to Android XR
akkeylab
0
640
VS Code Update for GitHub Copilot
74th
2
660
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
2
150
TypeScriptでDXを上げろ! Hono編
yusukebe
1
390
設計やレビューに悩んでいるPHPerに贈る、クリーンなオブジェクト設計の指針たち
panda_program
6
2.3k
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Statistics for Hackers
jakevdp
799
220k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
A designer walks into a library…
pauljervisheath
207
24k
How to Think Like a Performance Engineer
csswizardry
25
1.7k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
How to train your dragon (web standard)
notwaldorf
96
6.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Adopting Sorbet at Scale
ufuk
77
9.5k
It's Worth the Effort
3n
185
28k
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