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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Akira Moroo
March 04, 2018
Programming
390
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
WASMで遊ぶ
Google V8 JavaScript EngineでのWebAssemblyのi32.addの実装を見てみたときのスライドです.
Akira Moroo
March 04, 2018
More Decks by Akira Moroo
See All by Akira Moroo
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
300
Exploring x86 MSR Space
retrage
0
1.5k
LLMでバイナリ解析支援
retrage
0
230
GitHub ActionsでDevSecOpsごっこ
retrage
0
110
Practical Rust (Hypervisor) Firmware
retrage
3
1.9k
Bypassing UEFI Secure Boot with Thin-Hypervisor
retrage
0
1.3k
Porting Linux to Nabla Containers
retrage
0
1.3k
Network Boot from Bell Labs
retrage
2
1.8k
Unikernelで始める自作OS/OS Development with Unikernel
retrage
1
680
Other Decks in Programming
See All in Programming
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
270
Vite+ Unified Toolchain for the Web
naokihaba
0
320
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.1k
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
560
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
190
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
550
AI 輔助遺留系統現代化的經驗分享
jame2408
1
240
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.2k
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
350
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
270
RTSPクライアントを自作してみた話
simotin13
0
610
Featured
See All Featured
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
840
How to train your dragon (web standard)
notwaldorf
97
6.7k
Heart Work Chapter 1 - Part 1
lfama
PRO
7
36k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
230
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
Mind Mapping
helmedeiros
PRO
1
250
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
230
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
780
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
970
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