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 {...@@ -42,12 +42,12 @@ pub extern fn __floattidf(arg: i128) f64 {
42 }42 }
43 // finish43 // finish
44 a |= @boolToInt((a & 4) != 0); // Or P into R44 a |= @boolToInt((a & 4) != 0); // Or P into R
45 a +%= 1; // round - this step may add a significant bit45 a += 1; // round - this step may add a significant bit
46 a >>= 2; // dump Q and R46 a >>= 2; // dump Q and R
47 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits47 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
48 if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {48 if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {
49 a >>= 1;49 a >>= 1;
50 e +%= 1;50 e += 1;
51 }51 }
52 // a is now rounded to DBL_MANT_DIG bits52 // a is now rounded to DBL_MANT_DIG bits
53 } else {53 } else {
std/special/compiler_rt/floattisf.zig+2-2
...@@ -43,12 +43,12 @@ pub extern fn __floattisf(arg: i128) f32 {...@@ -43,12 +43,12 @@ pub extern fn __floattisf(arg: i128) f32 {
43 }43 }
44 // finish44 // finish
45 a |= @boolToInt((a & 4) != 0); // Or P into R45 a |= @boolToInt((a & 4) != 0); // Or P into R
46 a +%= 1; // round - this step may add a significant bit46 a += 1; // round - this step may add a significant bit
47 a >>= 2; // dump Q and R47 a >>= 2; // dump Q and R
48 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits48 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
49 if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {49 if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {
50 a >>= 1;50 a >>= 1;
51 e +%= 1;51 e += 1;
52 }52 }
53 // a is now rounded to FLT_MANT_DIG bits53 // a is now rounded to FLT_MANT_DIG bits
54 } else {54 } else {
std/special/compiler_rt/floattitf.zig+2-2
...@@ -42,12 +42,12 @@ pub extern fn __floattitf(arg: i128) f128 {...@@ -42,12 +42,12 @@ pub extern fn __floattitf(arg: i128) f128 {
42 }42 }
43 // finish43 // finish
44 a |= @boolToInt((a & 4) != 0); // Or P into R44 a |= @boolToInt((a & 4) != 0); // Or P into R
45 a +%= 1; // round - this step may add a significant bit45 a += 1; // round - this step may add a significant bit
46 a >>= 2; // dump Q and R46 a >>= 2; // dump Q and R
47 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits47 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits
48 if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {48 if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {
49 a >>= 1;49 a >>= 1;
50 e +%= 1;50 e += 1;
51 }51 }
52 // a is now rounded to LDBL_MANT_DIG bits52 // a is now rounded to LDBL_MANT_DIG bits
53 } else {53 } else {
std/special/compiler_rt/floatunditf.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const is_test = builtin.is_test;2const is_test = builtin.is_test;
3const std = @import("../../index.zig");3const std = @import("std");
44
5pub extern fn __floatunditf(a: u128) f128 {5pub extern fn __floatunditf(a: u128) f128 {
6 @setRuntimeSafety(is_test);6 @setRuntimeSafety(is_test);
std/special/compiler_rt/floatunsitf.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const is_test = builtin.is_test;2const is_test = builtin.is_test;
3const std = @import("../../index.zig");3const std = @import("std");
44
5pub extern fn __floatunsitf(a: u64) f128 {5pub extern fn __floatunsitf(a: u64) f128 {
6 @setRuntimeSafety(is_test);6 @setRuntimeSafety(is_test);
std/special/compiler_rt/floatuntidf.zig+8-8
...@@ -11,8 +11,8 @@ pub extern fn __floatuntidf(arg: u128) f64 {...@@ -11,8 +11,8 @@ pub extern fn __floatuntidf(arg: u128) f64 {
1111
12 var a = arg;12 var a = arg;
13 const N: u32 = @sizeOf(u128) * 8;13 const N: u32 = @sizeOf(u128) * 8;
14 const sd = @bitCast(i32, N -% @clz(a)); // number of significant digits14 const sd = @bitCast(i32, N - @clz(a)); // number of significant digits
15 var e: i32 = sd -% 1; // exponent15 var e: i32 = sd - 1; // exponent
16 if (sd > DBL_MANT_DIG) {16 if (sd > DBL_MANT_DIG) {
17 // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx17 // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
18 // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR18 // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
...@@ -27,28 +27,28 @@ pub extern fn __floatuntidf(arg: u128) f64 {...@@ -27,28 +27,28 @@ pub extern fn __floatuntidf(arg: u128) f64 {
27 },27 },
28 DBL_MANT_DIG + 2 => {},28 DBL_MANT_DIG + 2 => {},
29 else => {29 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;
31 const shift_amt_u7 = @intCast(u7, shift_amt);31 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))) |
33 @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);33 @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
34 },34 },
35 }35 }
36 // finish36 // finish
37 a |= @boolToInt((a & 4) != 0); // Or P into R37 a |= @boolToInt((a & 4) != 0); // Or P into R
38 a +%= 1; // round - this step may add a significant bit38 a += 1; // round - this step may add a significant bit
39 a >>= 2; // dump Q and R39 a >>= 2; // dump Q and R
40 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits40 // a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
41 if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {41 if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {
42 a >>= 1;42 a >>= 1;
43 e +%= 1;43 e += 1;
44 }44 }
45 // a is now rounded to DBL_MANT_DIG bits45 // a is now rounded to DBL_MANT_DIG bits
46 } else {46 } else {
47 a <<= @intCast(u7, DBL_MANT_DIG -% sd);47 a <<= @intCast(u7, DBL_MANT_DIG - sd);
48 // a is now rounded to DBL_MANT_DIG bits48 // a is now rounded to DBL_MANT_DIG bits
49 }49 }
5050
51 const high: u64 = @bitCast(u32, (e +% 1023) << 20) | // exponent51 const high: u64 = @bitCast(u32, (e + 1023) << 20) | // exponent
52 (@truncate(u32, a >> 32) & 0x000FFFFF); // mantissa-high52 (@truncate(u32, a >> 32) & 0x000FFFFF); // mantissa-high
53 const low = @truncate(u32, a); // mantissa-low53 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 {...@@ -11,8 +11,8 @@ pub extern fn __floatuntisf(arg: u128) f32 {
1111
12 var a = arg;12 var a = arg;
13 const N: u32 = @sizeOf(u128) * 8;13 const N: u32 = @sizeOf(u128) * 8;
14 const sd = @bitCast(i32, N -% @clz(a)); // number of significant digits14 const sd = @bitCast(i32, N - @clz(a)); // number of significant digits
15 var e: i32 = sd -% 1; // exponent15 var e: i32 = sd - 1; // exponent
16 if (sd > FLT_MANT_DIG) {16 if (sd > FLT_MANT_DIG) {
17 // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx17 // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
18 // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR18 // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
...@@ -27,28 +27,28 @@ pub extern fn __floatuntisf(arg: u128) f32 {...@@ -27,28 +27,28 @@ pub extern fn __floatuntisf(arg: u128) f32 {
27 },27 },
28 FLT_MANT_DIG + 2 => {},28 FLT_MANT_DIG + 2 => {},
29 else => {29 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;
31 const shift_amt_u7 = @intCast(u7, shift_amt);31 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))) |
33 @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);33 @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
34 },34 },
35 }35 }
36 // finish36 // finish
37 a |= @boolToInt((a & 4) != 0); // Or P into R37 a |= @boolToInt((a & 4) != 0); // Or P into R
38 a +%= 1; // round - this step may add a significant bit38 a += 1; // round - this step may add a significant bit
39 a >>= 2; // dump Q and R39 a >>= 2; // dump Q and R
40 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits40 // a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
41 if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {41 if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {
42 a >>= 1;42 a >>= 1;
43 e +%= 1;43 e += 1;
44 }44 }
45 // a is now rounded to FLT_MANT_DIG bits45 // a is now rounded to FLT_MANT_DIG bits
46 } else {46 } else {
47 a <<= @intCast(u7, FLT_MANT_DIG -% sd);47 a <<= @intCast(u7, FLT_MANT_DIG - sd);
48 // a is now rounded to FLT_MANT_DIG bits48 // a is now rounded to FLT_MANT_DIG bits
49 }49 }
5050
51 const high = @bitCast(u32, (e +% 127) << 23); // exponent51 const high = @bitCast(u32, (e + 127) << 23); // exponent
52 const low = @truncate(u32, a) & 0x007fffff; // mantissa52 const low = @truncate(u32, a) & 0x007fffff; // mantissa
5353
54 return @bitCast(f32, high | low);54 return @bitCast(f32, high | low);
std/special/compiler_rt/floatuntitf.zig+8-8
...@@ -11,8 +11,8 @@ pub extern fn __floatuntitf(arg: u128) f128 {...@@ -11,8 +11,8 @@ pub extern fn __floatuntitf(arg: u128) f128 {
1111
12 var a = arg;12 var a = arg;
13 const N: u32 = @sizeOf(u128) * 8;13 const N: u32 = @sizeOf(u128) * 8;
14 const sd = @bitCast(i32, N -% @clz(a)); // number of significant digits14 const sd = @bitCast(i32, N - @clz(a)); // number of significant digits
15 var e: i32 = sd -% 1; // exponent15 var e: i32 = sd - 1; // exponent
16 if (sd > LDBL_MANT_DIG) {16 if (sd > LDBL_MANT_DIG) {
17 // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx17 // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
18 // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR18 // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
...@@ -27,28 +27,28 @@ pub extern fn __floatuntitf(arg: u128) f128 {...@@ -27,28 +27,28 @@ pub extern fn __floatuntitf(arg: u128) f128 {
27 },27 },
28 LDBL_MANT_DIG + 2 => {},28 LDBL_MANT_DIG + 2 => {},
29 else => {29 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;
31 const shift_amt_u7 = @intCast(u7, shift_amt);31 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))) |
33 @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);33 @boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
34 },34 },
35 }35 }
36 // finish36 // finish
37 a |= @boolToInt((a & 4) != 0); // Or P into R37 a |= @boolToInt((a & 4) != 0); // Or P into R
38 a +%= 1; // round - this step may add a significant bit38 a += 1; // round - this step may add a significant bit
39 a >>= 2; // dump Q and R39 a >>= 2; // dump Q and R
40 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits40 // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits
41 if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {41 if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {
42 a >>= 1;42 a >>= 1;
43 e +%= 1;43 e += 1;
44 }44 }
45 // a is now rounded to LDBL_MANT_DIG bits45 // a is now rounded to LDBL_MANT_DIG bits
46 } else {46 } else {
47 a <<= @intCast(u7, LDBL_MANT_DIG -% sd);47 a <<= @intCast(u7, LDBL_MANT_DIG - sd);
48 // a is now rounded to LDBL_MANT_DIG bits48 // a is now rounded to LDBL_MANT_DIG bits
49 }49 }
5050
51 const high: u128 = (@intCast(u64, (e +% 16383)) << 48) | // exponent51 const high: u128 = (@intCast(u64, (e + 16383)) << 48) | // exponent
52 (@truncate(u64, a >> 64) & 0x0000ffffffffffff); // mantissa-high52 (@truncate(u64, a >> 64) & 0x0000ffffffffffff); // mantissa-high
53 const low = @truncate(u64, a); // mantissa-low53 const low = @truncate(u64, a); // mantissa-low
5454