Commit b0300b1
committed
Auto merge of #164 - rust-lang-nursery:memclr, r=alexcrichton
optimize memset and memclr for ARM
This commit optimizes those routines by rewriting them in assembly and
performing the memory copying in 32-bit chunks, rather than in 8-bit chunks
as it was done before this commit. This assembly implementation is
compatible with the ARMv6 and ARMv7 architectures.
This change results in a reduction of runtime of about 40-70% in all cases
that matter (the compiler will never use these intrinsics for sizes smaller
than 4 bytes). See data below:
| Bytes | HEAD | this PR | diff |
| ----- | ---- | ------- | ---------- |
| 0 | 6 | 14 | +133.3333% |
| 1 | 10 | 13 | +30% |
| 2 | 14 | 13 | -7.1429% |
| 3 | 18 | 13 | -27.77% |
| 4 | 24 | 21 | -12.5% |
| 16 | 70 | 36 | -48.5714% |
| 64 | 263 | 97 | -63.1179% |
| 256 | 1031 | 337 | -67.3133% |
| 1024 | 4103 | 1297 | -68.389% |
All times are in clock cycles. The measurements were done on a Cortex-M3
processor running at 8 MHz using the technique described [here].
[here]: http://blog.japaric.io/rtfm-overhead
---
For relevance all pure Rust programs for Cortex-M microcontrollers use memclr to
zero the .bss during startup so this change results in a quicker boot time.
Some questions / comments:
- ~~the original code (it had a bug) comes from this [repo] and it's licensed
under the ICS license. I have preserved the copyright and license text in the
source code. IANAL, is that OK?~~ no longer applies. The intrinsics are written in Rust now.
- ~~I don't know whether this ARM implementation works for ARMv4 or ARMv5.
@FenrirWolf and @Uvekilledkenny may want to take look at it first.~~ no longer applies. The intrinsics are written in Rust now.
- ~~No idea whether this implementation works on processors that have no thumb
instruction set. The current implementation uses 16-bit thumb instructions.~~ no longer applies. The intrinsics are written in Rust now.
- ~~The loop code can be rewritten in less instructions but using 32-bit thumb
instructions. That 32-bit version would only work on ARMv7 though. I have yet
to check whether that makes any difference in the runtime of the intrinsic.~~ no longer applies. The intrinsics are written in Rust now.
- ~~I'll look into memcpy4 next.~~ done
[repo]: https://github.com/bobbl/libaeabi-cortexm0File tree
6 files changed
+476
-31
lines changed- src
- tests
6 files changed
+476
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | 62 | | |
72 | 63 | | |
| 64 | + | |
73 | 65 | | |
| 66 | + | |
74 | 67 | | |
75 | | - | |
| 68 | + | |
76 | 69 | | |
| 70 | + | |
| 71 | + | |
77 | 72 | | |
78 | | - | |
79 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
80 | 86 | | |
| 87 | + | |
| 88 | + | |
81 | 89 | | |
| 90 | + | |
82 | 91 | | |
83 | | - | |
| 92 | + | |
84 | 93 | | |
85 | 94 | | |
| 95 | + | |
86 | 96 | | |
| 97 | + | |
87 | 98 | | |
88 | | - | |
| 99 | + | |
89 | 100 | | |
| 101 | + | |
| 102 | + | |
90 | 103 | | |
| 104 | + | |
91 | 105 | | |
92 | | - | |
| 106 | + | |
93 | 107 | | |
| 108 | + | |
| 109 | + | |
94 | 110 | | |
| 111 | + | |
95 | 112 | | |
96 | | - | |
| 113 | + | |
97 | 114 | | |
98 | 115 | | |
99 | | - | |
| 116 | + | |
100 | 117 | | |
| 118 | + | |
101 | 119 | | |
102 | | - | |
| 120 | + | |
| 121 | + | |
103 | 122 | | |
| 123 | + | |
| 124 | + | |
104 | 125 | | |
105 | | - | |
106 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
107 | 140 | | |
| 141 | + | |
| 142 | + | |
108 | 143 | | |
| 144 | + | |
109 | 145 | | |
110 | | - | |
| 146 | + | |
111 | 147 | | |
112 | 148 | | |
| 149 | + | |
113 | 150 | | |
| 151 | + | |
114 | 152 | | |
115 | | - | |
| 153 | + | |
116 | 154 | | |
| 155 | + | |
| 156 | + | |
117 | 157 | | |
| 158 | + | |
118 | 159 | | |
119 | | - | |
| 160 | + | |
120 | 161 | | |
| 162 | + | |
| 163 | + | |
121 | 164 | | |
| 165 | + | |
122 | 166 | | |
123 | | - | |
| 167 | + | |
124 | 168 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
0 commit comments