http://d.puremagic.com/issues/show_bug.cgi?id=9320
Summary: Non-POD status of a struct correlated to bad inlining. Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nob...@puremagic.com ReportedBy: dran...@gmail.com --- Comment #0 from Nicolas Sicard <dran...@gmail.com> 2013-01-14 14:08:34 PST --- This codes defines a struct that is just a wrapper around a real x, with binary operators. --- struct Foo { real x; version(Constructor) { this(real x) { this.x = x; } } Foo opBinary(string op)(Foo other) { return Foo(mixin("x" ~ op ~ "other.x")); } } version(Constructor) static assert(!__traits(isPOD, Foo)); else static assert(__traits(isPOD, Foo)); Foo test(Foo a, Foo b, Foo c) { return (a + b) / (a * b) - c; } void main() {} --- When compiled with -O -inline -release, the object code for the test function is: --- push RBP mov RBP,RSP sub RSP,010h fld tbyte ptr 030h[RBP] fld tbyte ptr 020h[RBP] faddp ST(1),ST fld tbyte ptr 030h[RBP] fld tbyte ptr 020h[RBP] fmulp ST(1),ST fdivp ST(1),ST fld tbyte ptr 010h[RBP] fsubp ST(1),ST fstp tbyte ptr [RDI] mov word ptr 0Ah[RDI],0 mov dword ptr 0Ch[RDI],0 mov RAX,RDI mov RSP,RBP pop RBP ret --- When compiled with the same flags, but with -version=Constructor, I benchmarked the code as 5x slower (no data here) and the object code becomes: --- push RBP mov RBP,RSP sub RSP,0D0h mov -010h[RBP],RDI lea RSI,020h[RBP] lea RDI,-0A0h[RBP] movsd movsd mov RSI,[00h][RIP] lea RDI,-090h[RBP] movsd movsd fld tbyte ptr 030h[RBP] fld tbyte ptr -0A0h[RBP] faddp ST(1),ST fstp tbyte ptr -090h[RBP] mov word ptr -086h[RBP],0 mov dword ptr -084h[RBP],0 lea RSI,-090h[RBP] lea RDI,-0B0h[RBP] movsd movsd lea RSI,020h[RBP] lea RDI,-060h[RBP] movsd movsd mov RSI,[00h][RIP] lea RDI,-050h[RBP] movsd movsd fld tbyte ptr 030h[RBP] fld tbyte ptr -060h[RBP] fmulp ST(1),ST fstp tbyte ptr -050h[RBP] mov word ptr -046h[RBP],0 mov dword ptr -044h[RBP],0 lea RSI,-050h[RBP] lea RDI,-070h[RBP] movsd movsd lea RSI,-070h[RBP] lea RDI,-080h[RBP] movsd movsd mov RSI,[00h][RIP] lea RDI,-040h[RBP] movsd movsd fld tbyte ptr -0B0h[RBP] fld tbyte ptr -080h[RBP] fdivp ST(1),ST fstp tbyte ptr -040h[RBP] mov word ptr -036h[RBP],0 mov dword ptr -034h[RBP],0 lea RSI,-040h[RBP] lea RDI,-0C0h[RBP] movsd movsd lea RSI,010h[RBP] lea RDI,-030h[RBP] movsd movsd mov RSI,[00h][RIP] lea RDI,-020h[RBP] movsd movsd fld tbyte ptr -0C0h[RBP] fld tbyte ptr -030h[RBP] fsubp ST(1),ST fstp tbyte ptr -020h[RBP] mov word ptr -016h[RBP],0 mov dword ptr -014h[RBP],0 lea RSI,-020h[RBP] lea RDI,-0D0h[RBP] movsd movsd lea RSI,-0D0h[RBP] mov RDI,-010h[RBP] movsd movsd mov RAX,-010h[RBP] mov RSP,RBP pop RBP ret --- D2.061, OSX 10.8.2 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------