Cent/ucent why should we implement?
Dom Disc
dominikus at scherkl.de
Mon Sep 7 10:38:42 UTC 2026
On Sunday, 6 September 2026 at 10:33:15 UTC, Guillaume Piolat
wrote:
> On Sunday, 6 September 2026 at 02:03:09 UTC, Luna wrote:
>>
>> Makes writing float/double parsers far easier given then you
>> can assume that the compiler implements 128 bit values
>> correctly
>
> Clock conversion in video needs 64-bit * 64-bit => 128-bit
> result
This is already available in the registers. You just need to copy
it out:
```d
ulong[2] mul128(const ulong u, const ulong v) @safe pure @nogc
nothrow
{
ulong[2] r;
if(!u || !v) return r;
version(D_InlineAsm_X86)
{
asm @trusted pure @nogc nothrow
{
mov R8, r.ptr;
mov R9, v;
mov RAX, u;
mul R9;
mov [R8], RAX;
add R8, 8;
mov [R8], RDX;
}
}
else // without asm we have no access to the high bits of the
result
{
// this is awfully slow (4 multiplications, 6 additions and
8 shifts)
// but during CTFE this will only increase the compilation
time
// so maybe acceptable
enum m = uint.max;
ulong t;
t = (u & m)*(v & m);
r[0] = t & m;
t = (u>>32)*(v & m) + (t>>32);
r[1] = t>>32;
t = (u & m)*(v>>32) + (t & m);
r[0] += (t<<32);
r[1] += (u>>32)*(v>>32) + (t>>32);
}
return r; // r[1] contains the high bits of the product, r[0]
the low bits (big endian)
}
```
But at least, this function should be in Phobos.
More information about the Digitalmars-d
mailing list