checkedint call removal

via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 28 03:39:40 PDT 2014


On Monday, 28 July 2014 at 09:46:34 UTC, bearophile wrote:
>     uint y = 3_000_000_000;
>     writeln(x, " ", y);
>     writeln(x * y);

D promotes int to uint, right? Which is a bad idea. It should 
promote to long, right?

>     bool overflow = false;
>     immutable r1 = muls(x, y, overflow);

Why does muls accept this without an explicit cast to signed 
operands long? If the result is signed, the operands should be 
signed?

>     overflow = false;
>     immutable r2 = mulu(x, y, overflow);

Well, it overflows because you multiply 0xfffffffff with 
3000000000 if it promotes int to uint, but the result would still 
be incorrect without an overflow if the values were -1 and 1. You 
would get 0xffffffff without an overflow/underflow.

(I might get it all wrong here, I didn't run the code.)

However, if you manually remove overflow checks, you probably 
need to check that you still get vectorized output with 
auto-vectorization. Maybe it is better that the backend deals 
with it. Dunno.


More information about the Digitalmars-d mailing list