core.checkedint?
safety0ff via digitalmars-d-ldc
digitalmars-d-ldc at puremagic.com
Sat Nov 1 10:55:52 PDT 2014
I'm not terribly interested in preparing a PR for this, but I
believe the code should be something like this (untested):
ldc/src/core/checkedint.d:
uint mulu(uint x, uint y, ref bool overflow)
{
+ version (LDC)
+ {
+ auto res = llvm_umul_with_overflow(x, y);
+ overflow |= res.overflow;
+ return res.result;
+ }
+ else
+ {
ulong r = ulong(x) * ulong(y);
if (r > uint.max)
overflow = true;
return cast(uint)r;
+ }
}
Rinse and repeat with:
llvm_uadd_with_overflow, llvm_sadd_with_overflow,
llvm_usub_with_overflow, llvm_ssub_with_overflow,
llvm_smul_with_overflow.
More information about the digitalmars-d-ldc
mailing list