Skip to content

Commit 665f268

Browse files
committed
Tweak addo & subo to try and fix MIPS
1 parent 5e71218 commit 665f268

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/int/add.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
use int::LargeInt;
22
use int::Int;
33

4-
trait Add: LargeInt {
5-
fn add(self, other: Self) -> Self {
4+
trait UAdd: LargeInt {
5+
fn uadd(self, other: Self) -> Self {
66
let (low, carry) = self.low().overflowing_add(other.low());
77
let high = self.high().wrapping_add(other.high());
88
let carry = if carry { Self::HighHalf::ONE } else { Self::HighHalf::ZERO };
99
Self::from_parts(low, high.wrapping_add(carry))
1010
}
1111
}
1212

13+
impl UAdd for u128 {}
14+
15+
trait Add: Int
16+
where <Self as Int>::UnsignedInt: UAdd
17+
{
18+
fn add(self, other: Self) -> Self {
19+
Self::from_unsigned(self.unsigned().uadd(other.unsigned()))
20+
}
21+
}
22+
1323
impl Add for u128 {}
24+
impl Add for i128 {}
1425

15-
trait Addo: Int {
26+
trait Addo: Add
27+
where <Self as Int>::UnsignedInt: UAdd
28+
{
1629
fn addo(self, other: Self, overflow: &mut i32) -> Self {
1730
*overflow = 0;
18-
let result = self.wrapping_add(other);
31+
let result = Add::add(self, other);
1932
if other >= Self::ZERO {
2033
if result < self {
2134
*overflow = 1;

src/int/sub.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use int::LargeInt;
2-
use int::Int;
32

43
trait Sub: LargeInt {
54
fn sub(self, other: Self) -> Self {
@@ -8,12 +7,13 @@ trait Sub: LargeInt {
87
}
98
}
109

10+
impl Sub for i128 {}
1111
impl Sub for u128 {}
1212

13-
trait Subo: Int {
13+
trait Subo: Sub {
1414
fn subo(self, other: Self, overflow: &mut i32) -> Self {
1515
*overflow = 0;
16-
let result = self.wrapping_sub(other);
16+
let result = Sub::sub(self, other);
1717
if other >= Self::ZERO {
1818
if result > self {
1919
*overflow = 1;

0 commit comments

Comments
 (0)