4 ms·
It required a little bit of messing with optimisation settings and library generation in Rust, but they emit very very similar x86-64 assembly: https://godbolt
by 14113 3mo ago
It required a little bit of messing with optimisation settings and library generation in Rust, but they emit very very similar x86-64 assembly:
https://godbolt.org/z/89W4srz4d https://godbolt.org/z/89W4srz4d
- steveklabnik 3mo agoNice, thank you for picking up after my laziness. Surely only a few bytes different in the binary, and much, much smaller of a delta than the source.
- aw1621107 3mo agoYou can further reduce the difference by passing Expr by pointer in the C version. At that point I think the only difference in the assembly is the order in which the cases are handed.
- steveklabnik 3mo agoAh yeah, honestly both should probably be passed by pointer anyway. But that makes me wonder about the actual differences here and why... maybe something fun to dig into.
- 14113 3mo agoPassing by pointer (in C) reduced the difference a lot, but swapping the order of Add and Int in the Rust enum was enough to reduce the different to: cmp ecx, 1 je .LBB0_3 vs cmp ecx, 2 jne .LBB0_2 LBB0_3 and LBBO_2 were the same in both outputs (up to alpha renaming). Oddly, both sources seemed to be quite sensitive to match switch and enum reordering, resulting in very different generated code. Possibly something to look into further.