File tree 8 files changed +82
-78
lines changed
8 files changed +82
-78
lines changed Original file line number Diff line number Diff line change @@ -60,12 +60,12 @@ pub unsafe fn __aeabi_ldivmod() {
60
60
// TODO: These two functions should be defined as aliases
61
61
#[ cfg_attr( not( test) , no_mangle) ]
62
62
pub extern "C" fn __aeabi_uidiv ( a : u32 , b : u32 ) -> u32 {
63
- :: udiv:: __udivsi3 ( a, b)
63
+ :: int :: udiv:: __udivsi3 ( a, b)
64
64
}
65
65
66
66
#[ cfg_attr( not( test) , no_mangle) ]
67
67
pub extern "C" fn __aeabi_idiv ( a : i32 , b : i32 ) -> i32 {
68
- :: sdiv:: __divsi3 ( a, b)
68
+ :: int :: sdiv:: __divsi3 ( a, b)
69
69
}
70
70
71
71
extern "C" {
Original file line number Diff line number Diff line change
1
+
2
+ pub mod mul;
3
+ pub mod sdiv;
4
+ pub mod shift;
5
+ pub mod udiv;
6
+
7
+ /// Trait for some basic operations on integers
8
+ pub trait Int {
9
+ /// Returns the bitwidth of the int type
10
+ fn bits ( ) -> u32 ;
11
+ }
12
+
13
+ // TODO: Once i128/u128 support lands, we'll want to add impls for those as well
14
+ impl Int for u32 {
15
+ fn bits ( ) -> u32 {
16
+ 32
17
+ }
18
+ }
19
+ impl Int for i32 {
20
+ fn bits ( ) -> u32 {
21
+ 32
22
+ }
23
+ }
24
+ impl Int for u64 {
25
+ fn bits ( ) -> u32 {
26
+ 64
27
+ }
28
+ }
29
+ impl Int for i64 {
30
+ fn bits ( ) -> u32 {
31
+ 64
32
+ }
33
+ }
34
+
35
+ /// Trait to convert an integer to/from smaller parts
36
+ pub trait LargeInt {
37
+ type LowHalf ;
38
+ type HighHalf ;
39
+
40
+ fn low ( self ) -> Self :: LowHalf ;
41
+ fn high ( self ) -> Self :: HighHalf ;
42
+ fn from_parts ( low : Self :: LowHalf , high : Self :: HighHalf ) -> Self ;
43
+ }
44
+
45
+ // TODO: Once i128/u128 support lands, we'll want to add impls for those as well
46
+ impl LargeInt for u64 {
47
+ type LowHalf = u32 ;
48
+ type HighHalf = u32 ;
49
+
50
+ fn low ( self ) -> u32 {
51
+ self as u32
52
+ }
53
+ fn high ( self ) -> u32 {
54
+ ( self >> 32 ) as u32
55
+ }
56
+ fn from_parts ( low : u32 , high : u32 ) -> u64 {
57
+ low as u64 | ( ( high as u64 ) << 32 )
58
+ }
59
+ }
60
+ impl LargeInt for i64 {
61
+ type LowHalf = u32 ;
62
+ type HighHalf = i32 ;
63
+
64
+ fn low ( self ) -> u32 {
65
+ self as u32
66
+ }
67
+ fn high ( self ) -> i32 {
68
+ ( self >> 32 ) as i32
69
+ }
70
+ fn from_parts ( low : u32 , high : i32 ) -> i64 {
71
+ low as i64 | ( ( high as i64 ) << 32 )
72
+ }
73
+ }
Original file line number Diff line number Diff line change 1
- use { Int , LargeInt } ;
1
+ use int :: { Int , LargeInt } ;
2
2
3
3
macro_rules! mul {
4
4
( $intrinsic: ident: $ty: ty) => {
Original file line number Diff line number Diff line change 1
- use Int ;
1
+ use int :: Int ;
2
2
3
3
macro_rules! div {
4
4
( $intrinsic: ident: $ty: ty, $uty: ty) => {
Original file line number Diff line number Diff line change 1
- use { Int , LargeInt } ;
1
+ use int :: { Int , LargeInt } ;
2
2
3
3
macro_rules! ashl {
4
4
( $intrinsic: ident: $ty: ty) => {
Original file line number Diff line number Diff line change 1
1
use core:: mem;
2
- use { Int , LargeInt } ;
2
+ use int :: { Int , LargeInt } ;
3
3
4
4
/// Returns `n / d`
5
5
#[ cfg_attr( not( test) , no_mangle) ]
Original file line number Diff line number Diff line change @@ -20,83 +20,14 @@ extern crate core;
20
20
#[ cfg( all( not( windows) , not( target_os = "macos" ) ) ) ]
21
21
extern crate rlibc;
22
22
23
+ pub mod int;
24
+
23
25
#[ cfg( target_arch = "arm" ) ]
24
26
pub mod arm;
25
27
26
28
#[ cfg( target_arch = "x86_64" ) ]
27
29
pub mod x86_64;
28
30
29
- pub mod udiv;
30
- pub mod sdiv;
31
- pub mod mul;
32
- pub mod shift;
33
-
34
31
#[ cfg( test) ]
35
32
mod qc;
36
33
37
- /// Trait for some basic operations on integers
38
- trait Int {
39
- fn bits ( ) -> u32 ;
40
- }
41
-
42
- // TODO: Once i128/u128 support lands, we'll want to add impls for those as well
43
- impl Int for u32 {
44
- fn bits ( ) -> u32 {
45
- 32
46
- }
47
- }
48
- impl Int for i32 {
49
- fn bits ( ) -> u32 {
50
- 32
51
- }
52
- }
53
- impl Int for u64 {
54
- fn bits ( ) -> u32 {
55
- 64
56
- }
57
- }
58
- impl Int for i64 {
59
- fn bits ( ) -> u32 {
60
- 64
61
- }
62
- }
63
-
64
- /// Trait to convert an integer to/from smaller parts
65
- trait LargeInt {
66
- type LowHalf ;
67
- type HighHalf ;
68
-
69
- fn low ( self ) -> Self :: LowHalf ;
70
- fn high ( self ) -> Self :: HighHalf ;
71
- fn from_parts ( low : Self :: LowHalf , high : Self :: HighHalf ) -> Self ;
72
- }
73
-
74
- // TODO: Once i128/u128 support lands, we'll want to add impls for those as well
75
- impl LargeInt for u64 {
76
- type LowHalf = u32 ;
77
- type HighHalf = u32 ;
78
-
79
- fn low ( self ) -> u32 {
80
- self as u32
81
- }
82
- fn high ( self ) -> u32 {
83
- ( self >> 32 ) as u32
84
- }
85
- fn from_parts ( low : u32 , high : u32 ) -> u64 {
86
- low as u64 | ( ( high as u64 ) << 32 )
87
- }
88
- }
89
- impl LargeInt for i64 {
90
- type LowHalf = u32 ;
91
- type HighHalf = i32 ;
92
-
93
- fn low ( self ) -> u32 {
94
- self as u32
95
- }
96
- fn high ( self ) -> i32 {
97
- ( self >> 32 ) as i32
98
- }
99
- fn from_parts ( low : u32 , high : i32 ) -> i64 {
100
- low as i64 | ( ( high as i64 ) << 32 )
101
- }
102
- }
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ use std::fmt;
8
8
9
9
use quickcheck:: { Arbitrary , Gen } ;
10
10
11
- use LargeInt ;
11
+ use int :: LargeInt ;
12
12
13
13
// Generates values in the full range of the integer type
14
14
macro_rules! arbitrary {
You can’t perform that action at this time.
0 commit comments