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
BrainF*ckの高速化
Search
Akira Moroo
March 04, 2018
Programming
0
860
BrainF*ckの高速化
以下の内容の解説です.
https://eli.thegreenplace.net/2017/adventures-in-jit-compilation-part-1-an-interpreter/
Akira Moroo
March 04, 2018
Tweet
Share
More Decks by Akira Moroo
See All by Akira Moroo
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
150
Exploring x86 MSR Space
retrage
0
1.4k
LLMでバイナリ解析支援
retrage
0
220
GitHub ActionsでDevSecOpsごっこ
retrage
0
91
Practical Rust (Hypervisor) Firmware
retrage
3
1.8k
Bypassing UEFI Secure Boot with Thin-Hypervisor
retrage
0
1.2k
Porting Linux to Nabla Containers
retrage
0
1.2k
Network Boot from Bell Labs
retrage
2
1.7k
Unikernelで始める自作OS/OS Development with Unikernel
retrage
1
650
Other Decks in Programming
See All in Programming
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
120
Claude Codeセッション現状確認 2026福岡 / fukuoka-aicoding-00-beacon
monochromegane
4
410
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
530
ロボットのための工場に灯りは要らない
watany
7
1.9k
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
350
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
220
Geminiの機能を調べ尽くしてみた
naruyoshimi
0
200
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
180
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
690
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
400
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
470
ベクトル検索のフィルタを用いた機械学習モデルとの統合 / python-meetup-fukuoka-06-vector-attr
monochromegane
2
360
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
Done Done
chrislema
186
16k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
170
Designing Experiences People Love
moore
143
24k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.1k
The Spectacular Lies of Maps
axbom
PRO
1
600
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
67
My Coaching Mixtape
mlcsv
0
69
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Transcript
BrainF*ckの高速化 2018/03/04 Dentoo.LT 19 @retrage
BrainF*ck? • BrainFuck (BF) • いわゆる難解プログラミング言語 • ><+-.,[]の8個の命令から成る • 言語処理系入門に最適
1
愚直なBF処理系は遅い • [と]は条件付きジャンプ命令 • [はポインタの指す値が0ならば次の]までジャンプ • ]はポインタの指す値が0でないならば次の[までジャン プ • 愚直なBF処理系では間にある命令は実行されな
いにも関わらず読み出される • ⇒初期化時にあらかじめJumpTableを作成しておく 2
ホットスポットを探す • 命令の実行には局所性がある • 一部の命令は大量に実行されるが,他の命令はあまり 実行されない • 例: データポインタを7デクリメント •
BF: <<<<<<< • C: dataptr -= 7; • ⇒ホットスポットに対応するBFより高水準な命令を 追加,初期化時にBFをこれらの命令に変換,実行 3
ループの最適化 • [と]のループには使われるパターンが存在 • 例: 現在のメモリを0にセット • C: data[data_ptr] =
0; • BF: [-] • 一見短いが,0になるまでループされる • ⇒ループパターンを表現する高水準な命令を追加 4
まとめ • BrainF*ckは実装しやすい言語処理系 • JumpTableで高速化 • 高水準な命令へ変換することで高速化 • ループのパターンを高水準な命令へ変換 •
Rustでの実装 • https://github.com/retrage/brainfuck-rs 5
参考文献 • https://ja.wikipedia.org/wiki/Brainfuck • https://eli.thegreenplace.net/2017/adventures-in- jit-compilation-part-1-an-interpreter/ • https://postd.cc/adventures-in-jit-compilation-part- 1-an-interpreter/ •
https://github.com/retrage/brainfuck-rs 6