Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
WASMで遊ぶ
Search
Akira Moroo
March 04, 2018
Programming
400
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
630
Exploring x86 MSR Space
retrage
0
1.6k
LLMでバイナリ解析支援
retrage
0
280
GitHub ActionsでDevSecOpsごっこ
retrage
0
130
Practical Rust (Hypervisor) Firmware
retrage
3
2k
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.9k
Unikernelで始める自作OS/OS Development with Unikernel
retrage
1
730
Other Decks in Programming
See All in Programming
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
440
Agents on Rails - Rails at Scale 2026
irinanazarova
0
570
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
190
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
270
APNsからLive Activityを開始する話
yumnumm
0
170
R8 の設定見直しでアプリサイズ削減
andpad
0
220
Kotlinの15年とServer-Side Kotlin
n_takehata
1
160
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
830
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
1k
Performance Optimization With LLMs
xleitix
0
160
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
3
600
Featured
See All Featured
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
560
We Have a Design System, Now What?
morganepeng
55
8.4k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
290
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
360
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
HDC tutorial
michielstock
2
960
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
WCS-LA-2024
lcolladotor
0
900
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
RailsConf 2023
tenderlove
30
1.6k
The untapped power of vector embeddings
frankvandijk
2
1.9k
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