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
CRubyの命令ディスパッチのしくみ
Search
utsubo
May 28, 2026
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CRubyの命令ディスパッチのしくみ
utsubo
May 28, 2026
More Decks by utsubo
See All by utsubo
slide.pdf
utsubo256
1
79
Kaigi on Rails 2025を楽しむためにやったこと
utsubo256
1
21
Shikumi.rb のしくみ
utsubo256
1
35
first_time_lt_meeting_16.pdf
utsubo256
1
80
RubyKaigi 2025振り返り 最大限楽しむためにやったこと/Kaigi Effect
utsubo256
1
78
Featured
See All Featured
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
370
New Earth Scene 8
popppiees
4
2.6k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
2k
Believing is Seeing
oripsolob
1
220
Rails Girls Zürich Keynote
gr2m
96
14k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
470
A Soul's Torment
seathinner
8
3.6k
Test your architecture with Archunit
thirion
2
2.4k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
520
For a Future-Friendly Web
brad_frost
183
10k
Transcript
CRuby の命令ディスパッチのしくみ utsubo 2026/5/28 柏.rb #23
自己紹介 utsubo (@utsubo1024) FBC 生 Shikumi.rb を主催しています 最近ハマっていること: YARV の
しくみ
命令ディスパッチとは ここでの命令とはISeq に並ぶopcode のこと 参照: YARV Maniacs 【第 3 回】
命令ディスパッチの高速化 https://magazine.rubyist.net/articles/0008/0008-YarvManiacs.html 命令によってそれに応じた処理をさせること
今回は 1 + 2 * 3 を例にして、 命令ディスパッチのしくみを深掘りしていきます!
1 + 2 * 3 のコンパイル結果 ruby 4.0.3 で実行
どこで実行されるか
命令ディスパッチの実装 vm.c:97-105 (vm_exec_core() 内) v4.0.3 のソースコードを参照
マクロ展開 make V=1 vm.i を実行して、 vm.c を前処理( マクロ展開等) した vm.i
ファイルを作成する
展開されたINSN_DISPATCH() vm.i *reg_pc: 次に実行する命令ハンドラのアドレス
命令ハンドラ 各opcode に対応した、その命令を実装するC コードの実装部分。 insns.def に各opcode の定義が書かれていて、ビルド時に vm.inc ファイル に変換され、vm_exec_core
関数内でinclude される。 命令ディスパッチ opcode に応じた処理をさせること 命令ハンドラ その処理の実装部分
命令ハンドラの実装 例. putobject vm.inc:861-888 874 行目のADD_PC(INSN_AT TR(width)); pc を次の命令ハンドラのアドレス位置 まで進める
880 行目のINC_SP(INSN_AT TR(sp_inc)) スタックを1 つ増やす 881 行目のTOPN(0) = val; そのスタックにval を書き込む 887 行目のEND_INSN(putobject); *reg_pc の命令ハンドラへgoto でジャ ンプする
まとめ 1 + 2 * 3 はISeq にコンパイルされる ISeq にはopcode
とoperand が並んでいる CRuby のVM はopcode に対応する命令ハンドラへ制御 を移しながら処理を実行している VM がopcode に応じて命令ハンドラへ制御を移す処理 を命令ディスパッチと呼ぶ