[Issue 12958] core.checkedint.mulu is broken

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jun 24 07:30:25 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12958

--- Comment #3 from David Nadlinger <code at klickverbot.at> ---
(In reply to David Bregman from comment #2)
> To do the full thing, I'm pretty sure we essentially need to use addu()
> (inlined of course) to sum the partials.

I agree.

> So here's my proposed solution (below): The overflow checks are written in
> such a way that DMD is able to generate branchless code (I checked the
> assembler).

At first glance, this looks good, but chances are I've missed to check some
other edge cases. To this end, it would be awesome if somebody could write a
quick test harness that verifies random multiplication results using BigInt
arithmetic.

Let me also note that performance does not really matter here, as any such
explicit implementation will be much slower than simply using the appropriate
hardware instructions (mul/seto or mul/jno/mov). LDC will map the functions
onto the respective LLVM intrinsics, and I suppose DMD will do something
similar.

--


More information about the Digitalmars-d-bugs mailing list