4 ms·
This is a nice summary! Kudos. Some nitpicks from someone who spends most of their professional day looking at machine code: * "Execution section" is a weird
by woodruffw 6y ago
This is a nice summary! Kudos.
Some nitpicks from someone who spends most of their professional day looking at machine code:
* "Execution section" is a weird phrase -- we'd normally talk about a specific section containing machine code (e.g., the `.text` section), or a collection of executable segments (i.e., regions that will be mapped with executable permissions at program load time).
* It's a stretch to call x86 "hardware independent." It has two major vendors (with a few peripheral ones), and is both complex and deeply generational (in terms of features being frequently added) as far as ISAs go. JVM bytecode is closer to hardware independent; LLVM IR can be hardware independent but frequently isn't in the real world.
* Rust and LLVM might not have done this because you ran a debug build, but I actually would have expected your `sum` function to have no stack allocations at all -- it's both small enough to fit within the red zone[1] and is also trivially promotable to registers. Sure enough, with `opt-level=1` or above, the compiler gets very clever and actually uses a `lea` to perform the sum[2].
[1]: https://en.wikipedia.org/wiki/Red_zone_(computing) https://en.wikipedia.org/wiki/Red_zone_(computing)
[2]: https://rust.godbolt.org/z/dojnvs https://rust.godbolt.org/z/dojnvs