Skip to content

Commit

Permalink
Auto merge of #181 - TimNN:no-memcpy, r=alexcrichton
Browse files Browse the repository at this point in the history
Avoid memcpy references in unoptimized code

Fixes rust-lang/rust#43411.
  • Loading branch information
bors committed Jul 23, 2017
2 parents f6c4034 + c138713 commit 6b9281d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/float/add.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use core::mem;
use core::num::Wrapping;

use float::Float;
Expand Down Expand Up @@ -75,7 +74,10 @@ macro_rules! add {

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

// Extract the exponent and significand from the (possibly swapped) a and b.
Expand Down
13 changes: 11 additions & 2 deletions src/int/udiv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ macro_rules! udivmod_inner {
// 1 <= sr <= u64::bits() - 1
let mut carry = 0;

for _ in 0..sr {
// Don't use a range because they may generate references to memcpy in unoptimized code
let mut i = 0;
while i < sr {
i += 1;

// r:q = ((r:q) << 1) | carry
r = (r << 1) | (q >> (<$ty>::bits() - 1));
q = (q << 1) | carry as $ty;
Expand Down Expand Up @@ -181,7 +185,12 @@ intrinsics! {
let mut r = n >> sr;

let mut carry = 0;
for _ in 0..sr {

// Don't use a range because they may generate references to memcpy in unoptimized code
let mut i = 0;
while i < sr {
i += 1;

// r:q = ((r:q) << 1) | carry
r = (r << 1) | (q >> (u32::bits() - 1));
q = (q << 1) | carry;
Expand Down

0 comments on commit 6b9281d

Please sign in to comment.