www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - is there a way to do _umul128 on posix ?

reply Newbie2019 <newbie2019 gmail.com> writes:
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 ?
Sep 09 2019
next sibling parent Newbie2019 <newbie2019 gmail.com> writes:
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;
Sep 09 2019
prev sibling next sibling parent reply a11e99z <black80 bk.ru> writes:
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
Sep 10 2019
parent a11e99z <black80 bk.ru> writes:
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.
Sep 10 2019
prev sibling parent reply Kagamin <spam here.lot> writes:
https://forum.dlang.org/post/nydunscuwdcinamqails forum.dlang.org
Sep 10 2019
parent Newbie2019 <newbie2019 gmail.com> writes:
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.
Sep 10 2019