4 ms·
> It's not even clear to me that there's any overhead to the Rust version. There is a slight bit of stack overhead: Option<ForkResult> is at least {tag:u8, {ta
by masklinn 11y ago
> It's not even clear to me that there's any overhead to the Rust version.
There is a slight bit of stack overhead: Option<ForkResult> is at least {tag:u8, {tag:u8, pid:i32}}, and due to alignment constraints it's actually {tag: u32, {tag: u32, pid: i32 }}). A nonzero wrapper[0] would allow folding either ForkResult or Option into a 0-valued pid_t and remove one level of tagging: http://is.gd/yxStW1 http://is.gd/yxStW1
Beyond that you'd need generalised enum folding in order to fold two tags into the underlying value (you'd denote that pid_t is nonzero and nonnegative for instance)
[0] which is unstable, so not really an option
- pcwalton 11y agoBut if the wrappers get inlined (which they should be) then SROA kicks in and promotes the tags to SSA values, where other optimizations such as SCCP can eliminate them. Optimizing compilers are awesome :)
- arielb1 11y agoWe do have a planned optimization that would fold the tags for cases like `Option<ForkResult>` to give a word pair, which should be returned in %eax:%edx (or %rax:%rdx).
- Jweb_Guru 11y agoReally? That's exciting. Missed enum layout optimizations are one of my few issues with Rust right now.
- ant6n 11y agoTheoretically It should be possible to have a union based on the value of the ints {-1, 0, positive}, which should use only one 32bit integer.