Thread overview
is there a way to do _umul128 on posix ?
Sep 10
a11e99z
Sep 10
a11e99z
Sep 10
Kagamin
September 10
I need _umul128 to do the fast math,   is there a way to made it work for posix ?

On windows I can use _umul128, is there a ASM or work around in LDC to do this on posix ?






September 10
On Tuesday, 10 September 2019 at 04:13:25 UTC, Newbie2019 wrote:
> I need _umul128 to do the fast math,   is there a way to made it work for posix ?
>
> On windows I can use _umul128, is there a ASM or work around in LDC to do this on posix ?

I need this to work:  __uint128_t	r = uint64_t * uint64_t;

September 10
On Tuesday, 10 September 2019 at 04:13:25 UTC, Newbie2019 wrote:
> I need _umul128 to do the fast math,   is there a way to made it work for posix ?
>
> On windows I can use _umul128, is there a ASM or work around in LDC to do this on posix ?

https://run.dlang.io/is/2xYt5j

struct m128 { ulong lo, hi; }

// REX.W + F7 /4 	MUL r/m64 	(RDX:RAX ← RAX ∗ r/m64).
// https://en.wikipedia.org/wiki/X86_calling_conventions#x86-64_calling_conventions
// Windows RCX, RDX, R8, R9. returns RAX only
// Linux RDI, RSI, RDX, RCX, R8, R9. returns RDX:RAX
m128 mul128( ulong a, ulong b ) pure nothrow @nogc @trusted {
    asm pure @nogc nothrow {
	naked;
	mov RAX, RDI;
        mul RSI;
        ret;
    }
}
// probably u can do it inline


September 10
https://forum.dlang.org/post/nydunscuwdcinamqails@forum.dlang.org
September 10
On Tuesday, 10 September 2019 at 07:34:49 UTC, a11e99z wrote:
> On Tuesday, 10 September 2019 at 04:13:25 UTC, Newbie2019 wrote:
>> I need _umul128 to do the fast math,   is there a way to made it work for posix ?
>>
>> On windows I can use _umul128, is there a ASM or work around in LDC to do this on posix ?
>
> https://run.dlang.io/is/2xYt5j
>
> struct m128 { ulong lo, hi; }
>
> // REX.W + F7 /4 	MUL r/m64 	(RDX:RAX ← RAX ∗ r/m64).
> // https://en.wikipedia.org/wiki/X86_calling_conventions#x86-64_calling_conventions
> // Windows RCX, RDX, R8, R9. returns RAX only
> // Linux RDI, RSI, RDX, RCX, R8, R9. returns RDX:RAX
> m128 mul128( ulong a, ulong b ) pure nothrow @nogc @trusted {
>     asm pure @nogc nothrow {
> 	naked;
> 	mov RAX, RDI;
>         mul RSI;
>         ret;
>     }
> }
> // probably u can do it inline

just realized that D uses the registers in the reverse order than Linux convention (maybe Windows too).
one more WTF.
September 10
On Tuesday, 10 September 2019 at 08:50:39 UTC, Kagamin wrote:
> https://forum.dlang.org/post/nydunscuwdcinamqails@forum.dlang.org

Thanks, this work great for me.


On Tuesday, 10 September 2019 at 07:34:49 UTC, a11e99z wrote:
> On Tuesday, 10 September 2019 at 04:13:25 UTC, Newbie2019 wrote: https://run.dlang.io/is/2xYt5j
>
> struct m128 { ulong lo, hi; }
>

Thanks for the tips.