authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-06-30 20:06:30+12:00
committergravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-06-30 21:58:59+12:00
log9f48b2ab48bcd6cfba45b8dfc60d0ad9633b294e
treef4b01cbfcebc40284d0b7fe7aec3f371e32fc799
parent814a34f263cbfeabbf7a898b3b70fa781baaccac

compiler_rt: Remove wrapping add/sub operators where unneeded

Closes #495.

8 files changed, 32 insertions(+), 32 deletions(-)

std/special/compiler_rt/floattidf.zig+2-2
......@@ -42,12 +42,12 @@ pub extern fn __floattidf(arg: i128) f64 {
4242 }
4343 // finish
4444 a |= @boolToInt((a & 4) != 0); // Or P into R
45 a +%= 1; // round - this step may add a significant bit
45 a += 1; // round - this step may add a significant bit
4646 a >>= 2; // dump Q and R
4747 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
4848 if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {
4949 a >>= 1;
50 e +%= 1;
50 e += 1;
5151 }
5252 // a is now rounded to DBL_MANT_DIG bits
5353 } else {
std/special/compiler_rt/floattisf.zig+2-2
......@@ -43,12 +43,12 @@ pub extern fn __floattisf(arg: i128) f32 {
4343 }
4444 // finish
4545 a |= @boolToInt((a & 4) != 0); // Or P into R
46 a +%= 1; // round - this step may add a significant bit
46 a += 1; // round - this step may add a significant bit
4747 a >>= 2; // dump Q and R
4848 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
4949 if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {
5050 a >>= 1;
51 e +%= 1;
51 e += 1;
5252 }
5353 // a is now rounded to FLT_MANT_DIG bits
5454 } else {
std/special/compiler_rt/floattitf.zig+2-2
......@@ -42,12 +42,12 @@ pub extern fn __floattitf(arg: i128) f128 {
4242 }
4343 // finish
4444 a |= @boolToInt((a & 4) != 0); // Or P into R
45 a +%= 1; // round - this step may add a significant bit
45 a += 1; // round - this step may add a significant bit
4646 a >>= 2; // dump Q and R
4747 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits
4848 if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {
4949 a >>= 1;
50 e +%= 1;
50 e += 1;
5151 }
5252 // a is now rounded to LDBL_MANT_DIG bits
5353 } else {
std/special/compiler_rt/floatunditf.zig+1-1
......@@ -1,6 +1,6 @@
11const builtin = @import("builtin");
22const is_test = builtin.is_test;
3const std = @import("../../index.zig");
3const std = @import("std");
44
55pub extern fn __floatunditf(a: u128) f128 {
66 @setRuntimeSafety(is_test);
std/special/compiler_rt/floatunsitf.zig+1-1
......@@ -1,6 +1,6 @@
11const builtin = @import("builtin");
22const is_test = builtin.is_test;
3const std = @import("../../index.zig");
3const std = @import("std");
44
55pub extern fn __floatunsitf(a: u64) f128 {
66 @setRuntimeSafety(is_test);
std/special/compiler_rt/floatuntidf.zig+8-8
......@@ -11,8 +11,8 @@ pub extern fn __floatuntidf(arg: u128) f64 {
1111
1212 var a = arg;
1313 const N: u32 = @sizeOf(u128) * 8;
14 const sd = @bitCast(i32, N -% @clz(a)); // number of significant digits
15 var e: i32 = sd -% 1; // exponent
14 const sd = @bitCast(i32, N - @clz(a)); // number of significant digits
15 var e: i32 = sd - 1; // exponent
1616 if (sd > DBL_MANT_DIG) {
1717 // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
1818 // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
......@@ -27,28 +27,28 @@ pub extern fn __floatuntidf(arg: u128) f64 {
2727 },
2828 DBL_MANT_DIG + 2 => {},
2929 else => {
30 const shift_amt = @bitCast(i32, N +% (DBL_MANT_DIG + 2)) -% sd;
30 const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd;
3131 const shift_amt_u7 = @intCast(u7, shift_amt);
32 a = (a >> @intCast(u7, sd -% (DBL_MANT_DIG + 2))) |
32 a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) |
3333 @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
3434 },
3535 }
3636 // finish
3737 a |= @boolToInt((a & 4) != 0); // Or P into R
38 a +%= 1; // round - this step may add a significant bit
38 a += 1; // round - this step may add a significant bit
3939 a >>= 2; // dump Q and R
4040 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
4141 if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {
4242 a >>= 1;
43 e +%= 1;
43 e += 1;
4444 }
4545 // a is now rounded to DBL_MANT_DIG bits
4646 } else {
47 a <<= @intCast(u7, DBL_MANT_DIG -% sd);
47 a <<= @intCast(u7, DBL_MANT_DIG - sd);
4848 // a is now rounded to DBL_MANT_DIG bits
4949 }
5050
51 const high: u64 = @bitCast(u32, (e +% 1023) << 20) | // exponent
51 const high: u64 = @bitCast(u32, (e + 1023) << 20) | // exponent
5252 (@truncate(u32, a >> 32) & 0x000FFFFF); // mantissa-high
5353 const low = @truncate(u32, a); // mantissa-low
5454
std/special/compiler_rt/floatuntisf.zig+8-8
......@@ -11,8 +11,8 @@ pub extern fn __floatuntisf(arg: u128) f32 {
1111
1212 var a = arg;
1313 const N: u32 = @sizeOf(u128) * 8;
14 const sd = @bitCast(i32, N -% @clz(a)); // number of significant digits
15 var e: i32 = sd -% 1; // exponent
14 const sd = @bitCast(i32, N - @clz(a)); // number of significant digits
15 var e: i32 = sd - 1; // exponent
1616 if (sd > FLT_MANT_DIG) {
1717 // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
1818 // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
......@@ -27,28 +27,28 @@ pub extern fn __floatuntisf(arg: u128) f32 {
2727 },
2828 FLT_MANT_DIG + 2 => {},
2929 else => {
30 const shift_amt = @bitCast(i32, N +% (FLT_MANT_DIG + 2)) -% sd;
30 const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd;
3131 const shift_amt_u7 = @intCast(u7, shift_amt);
32 a = (a >> @intCast(u7, sd -% (FLT_MANT_DIG + 2))) |
32 a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) |
3333 @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
3434 },
3535 }
3636 // finish
3737 a |= @boolToInt((a & 4) != 0); // Or P into R
38 a +%= 1; // round - this step may add a significant bit
38 a += 1; // round - this step may add a significant bit
3939 a >>= 2; // dump Q and R
4040 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
4141 if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {
4242 a >>= 1;
43 e +%= 1;
43 e += 1;
4444 }
4545 // a is now rounded to FLT_MANT_DIG bits
4646 } else {
47 a <<= @intCast(u7, FLT_MANT_DIG -% sd);
47 a <<= @intCast(u7, FLT_MANT_DIG - sd);
4848 // a is now rounded to FLT_MANT_DIG bits
4949 }
5050
51 const high = @bitCast(u32, (e +% 127) << 23); // exponent
51 const high = @bitCast(u32, (e + 127) << 23); // exponent
5252 const low = @truncate(u32, a) & 0x007fffff; // mantissa
5353
5454 return @bitCast(f32, high | low);
std/special/compiler_rt/floatuntitf.zig+8-8
......@@ -11,8 +11,8 @@ pub extern fn __floatuntitf(arg: u128) f128 {
1111
1212 var a = arg;
1313 const N: u32 = @sizeOf(u128) * 8;
14 const sd = @bitCast(i32, N -% @clz(a)); // number of significant digits
15 var e: i32 = sd -% 1; // exponent
14 const sd = @bitCast(i32, N - @clz(a)); // number of significant digits
15 var e: i32 = sd - 1; // exponent
1616 if (sd > LDBL_MANT_DIG) {
1717 // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
1818 // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
......@@ -27,28 +27,28 @@ pub extern fn __floatuntitf(arg: u128) f128 {
2727 },
2828 LDBL_MANT_DIG + 2 => {},
2929 else => {
30 const shift_amt = @bitCast(i32, N +% (LDBL_MANT_DIG + 2)) -% sd;
30 const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd;
3131 const shift_amt_u7 = @intCast(u7, shift_amt);
32 a = (a >> @intCast(u7, sd -% (LDBL_MANT_DIG + 2))) |
32 a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) |
3333 @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
3434 },
3535 }
3636 // finish
3737 a |= @boolToInt((a & 4) != 0); // Or P into R
38 a +%= 1; // round - this step may add a significant bit
38 a += 1; // round - this step may add a significant bit
3939 a >>= 2; // dump Q and R
4040 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits
4141 if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {
4242 a >>= 1;
43 e +%= 1;
43 e += 1;
4444 }
4545 // a is now rounded to LDBL_MANT_DIG bits
4646 } else {
47 a <<= @intCast(u7, LDBL_MANT_DIG -% sd);
47 a <<= @intCast(u7, LDBL_MANT_DIG - sd);
4848 // a is now rounded to LDBL_MANT_DIG bits
4949 }
5050
51 const high: u128 = (@intCast(u64, (e +% 16383)) << 48) | // exponent
51 const high: u128 = (@intCast(u64, (e + 16383)) << 48) | // exponent
5252 (@truncate(u64, a >> 64) & 0x0000ffffffffffff); // mantissa-high
5353 const low = @truncate(u64, a); // mantissa-low
5454