The OpenD Programming Language

extMul

Extended unsigned multiplications. Performs U x U multiplication and returns ExtMulResult!U that contains extended result.

@nogc nothrow pure @trusted
extMul
(
U
)
(
in U a
,
in U b
)

Parameters

a U

unsigned integer

b U

unsigned integer

Return Value

Type: ExtMulResult!U

128bit result if U is ulong or 256bit result if U is ucent. Optimization: Algorithm is optimized for LDC (LLVM IR, any target) and for DMD (X86_64).

Examples

64bit x 64bit -> 128bit

immutable a = 0x93_8d_28_00_0f_50_a5_56;
immutable b = 0x54_c3_2f_e8_cc_a5_97_10;
enum c = extMul(a, b);     // Compile time algorithm
assert(extMul(a, b) == c); // Fast runtime algorithm
static assert(c.high == 0x30_da_d1_42_95_4a_50_78);
static assert(c.low == 0x27_9b_4b_b4_9e_fe_0f_60);

32bit x 32bit -> 64bit

immutable a = 0x0f_50_a5_56;
immutable b = 0xcc_a5_97_10;
static assert(cast(ulong)extMul(a, b) == ulong(a) * b);
immutable ushort a = 0xa5_56;
immutable ushort b = 0x97_10;
static assert(cast(uint)extMul(a, b) == a * b);
immutable ubyte a = 0x56;
immutable ubyte b = 0x10;
static assert(cast(ushort)extMul(a, b) == a * b);

Meta