Jump table

125 views
Skip to first unread message

Pierre Durand

unread,
Nov 27, 2025, 8:14:07 AM (8 days ago) Nov 27
to golang-nuts
Hello,

Does the Go compiler generate jump table ?
If I write a switch case (with fixed string or int value), and return immediately, does it generate a jump table ?
If so, can you show me the file where it is done.

Thank you :)

Jan Mercl

unread,
Nov 27, 2025, 8:31:13 AM (8 days ago) Nov 27
to Pierre Durand, golang-nuts

Pierre Durand

unread,
Nov 27, 2025, 9:54:44 AM (8 days ago) Nov 27
to golang-nuts
Thank you :)

Brian Candler

unread,
Nov 27, 2025, 10:39:09 AM (8 days ago) Nov 27
to golang-nuts
Aside: Godbolt is a useful tool if you want to see what assembly is generated for some given source code.

Try:

Pierre Durand

unread,
Nov 27, 2025, 11:43:37 AM (8 days ago) Nov 27
to golang-nuts
Yes I'm also using gobolt, but my switch/case was too small.
Thank you :) 

Jon Perryman

unread,
Nov 27, 2025, 11:13:46 PM (8 days ago) Nov 27
to golang-nuts
As an FYI, don't forget to specify -O3 otherwise you may see less than optimal asm code generated. Also note that hovering over the assembler instruction will display help text describing the instruction (useful for understanding instructions). You can easily switch between machine architectures to see it's effect.
Reply all
Reply to author
Forward
0 new messages