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
790
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
Exploring x86 MSR Space
retrage
0
1.3k
LLMでバイナリ解析支援
retrage
0
170
GitHub ActionsでDevSecOpsごっこ
retrage
0
43
Practical Rust (Hypervisor) Firmware
retrage
3
1.6k
Bypassing UEFI Secure Boot with Thin-Hypervisor
retrage
0
1.1k
Porting Linux to Nabla Containers
retrage
0
1.2k
Network Boot from Bell Labs
retrage
2
1.6k
Unikernelで始める自作OS/OS Development with Unikernel
retrage
1
550
LLVM Backend Development for EFI Byte Code
retrage
2
940
Other Decks in Programming
See All in Programming
PostgreSQLのRow Level SecurityをPHPのORMで扱う Eloquent vs Doctrine #phpcon #track2
77web
2
530
LT 2025-06-30: プロダクトエンジニアの役割
yamamotok
0
760
iOS 26にアップデートすると実機でのHot Reloadができない?
umigishiaoi
0
130
なぜ「共通化」を考え、失敗を繰り返すのか
rinchoku
1
650
A2A プロトコルを試してみる
azukiazusa1
2
1.4k
NPOでのDevinの活用
codeforeveryone
0
830
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
820
チームのテスト力を総合的に鍛えて品質、スピード、レジリエンスを共立させる/Testing approach that improves quality, speed, and resilience
goyoki
5
870
AI時代のソフトウェア開発を考える(2025/07版) / Agentic Software Engineering Findy 2025-07 Edition
twada
PRO
86
28k
レベル1の開発生産性向上に取り組む − 日々の作業の効率化・自動化を通じた改善活動
kesoji
0
190
dbt民主化とLLMによる開発ブースト ~ AI Readyな分析サイクルを目指して ~
yoshyum
3
1k
AIと”コードの評価関数”を共有する / Share the "code evaluation function" with AI
euglena1215
1
160
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
The Cult of Friendly URLs
andyhume
79
6.5k
Done Done
chrislema
184
16k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
A Modern Web Designer's Workflow
chriscoyier
695
190k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.4k
Typedesign – Prime Four
hannesfritz
42
2.7k
Git: the NoSQL Database
bkeepers
PRO
430
65k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
Embracing the Ebb and Flow
colly
86
4.7k
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