Skip to content

Commit c138713

Browse files
committed
Avoid memcpy references in unoptimized code
1 parent f6c4034 commit c138713

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/float/add.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use core::mem;
21
use core::num::Wrapping;
32

43
use float::Float;
@@ -75,7 +74,10 @@ macro_rules! add {
7574

7675
// Swap a and b if necessary so that a has the larger absolute value.
7776
if b_abs > a_abs {
78-
mem::swap(&mut a_rep, &mut b_rep);
77+
// Don't use mem::swap because it may generate references to memcpy in unoptimized code.
78+
let tmp = a_rep;
79+
a_rep = b_rep;
80+
b_rep = tmp;
7981
}
8082

8183
// Extract the exponent and significand from the (possibly swapped) a and b.

src/int/udiv.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ macro_rules! udivmod_inner {
125125
// 1 <= sr <= u64::bits() - 1
126126
let mut carry = 0;
127127

128-
for _ in 0..sr {
128+
// Don't use a range because they may generate references to memcpy in unoptimized code
129+
let mut i = 0;
130+
while i < sr {
131+
i += 1;
132+
129133
// r:q = ((r:q) << 1) | carry
130134
r = (r << 1) | (q >> (<$ty>::bits() - 1));
131135
q = (q << 1) | carry as $ty;
@@ -181,7 +185,12 @@ intrinsics! {
181185
let mut r = n >> sr;
182186

183187
let mut carry = 0;
184-
for _ in 0..sr {
188+
189+
// Don't use a range because they may generate references to memcpy in unoptimized code
190+
let mut i = 0;
191+
while i < sr {
192+
i += 1;
193+
185194
// r:q = ((r:q) << 1) | carry
186195
r = (r << 1) | (q >> (u32::bits() - 1));
187196
q = (q << 1) | carry;

0 commit comments

Comments
 (0)