<div dir="ltr"><div>I asked Grok to write me a portable 64x64->128 multiplication function in D to get the pattern, and this is what it wrote:</div><div><br></div><div>// Multiplies two 64-bit unsigned integers, returning a 128-bit result as (low, high)<br>(ulong, ulong) mul64x64to128(ulong x, ulong y) {<br>    // Split into 32-bit halves<br>    uint x_l = cast(uint)x;<br>    uint x_h = cast(uint)(x >> 32);<br>    uint y_l = cast(uint)y;<br>    uint y_h = cast(uint)(y >> 32);<br>    <br>    // Compute partial products<br>    ulong p_ll = cast(ulong)x_l * y_l;        // Bits 0-63<br>    ulong p_lh = cast(ulong)x_l * y_h;        // Bits 32-95<br>    ulong p_hl = cast(ulong)x_h * y_l;        // Bits 32-95<br>    ulong p_hh = cast(ulong)x_h * y_h;        // Bits 64-127<br>    <br>    ulong low = p_ll;                         // Lower 64 bits<br>    uint p_lh_low = cast(uint)p_lh;<br>    uint p_hl_low = cast(uint)p_hl;<br>    uint p_ll_high = cast(uint)(p_ll >> 32);<br>    <br>    // Compute carry from middle terms<br>    ulong sum_mid = cast(ulong)p_lh_low + p_hl_low + p_ll_high;<br>    ulong carry = sum_mid >> 32;<br>    <br>    // Upper 64 bits<br>    ulong high = p_hh + (p_lh >> 32) + (p_hl >> 32) + carry;<br>    <br>    return (low, high);<br>}</div><div><br></div><div><br></div><div>What I loved is that its function returned a pair of ulong's, because apparently it made an assumption that we had in-language tuples! I wonder where it got that idea?</div><div><br></div><div>We should learn from our AI overlords! :P</div></div>