compiler_rt: Remove wrapping add/sub operators where unneeded

Closes #495.
This commit is contained in:
Marc Tiehuis 2018-06-30 20:06:30 +12:00
parent 814a34f263
commit 9f48b2ab48
8 changed files with 32 additions and 32 deletions

View File

@ -42,12 +42,12 @@ pub extern fn __floattidf(arg: i128) f64 {
}
// finish
a |= @boolToInt((a & 4) != 0); // Or P into R
a +%= 1; // round - this step may add a significant bit
a += 1; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {
a >>= 1;
e +%= 1;
e += 1;
}
// a is now rounded to DBL_MANT_DIG bits
} else {

View File

@ -43,12 +43,12 @@ pub extern fn __floattisf(arg: i128) f32 {
}
// finish
a |= @boolToInt((a & 4) != 0); // Or P into R
a +%= 1; // round - this step may add a significant bit
a += 1; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {
a >>= 1;
e +%= 1;
e += 1;
}
// a is now rounded to FLT_MANT_DIG bits
} else {

View File

@ -42,12 +42,12 @@ pub extern fn __floattitf(arg: i128) f128 {
}
// finish
a |= @boolToInt((a & 4) != 0); // Or P into R
a +%= 1; // round - this step may add a significant bit
a += 1; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits
if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {
a >>= 1;
e +%= 1;
e += 1;
}
// a is now rounded to LDBL_MANT_DIG bits
} else {

View File

@ -1,6 +1,6 @@
const builtin = @import("builtin");
const is_test = builtin.is_test;
const std = @import("../../index.zig");
const std = @import("std");
pub extern fn __floatunditf(a: u128) f128 {
@setRuntimeSafety(is_test);

View File

@ -1,6 +1,6 @@
const builtin = @import("builtin");
const is_test = builtin.is_test;
const std = @import("../../index.zig");
const std = @import("std");
pub extern fn __floatunsitf(a: u64) f128 {
@setRuntimeSafety(is_test);

View File

@ -11,8 +11,8 @@ pub extern fn __floatuntidf(arg: u128) f64 {
var a = arg;
const N: u32 = @sizeOf(u128) * 8;
const sd = @bitCast(i32, N -% @clz(a)); // number of significant digits
var e: i32 = sd -% 1; // exponent
const sd = @bitCast(i32, N - @clz(a)); // number of significant digits
var e: i32 = sd - 1; // exponent
if (sd > DBL_MANT_DIG) {
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
@ -27,28 +27,28 @@ pub extern fn __floatuntidf(arg: u128) f64 {
},
DBL_MANT_DIG + 2 => {},
else => {
const shift_amt = @bitCast(i32, N +% (DBL_MANT_DIG + 2)) -% sd;
const shift_amt = @bitCast(i32, N + (DBL_MANT_DIG + 2)) - sd;
const shift_amt_u7 = @intCast(u7, shift_amt);
a = (a >> @intCast(u7, sd -% (DBL_MANT_DIG + 2))) |
a = (a >> @intCast(u7, sd - (DBL_MANT_DIG + 2))) |
@boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
},
}
// finish
a |= @boolToInt((a & 4) != 0); // Or P into R
a +%= 1; // round - this step may add a significant bit
a += 1; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits
if ((a & (u128(1) << DBL_MANT_DIG)) != 0) {
a >>= 1;
e +%= 1;
e += 1;
}
// a is now rounded to DBL_MANT_DIG bits
} else {
a <<= @intCast(u7, DBL_MANT_DIG -% sd);
a <<= @intCast(u7, DBL_MANT_DIG - sd);
// a is now rounded to DBL_MANT_DIG bits
}
const high: u64 = @bitCast(u32, (e +% 1023) << 20) | // exponent
const high: u64 = @bitCast(u32, (e + 1023) << 20) | // exponent
(@truncate(u32, a >> 32) & 0x000FFFFF); // mantissa-high
const low = @truncate(u32, a); // mantissa-low

View File

@ -11,8 +11,8 @@ pub extern fn __floatuntisf(arg: u128) f32 {
var a = arg;
const N: u32 = @sizeOf(u128) * 8;
const sd = @bitCast(i32, N -% @clz(a)); // number of significant digits
var e: i32 = sd -% 1; // exponent
const sd = @bitCast(i32, N - @clz(a)); // number of significant digits
var e: i32 = sd - 1; // exponent
if (sd > FLT_MANT_DIG) {
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
@ -27,28 +27,28 @@ pub extern fn __floatuntisf(arg: u128) f32 {
},
FLT_MANT_DIG + 2 => {},
else => {
const shift_amt = @bitCast(i32, N +% (FLT_MANT_DIG + 2)) -% sd;
const shift_amt = @bitCast(i32, N + (FLT_MANT_DIG + 2)) - sd;
const shift_amt_u7 = @intCast(u7, shift_amt);
a = (a >> @intCast(u7, sd -% (FLT_MANT_DIG + 2))) |
a = (a >> @intCast(u7, sd - (FLT_MANT_DIG + 2))) |
@boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
},
}
// finish
a |= @boolToInt((a & 4) != 0); // Or P into R
a +%= 1; // round - this step may add a significant bit
a += 1; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits
if ((a & (u128(1) << FLT_MANT_DIG)) != 0) {
a >>= 1;
e +%= 1;
e += 1;
}
// a is now rounded to FLT_MANT_DIG bits
} else {
a <<= @intCast(u7, FLT_MANT_DIG -% sd);
a <<= @intCast(u7, FLT_MANT_DIG - sd);
// a is now rounded to FLT_MANT_DIG bits
}
const high = @bitCast(u32, (e +% 127) << 23); // exponent
const high = @bitCast(u32, (e + 127) << 23); // exponent
const low = @truncate(u32, a) & 0x007fffff; // mantissa
return @bitCast(f32, high | low);

View File

@ -11,8 +11,8 @@ pub extern fn __floatuntitf(arg: u128) f128 {
var a = arg;
const N: u32 = @sizeOf(u128) * 8;
const sd = @bitCast(i32, N -% @clz(a)); // number of significant digits
var e: i32 = sd -% 1; // exponent
const sd = @bitCast(i32, N - @clz(a)); // number of significant digits
var e: i32 = sd - 1; // exponent
if (sd > LDBL_MANT_DIG) {
// start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
// finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
@ -27,28 +27,28 @@ pub extern fn __floatuntitf(arg: u128) f128 {
},
LDBL_MANT_DIG + 2 => {},
else => {
const shift_amt = @bitCast(i32, N +% (LDBL_MANT_DIG + 2)) -% sd;
const shift_amt = @bitCast(i32, N + (LDBL_MANT_DIG + 2)) - sd;
const shift_amt_u7 = @intCast(u7, shift_amt);
a = (a >> @intCast(u7, sd -% (LDBL_MANT_DIG + 2))) |
a = (a >> @intCast(u7, sd - (LDBL_MANT_DIG + 2))) |
@boolToInt((a & (u128(@maxValue(u128)) >> shift_amt_u7)) != 0);
},
}
// finish
a |= @boolToInt((a & 4) != 0); // Or P into R
a +%= 1; // round - this step may add a significant bit
a += 1; // round - this step may add a significant bit
a >>= 2; // dump Q and R
// a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits
if ((a & (u128(1) << LDBL_MANT_DIG)) != 0) {
a >>= 1;
e +%= 1;
e += 1;
}
// a is now rounded to LDBL_MANT_DIG bits
} else {
a <<= @intCast(u7, LDBL_MANT_DIG -% sd);
a <<= @intCast(u7, LDBL_MANT_DIG - sd);
// a is now rounded to LDBL_MANT_DIG bits
}
const high: u128 = (@intCast(u64, (e +% 16383)) << 48) | // exponent
const high: u128 = (@intCast(u64, (e + 16383)) << 48) | // exponent
(@truncate(u64, a >> 64) & 0x0000ffffffffffff); // mantissa-high
const low = @truncate(u64, a); // mantissa-low