diff --git a/crates/panic-handler/Cargo.toml b/crates/panic-handler/Cargo.toml index 2ad858409..92fbb748a 100644 --- a/crates/panic-handler/Cargo.toml +++ b/crates/panic-handler/Cargo.toml @@ -5,4 +5,8 @@ authors = ["Alex Crichton "] edition = "2021" publish = false +[lib] +test = false +bench = false + [dependencies] diff --git a/src/int/addsub.rs b/src/int/addsub.rs deleted file mode 100644 index e95590d84..000000000 --- a/src/int/addsub.rs +++ /dev/null @@ -1,96 +0,0 @@ -use crate::int::{DInt, Int, MinInt}; - -trait UAddSub: DInt + Int { - fn uadd(self, other: Self) -> Self { - let (lo, carry) = self.lo().overflowing_add(other.lo()); - let hi = self.hi().wrapping_add(other.hi()); - let carry = if carry { Self::H::ONE } else { Self::H::ZERO }; - Self::from_lo_hi(lo, hi.wrapping_add(carry)) - } - fn uadd_one(self) -> Self { - let (lo, carry) = self.lo().overflowing_add(Self::H::ONE); - let carry = if carry { Self::H::ONE } else { Self::H::ZERO }; - Self::from_lo_hi(lo, self.hi().wrapping_add(carry)) - } - fn usub(self, other: Self) -> Self { - let uneg = (!other).uadd_one(); - self.uadd(uneg) - } -} - -impl UAddSub for u128 {} - -trait AddSub: Int -where - ::UnsignedInt: UAddSub, -{ - fn add(self, other: Self) -> Self { - Self::from_unsigned(self.unsigned().uadd(other.unsigned())) - } - fn sub(self, other: Self) -> Self { - Self::from_unsigned(self.unsigned().usub(other.unsigned())) - } -} - -impl AddSub for u128 {} -impl AddSub for i128 {} - -trait Addo: AddSub -where - ::UnsignedInt: UAddSub, -{ - fn addo(self, other: Self) -> (Self, bool) { - let sum = AddSub::add(self, other); - (sum, (other < Self::ZERO) != (sum < self)) - } -} - -impl Addo for i128 {} -impl Addo for u128 {} - -trait Subo: AddSub -where - ::UnsignedInt: UAddSub, -{ - fn subo(self, other: Self) -> (Self, bool) { - let sum = AddSub::sub(self, other); - (sum, (other < Self::ZERO) != (self < sum)) - } -} - -impl Subo for i128 {} -impl Subo for u128 {} - -intrinsics! { - pub extern "C" fn __rust_i128_add(a: i128, b: i128) -> i128 { - AddSub::add(a,b) - } - - pub extern "C" fn __rust_i128_addo(a: i128, b: i128) -> (i128, bool) { - a.addo(b) - } - - pub extern "C" fn __rust_u128_add(a: u128, b: u128) -> u128 { - AddSub::add(a,b) - } - - pub extern "C" fn __rust_u128_addo(a: u128, b: u128) -> (u128, bool) { - a.addo(b) - } - - pub extern "C" fn __rust_i128_sub(a: i128, b: i128) -> i128 { - AddSub::sub(a,b) - } - - pub extern "C" fn __rust_i128_subo(a: i128, b: i128) -> (i128, bool) { - a.subo(b) - } - - pub extern "C" fn __rust_u128_sub(a: u128, b: u128) -> u128 { - AddSub::sub(a,b) - } - - pub extern "C" fn __rust_u128_subo(a: u128, b: u128) -> (u128, bool) { - a.subo(b) - } -} diff --git a/src/int/mod.rs b/src/int/mod.rs index c0d5a6715..a5261134a 100644 --- a/src/int/mod.rs +++ b/src/int/mod.rs @@ -2,7 +2,6 @@ use core::ops; mod specialized_div_rem; -pub mod addsub; mod big; pub mod bswap; pub mod leading_zeros; diff --git a/testcrate/tests/addsub.rs b/testcrate/tests/addsub.rs index 284a2bf5a..0ee17f807 100644 --- a/testcrate/tests/addsub.rs +++ b/testcrate/tests/addsub.rs @@ -1,83 +1,9 @@ #![allow(unused_macros)] #![cfg_attr(f128_enabled, feature(f128))] +#[allow(unused_imports)] // Unused on some archs use testcrate::*; -mod int_addsub { - use super::*; - - macro_rules! sum { - ($($i:ty, $fn_add:ident, $fn_sub:ident);*;) => { - $( - #[test] - fn $fn_add() { - use compiler_builtins::int::addsub::{$fn_add, $fn_sub}; - - fuzz_2(N, |x: $i, y: $i| { - let add0 = x.wrapping_add(y); - let sub0 = x.wrapping_sub(y); - let add1: $i = $fn_add(x, y); - let sub1: $i = $fn_sub(x, y); - if add0 != add1 { - panic!( - "{}({}, {}): std: {}, builtins: {}", - stringify!($fn_add), x, y, add0, add1 - ); - } - if sub0 != sub1 { - panic!( - "{}({}, {}): std: {}, builtins: {}", - stringify!($fn_sub), x, y, sub0, sub1 - ); - } - }); - } - )* - }; - } - - macro_rules! overflowing_sum { - ($($i:ty, $fn_add:ident, $fn_sub:ident);*;) => { - $( - #[test] - fn $fn_add() { - use compiler_builtins::int::addsub::{$fn_add, $fn_sub}; - - fuzz_2(N, |x: $i, y: $i| { - let add0 = x.overflowing_add(y); - let sub0 = x.overflowing_sub(y); - let add1: ($i, bool) = $fn_add(x, y); - let sub1: ($i, bool) = $fn_sub(x, y); - if add0.0 != add1.0 || add0.1 != add1.1 { - panic!( - "{}({}, {}): std: {:?}, builtins: {:?}", - stringify!($fn_add), x, y, add0, add1 - ); - } - if sub0.0 != sub1.0 || sub0.1 != sub1.1 { - panic!( - "{}({}, {}): std: {:?}, builtins: {:?}", - stringify!($fn_sub), x, y, sub0, sub1 - ); - } - }); - } - )* - }; - } - - // Integer addition and subtraction is very simple, so 100 fuzzing passes should be plenty. - sum! { - u128, __rust_u128_add, __rust_u128_sub; - i128, __rust_i128_add, __rust_i128_sub; - } - - overflowing_sum! { - u128, __rust_u128_addo, __rust_u128_subo; - i128, __rust_i128_addo, __rust_i128_subo; - } -} - macro_rules! float_sum { ($($f:ty, $fn_add:ident, $fn_sub:ident, $apfloat_ty:ident, $sys_available:meta);*;) => { $(