On Tuesday, 23 May 2017 at 15:19:39 UTC, Andrei Alexandrescu wrote:
On 05/23/2017 09:42 AM, Stefan Koch wrote:
On Tuesday, 23 May 2017 at 13:27:42 UTC, Andrei Alexandrescu wrote:
On 5/22/17 4:51 PM, Johan Engelen wrote:

Thanks! Yes, seto is what I thought of - one way or another, it gets down to using a bit of machine-specific code to get there. I'll note that dmd does not generate seto (why?): https://goo.gl/nRjNMy. -- Andrei

it does this
overflow_flag = 0
if (overflowed)
   overflow_flag = 1;

Where did you see this pattern? Couldn't find it anywhere in core.checkedint. And how is "overflowed" tested?

this can in some circumstances be faster then using seto!
If the inliner does a good enough job :)

The code in core.checkedint is conservative:

pragma(inline, true)
ulong mulu(ulong x, ulong y, ref bool overflow)
    ulong r = x * y;
    if (x && (r / x) != y)
        overflow = true;
    return r;

The compiler is supposed to detect the pattern and generate optimal code.


That code is written nowhere.
It was my hand translation of the asm.
(And it was wrong)

The compiler does indeed seem to optimize the code somewhat.
Although the generated asm still looks wired.

Reply via email to