File tree 4 files changed +68
-11
lines changed
4 files changed +68
-11
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,6 @@ version = "0.1.0"
8
8
rustc-cfg = " 0.2.0"
9
9
gcc = " 0.3.36"
10
10
11
- [dependencies ]
12
-
13
- [dependencies .rlibc ]
14
- git = " https://github.com/alexcrichton/rlibc"
15
- optional = true
16
-
17
11
[dev-dependencies ]
18
12
quickcheck = " 0.3.1"
19
13
rand = " 0.3.14"
26
20
# Mark this crate as the #![compiler_builtins] crate
27
21
compiler-builtins = []
28
22
default = [" compiler-builtins" ]
23
+ # Include implementations of memory operations like memcpy
24
+ mem = []
29
25
rustbuild = [" compiler-builtins" ]
30
- weak = [" rlibc/weak" ]
31
26
32
27
[workspace ]
Original file line number Diff line number Diff line change 1
1
use core:: intrinsics;
2
2
3
+ #[ cfg( feature = "mem" ) ]
4
+ use mem:: { memcpy, memmove, memset} ;
5
+
3
6
// NOTE This function and the ones below are implemented using assembly because they using a custom
4
7
// calling convention which can't be implemented using a normal Rust function
5
8
#[ naked]
@@ -100,6 +103,7 @@ pub extern "C" fn __aeabi_uidiv(a: u32, b: u32) -> u32 {
100
103
:: int:: udiv:: __udivsi3 ( a, b)
101
104
}
102
105
106
+ #[ cfg( not( feature = "mem" ) ) ]
103
107
extern "C" {
104
108
fn memcpy ( dest : * mut u8 , src : * const u8 , n : usize ) -> * mut u8 ;
105
109
fn memmove ( dest : * mut u8 , src : * const u8 , n : usize ) -> * mut u8 ;
Original file line number Diff line number Diff line change 11
11
#![ feature( asm) ]
12
12
#![ feature( compiler_builtins) ]
13
13
#![ feature( core_intrinsics) ]
14
- #![ feature( linkage) ]
15
14
#![ feature( naked_functions) ]
16
15
#![ feature( staged_api) ]
17
16
#![ no_builtins]
@@ -102,16 +101,16 @@ extern crate compiler_rt;
102
101
#[ cfg( test) ]
103
102
extern crate rand;
104
103
105
- #[ cfg( feature = "weak" ) ]
106
- extern crate rlibc;
107
-
108
104
#[ cfg( test) ]
109
105
#[ macro_use]
110
106
mod qc;
111
107
112
108
pub mod int;
113
109
pub mod float;
114
110
111
+ #[ cfg( feature = "mem" ) ]
112
+ pub mod mem;
113
+
115
114
#[ cfg( target_arch = "arm" ) ]
116
115
pub mod arm;
117
116
Original file line number Diff line number Diff line change
1
+ #[ no_mangle]
2
+ pub unsafe extern "C" fn memcpy ( dest : * mut u8 ,
3
+ src : * const u8 ,
4
+ n : usize )
5
+ -> * mut u8 {
6
+ let mut i = 0 ;
7
+ while i < n {
8
+ * dest. offset ( i as isize ) = * src. offset ( i as isize ) ;
9
+ i += 1 ;
10
+ }
11
+ dest
12
+ }
13
+
14
+ #[ no_mangle]
15
+ pub unsafe extern "C" fn memmove ( dest : * mut u8 ,
16
+ src : * const u8 ,
17
+ n : usize )
18
+ -> * mut u8 {
19
+ if src < dest as * const u8 {
20
+ // copy from end
21
+ let mut i = n;
22
+ while i != 0 {
23
+ i -= 1 ;
24
+ * dest. offset ( i as isize ) = * src. offset ( i as isize ) ;
25
+ }
26
+ } else {
27
+ // copy from beginning
28
+ let mut i = 0 ;
29
+ while i < n {
30
+ * dest. offset ( i as isize ) = * src. offset ( i as isize ) ;
31
+ i += 1 ;
32
+ }
33
+ }
34
+ dest
35
+ }
36
+
37
+ #[ no_mangle]
38
+ pub unsafe extern "C" fn memset ( s : * mut u8 , c : i32 , n : usize ) -> * mut u8 {
39
+ let mut i = 0 ;
40
+ while i < n {
41
+ * s. offset ( i as isize ) = c as u8 ;
42
+ i += 1 ;
43
+ }
44
+ s
45
+ }
46
+
47
+ #[ no_mangle]
48
+ pub unsafe extern "C" fn memcmp ( s1 : * const u8 , s2 : * const u8 , n : usize ) -> i32 {
49
+ let mut i = 0 ;
50
+ while i < n {
51
+ let a = * s1. offset ( i as isize ) ;
52
+ let b = * s2. offset ( i as isize ) ;
53
+ if a != b {
54
+ return a as i32 - b as i32 ;
55
+ }
56
+ i += 1 ;
57
+ }
58
+ 0
59
+ }
You can’t perform that action at this time.
0 commit comments