Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Godbolt is a fun tool: https://godbolt.org/

The story I heard, was that the author is one of these obsessive genius types, who was having a debate about compiler efficiency, so he wrote an entire compiler engine to prove his point.

I can understand that.

This is a great article. Being able to descend into machine code/assembly is a valuable “tool of last resort.”

Personally, I avoid that like the plague, but an OS developer probably still needs to do this (I developed system stuff, back in the Dawn Times).

I started off with Machine Code, so it’s been a long, strange trip, for me...



IMHO you don't have to be obsessive to use godbolt.org in your daily work, neither should it be a "tool of last resort".

It really does help a lot to understand what the compiler will actually turn your high level code into, because quite often the results are very surprising (or if only to be shocked about the amount of assembly code that's generated from a few lines of C++ template code). Comparing the differences in output between different compilers and optimization levels is also very useful.


I consider Godbolt to be an educational and “thinking cap” tool, as opposed to a critical path optimization tool.

It is pretty damn cool, though.

It’s sort of like how an algebraic graphing app is most useful for students, as opposed to working engineers.

Nowadays, with on-chip threading, ASM stack dumps are a lot less useful than they used to be. Really, for me, munged function names are what I use to figure out the general vicinity of a bug, which I then figure out, by examining the source.


There was a great interview with Matt Godbolt on the CoRecursive podcast: https://corecursive.com/to-the-assembly/

Touches on a lot of good reasons why someone might still want to understand assembly in this day and age.


I don't understand this tool. My compiler has a flag for generating assembly output. That should be sufficient, no? Also, it more accurately reflects what my compiler actually generates given all the other flags.


Your compiler does, yes. Godbolt gives you everyone else's compilers, across a huge range of versions and architectures, without having to install anything.

It's quite often easier to just slam something into godbolt than to do it locally with a temporary file and gcc -S.


An important feature of godbolt is quickly comparing the output and language feature support of different compilers, or different versions of the same compiler (e.g. what versions of MSVC support a specific C99 feature, or which new C++ feature is safe to use across clang, gcc and MSVC).

And most importantly, you can check what your code would look like when compiled for 6502 or Z80 ;)


I see, but I'm not convinced a web-tool is the best way to go about it if optimizing assembly is part of one's dayjob.

I do understand that it's nice to play with, and that it can have educational value. I would personally love to see WASM support, and a way to see e.g. LLVM intermediate code. But I'd want to see some more documentation on the website e.g. about the ABI so I know how the arguments of a function are passed in etc.


> I'm not convinced a web-tool is the best way to go about it if optimizing assembly is one's dayjob.

It isn't, because that's not what it's for. Besides, few people have optimizing assembly as a dayjob, and in that case you'd be writing it rather than reading it. Trying to juice a compiler into producing specific assembly output is frustrating and brittle. I suppose it's useful for seeing whether your autovectorisation has worked.

But the best use of godbolt - uniquely as a web tool - is to show other people what the output is.

(I wish more people would stop before saying "tool X is useless for workflow Y" and ask themselves what the intended workflow of tool X is. Not everything is for everybody, that would be impossible.)

> more documentation on the website e.g. about the ABI so I know how the arguments of a function are passed in etc

It just calls the underlying compiler executables. Consult their documentation.


There's quite a range between "looking at compiler output is sometimes useful" and "optimizing assembly is one's day job".

We use it all the time, it's certainly not just a toy.

I have the luxury of having a build farm with a large range of compilers and platforms available, so I could use that to rig something like godbolt. But that'd be spending probably days on setting something up, + ongoing maintenance, instead of just using an existing thing that does the job? If I really were only doing this kind of thing, that'd probably be worth it to be able to customize etc. But I'm not. It being a service (and thus basically automatically a web tool) is a a valuable feature.

It's also a great tool to share and communicate results of such investigations. Again, easy for a web tool.


There's a few nice hidden features presented in Matt Godbolt's talk here:

https://www.youtube.com/watch?v=kIoZDUd5DKw

As for LLVM IR output, just use the right clang command line options:

https://www.godbolt.org/z/r7f6TY

Likewise for WASM:

https://www.godbolt.org/z/Kr6G3K




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: