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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
570
Exploring x86 MSR Space
retrage
0
1.6k
LLMでバイナリ解析支援
retrage
0
250
GitHub ActionsでDevSecOpsごっこ
retrage
0
120
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
710
Other Decks in Programming
See All in Programming
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
110
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
150
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
140
Laravelのアプリケーションをどこにデプロイするか #ツナギメオフライン.9
akase244
0
130
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
250
Java 27新機能 / Java 27 new features
kishida
2
110
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
150
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
320
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
320
Security issues being discussed on Web Platforms
petamoriken
0
870
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
170
Family mrubyの進捗
kishima
1
110
Featured
See All Featured
Claude Code のすすめ
schroneko
67
230k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.9k
Tell your own story through comics
letsgokoyo
1
1.1k
[SF Ruby Conf 2025] Rails X
palkan
2
1.4k
The agentic SEO stack - context over prompts
schlessera
0
930
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
600
Making the Leap to Tech Lead
cromwellryan
135
10k
Scaling GitHub
holman
464
140k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
840
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
520
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