Skip to content

Commit 43b32cb

Browse files
committed
---
yaml --- r: 193375 b: refs/heads/beta c: 6d6038a h: refs/heads/master i: 193373: 2b4b8b4 193371: e70fe7e 193367: 13066a8 193359: 4e957f5 193343: b9dcc14 v: v3
1 parent 61b977d commit 43b32cb

File tree

3 files changed

+149
-1
lines changed

3 files changed

+149
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: 280dea743b5227d0d162217cbb89db881242c94e
34+
refs/heads/beta: 6d6038a1944394fc5e64048aea6fdbad4f59ee15
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3737
refs/heads/tmp: de8a23bbc3a7b9cbd7574b5b91a34af59bf030e6

branches/beta/src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#![feature(unboxed_closures)]
7070
#![feature(rustc_attrs)]
7171
#![feature(optin_builtin_traits)]
72+
#![feature(concat_idents)]
7273

7374
#[macro_use]
7475
mod macros;

branches/beta/src/libcore/num/wrapping.rs

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,32 @@ use ops::*;
1414
#[cfg(not(stage0))]
1515
use intrinsics::{overflowing_add, overflowing_sub, overflowing_mul};
1616

17+
use intrinsics::{i8_add_with_overflow, u8_add_with_overflow};
18+
use intrinsics::{i16_add_with_overflow, u16_add_with_overflow};
19+
use intrinsics::{i32_add_with_overflow, u32_add_with_overflow};
20+
use intrinsics::{i64_add_with_overflow, u64_add_with_overflow};
21+
use intrinsics::{i8_sub_with_overflow, u8_sub_with_overflow};
22+
use intrinsics::{i16_sub_with_overflow, u16_sub_with_overflow};
23+
use intrinsics::{i32_sub_with_overflow, u32_sub_with_overflow};
24+
use intrinsics::{i64_sub_with_overflow, u64_sub_with_overflow};
25+
use intrinsics::{i8_mul_with_overflow, u8_mul_with_overflow};
26+
use intrinsics::{i16_mul_with_overflow, u16_mul_with_overflow};
27+
use intrinsics::{i32_mul_with_overflow, u32_mul_with_overflow};
28+
use intrinsics::{i64_mul_with_overflow, u64_mul_with_overflow};
29+
1730
pub trait WrappingOps {
1831
fn wrapping_add(self, rhs: Self) -> Self;
1932
fn wrapping_sub(self, rhs: Self) -> Self;
2033
fn wrapping_mul(self, rhs: Self) -> Self;
2134
}
2235

36+
#[unstable(feature = "core", reason = "may be removed, renamed, or relocated")]
37+
pub trait OverflowingOps {
38+
fn overflowing_add(self, rhs: Self) -> (Self, bool);
39+
fn overflowing_sub(self, rhs: Self) -> (Self, bool);
40+
fn overflowing_mul(self, rhs: Self) -> (Self, bool);
41+
}
42+
2343
#[cfg(not(stage0))]
2444
macro_rules! wrapping_impl {
2545
($($t:ty)*) => ($(
@@ -151,3 +171,130 @@ impl<T:WrappingOps+Shr<uint,Output=T>> Shr<uint> for Wrapping<T> {
151171
Wrapping(self.0 >> other)
152172
}
153173
}
174+
175+
macro_rules! overflowing_impl {
176+
($($t:ident)*) => ($(
177+
impl OverflowingOps for $t {
178+
#[inline(always)]
179+
fn overflowing_add(self, rhs: $t) -> ($t, bool) {
180+
unsafe {
181+
concat_idents!($t, _add_with_overflow)(self, rhs)
182+
}
183+
}
184+
#[inline(always)]
185+
fn overflowing_sub(self, rhs: $t) -> ($t, bool) {
186+
unsafe {
187+
concat_idents!($t, _sub_with_overflow)(self, rhs)
188+
}
189+
}
190+
#[inline(always)]
191+
fn overflowing_mul(self, rhs: $t) -> ($t, bool) {
192+
unsafe {
193+
concat_idents!($t, _mul_with_overflow)(self, rhs)
194+
}
195+
}
196+
}
197+
)*)
198+
}
199+
200+
overflowing_impl! { u8 u16 u32 u64 i8 i16 i32 i64 }
201+
202+
#[cfg(target_pointer_width = "64")]
203+
impl OverflowingOps for usize {
204+
#[inline(always)]
205+
fn overflowing_add(self, rhs: usize) -> (usize, bool) {
206+
unsafe {
207+
let res = u64_add_with_overflow(self as u64, rhs as u64);
208+
(res.0 as usize, res.1)
209+
}
210+
}
211+
#[inline(always)]
212+
fn overflowing_sub(self, rhs: usize) -> (usize, bool) {
213+
unsafe {
214+
let res = u64_sub_with_overflow(self as u64, rhs as u64);
215+
(res.0 as usize, res.1)
216+
}
217+
}
218+
#[inline(always)]
219+
fn overflowing_mul(self, rhs: usize) -> (usize, bool) {
220+
unsafe {
221+
let res = u64_mul_with_overflow(self as u64, rhs as u64);
222+
(res.0 as usize, res.1)
223+
}
224+
}
225+
}
226+
227+
#[cfg(target_pointer_width = "32")]
228+
impl OverflowingOps for usize {
229+
#[inline(always)]
230+
fn overflowing_add(self, rhs: usize) -> (usize, bool) {
231+
unsafe {
232+
let res = u32_add_with_overflow(self as u32, rhs as u32);
233+
(res.0 as usize, res.1)
234+
}
235+
}
236+
#[inline(always)]
237+
fn overflowing_sub(self, rhs: usize) -> (usize, bool) {
238+
unsafe {
239+
let res = u32_sub_with_overflow(self as u32, rhs as u32);
240+
(res.0 as usize, res.1)
241+
}
242+
}
243+
#[inline(always)]
244+
fn overflowing_mul(self, rhs: usize) -> (usize, bool) {
245+
unsafe {
246+
let res = u32_mul_with_overflow(self as u32, rhs as u32);
247+
(res.0 as usize, res.1)
248+
}
249+
}
250+
}
251+
252+
#[cfg(target_pointer_width = "64")]
253+
impl OverflowingOps for isize {
254+
#[inline(always)]
255+
fn overflowing_add(self, rhs: isize) -> (isize, bool) {
256+
unsafe {
257+
let res = i64_add_with_overflow(self as i64, rhs as i64);
258+
(res.0 as isize, res.1)
259+
}
260+
}
261+
#[inline(always)]
262+
fn overflowing_sub(self, rhs: isize) -> (isize, bool) {
263+
unsafe {
264+
let res = i64_sub_with_overflow(self as i64, rhs as i64);
265+
(res.0 as isize, res.1)
266+
}
267+
}
268+
#[inline(always)]
269+
fn overflowing_mul(self, rhs: isize) -> (isize, bool) {
270+
unsafe {
271+
let res = i64_mul_with_overflow(self as i64, rhs as i64);
272+
(res.0 as isize, res.1)
273+
}
274+
}
275+
}
276+
277+
#[cfg(target_pointer_width = "32")]
278+
impl OverflowingOps for isize {
279+
#[inline(always)]
280+
fn overflowing_add(self, rhs: isize) -> (isize, bool) {
281+
unsafe {
282+
let res = i32_add_with_overflow(self as i32, rhs as i32);
283+
(res.0 as isize, res.1)
284+
}
285+
}
286+
#[inline(always)]
287+
fn overflowing_sub(self, rhs: isize) -> (isize, bool) {
288+
unsafe {
289+
let res = i32_sub_with_overflow(self as i32, rhs as i32);
290+
(res.0 as isize, res.1)
291+
}
292+
}
293+
#[inline(always)]
294+
fn overflowing_mul(self, rhs: isize) -> (isize, bool) {
295+
unsafe {
296+
let res = i32_mul_with_overflow(self as i32, rhs as i32);
297+
(res.0 as isize, res.1)
298+
}
299+
}
300+
}

0 commit comments

Comments
 (0)