Trip notes from Israel
Stefan Koch via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Tue May 23 08:37:39 PDT 2017
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
>> op
>> 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.
>
>
> Andrei
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.
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
More information about the Digitalmars-d-announce
mailing list