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
720
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.1k
LLMでバイナリ解析支援
retrage
0
150
GitHub ActionsでDevSecOpsごっこ
retrage
0
34
Practical Rust (Hypervisor) Firmware
retrage
3
1.5k
Bypassing UEFI Secure Boot with Thin-Hypervisor
retrage
0
1.1k
Porting Linux to Nabla Containers
retrage
0
1.1k
Network Boot from Bell Labs
retrage
2
1.5k
Unikernelで始める自作OS/OS Development with Unikernel
retrage
1
510
LLVM Backend Development for EFI Byte Code
retrage
2
870
Other Decks in Programming
See All in Programming
Conform を推す - Advocating for Conform
mizoguchicoji
3
690
SwiftUIで単方向アーキテクチャを導入して得られた成果
takuyaosawa
0
270
Grafana Cloudとソラカメ
devoc
0
170
もう僕は OpenAPI を書きたくない
sgash708
5
1.6k
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
120
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
150
密集、ドキュメントのコロケーション with AWS Lambda
satoshi256kbyte
0
190
第3回関東Kaggler会_AtCoderはKaggleの役に立つ
chettub
3
1k
Formの複雑さに立ち向かう
bmthd
1
850
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
160
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
340
dbt Pythonモデルで実現するSnowflake活用術
trsnium
0
150
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Thoughts on Productivity
jonyablonski
69
4.5k
The Cult of Friendly URLs
andyhume
78
6.2k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Gamification - CAS2011
davidbonilla
80
5.1k
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