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
280
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
710
LLMでバイナリ解析支援
retrage
0
88
GitHub ActionsでDevSecOpsごっこ
retrage
0
17
Practical Rust (Hypervisor) Firmware
retrage
3
1.3k
Bypassing UEFI Secure Boot with Thin-Hypervisor
retrage
0
940
Porting Linux to Nabla Containers
retrage
0
1k
Network Boot from Bell Labs
retrage
2
1.3k
Unikernelで始める自作OS/OS Development with Unikernel
retrage
0
420
LLVM Backend Development for EFI Byte Code
retrage
2
700
Other Decks in Programming
See All in Programming
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
270
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
810
TYPO3 v13 – The road to LTS: What's new and new APIs
luisasofie_xoxo
0
210
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
140
単体テストを書かない技術 #phpcon_odawara
o0h
PRO
27
8.3k
障害対応を起点としたもっといい開発と運用のサイクル作りのためにできること / Hatena Enginner Seminar #29
polamjag
0
180
Node.js v22 で変わること
yosuke_furukawa
PRO
9
3.5k
CA.swift19 恋するAIアプリ開発の裏側
oskmr
0
360
Goのエラースタックトレースの歴史と今後
sonatard
9
1.5k
Build Apps for iOS, Android & Desktop in 100% Kotlin With Compose Multiplatform (mDevCamp 2024)
zsmb
0
340
SIMD Parallel Programming with the Vector API
josepaumard
0
180
Fragment Composition of GraphQL
quramy
7
1k
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
320
23k
Building a Modern Day E-commerce SEO Strategy
aleyda
17
6.4k
Into the Great Unknown - MozCon
thekraken
10
990
How to name files
jennybc
65
93k
Visualization
eitanlees
136
14k
Building Effective Engineering Teams - LeadDev
addyosmani
28
1.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Statistics for Hackers
jakevdp
789
220k
Docker and Python
trallard
34
2.7k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.1k
Product Roadmaps are Hard
iamctodd
44
9.7k
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