Skip to content

Avoid memcpy references in unoptimized code #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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