is there a way to do _umul128 on posix ?

a11e99z black80 at bk.ru
Tue Sep 10 09:04:46 UTC 2019


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.


More information about the digitalmars-d-ldc mailing list