Generating checked integral operations [WAS: Trip notes from Israel]

Andrei Alexandrescu via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Tue May 23 08:43:24 PDT 2017


On 05/23/2017 11:37 AM, Stefan Koch wrote:
> 
> The compiler does indeed seem to optimize the code somewhat.
> Although the generated asm still looks wired.
> http://asm.dlang.org/#compilers:!((compiler:dmd_nightly,options:'-dip25+-O+-release+-inline+-m32',source:'import+core.checkedint%3B%0A%0Aalias+T+%3D+ulong%3B%0Aextern+(C)+T+foo(uint+x,+uint+y,+ref+bool+overflow)%0A%7B%0A+++return+mulu(x,+y,+overflow)%3B%0A%7D%0A')),filterAsm:(binary:!t,intel:!t),version:3 

That call enters a different overload:

pragma(inline, true)
uint mulu(uint x, uint y, ref bool overflow)
{
     ulong r = ulong(x) * ulong(y);
     if (r > uint.max)
         overflow = true;
     return cast(uint)r;
}

which is of efficiency comparable with code using seto. I'm not too 
worried about that. https://goo.gl/eRXUpr is of interest.


Andrei


More information about the Digitalmars-d-announce mailing list