Skip to content

API: long Math.BigMul(long, long, out long) #31184

@benaadams

Description

@benaadams

API Shape

To return 128 bit result (as per long BigMul(int a, int b))

partial class Math
{
    ulong BigMul(ulong a, ulong b, out ulong low);
    long BigMul(long a, long b, out long low);
}

Use case

Manual multiply high is now being used for Dictionary

Which looks like

(uint)((((ulong)(uint)left * right >> 32) + (left >> 32) * right) >> 32)

When ideally it would be

(uint)Math.BigMul(left, right, out _)

Other langs

While it is what the asm does (i.e. RDX:RAX ← RAX ∗ SRC) the apis either use a 128bit value or the split pair.

MSVC:

__int64 _mul128(__int64 Multiplier, __int64 Multiplicand, __int64 *HighProduct)
__int64 __mulh(__int64 a, __int64 b)

Others use * overloading on a __uint128_t type

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-System.Numericshelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions