Closed
Description
I've tried, out of curiosity, a floating point arithmetic test and found quite a big difference between C++ and Rust.
The code used in rust
pub struct Stats
{
x: f32,
y: f32,
z: f32
}
pub fn sum(a: &Stats, b: &Stats) -> Stats
{
Stats {
x: a.x + b.x,
y: a.y + b.y,
z: a.z + b.z
}
}
The code used in C++
struct Stats
{
float x;
float y;
float z;
};
Stats sum(const Stats &a, const Stats &b)
{
return Stats {
a.x + b.x,
a.y + b.y,
a.z + b.z
};
}
Here is a link to a godbolt for side-by-side comparision of assembly output: https://godbolt.org/z/dqc4b74rv
Rust seem to absolutely want the floats back into e* registers instead of keeping them in xmm registers, C++ leaves them into the xmm registers. In some cases it might more advantageous to leave the floats in xmm registers for future operations on them rather then passing them back into the e* registers.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generationArea: Floating point numbers and arithmeticCategory: This is a bug.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.