Skip to content

Commit

Permalink
Try zero-init for the unaligned block instead of undef
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm committed Jul 4, 2018
1 parent fb97bb5 commit 7f5867e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {

if i < len {
// Swap any remaining bytes
let mut t: UnalignedBlock = mem::uninitialized();
let mut t = UnalignedBlock(0, 0, 0, 0);

This comment has been minimized.

Copy link
@scottmcm

scottmcm Jul 4, 2018

Author Owner

This comes out worse in my tests, adding zero-init to the unused parts of the block:

	xorps	xmm0, xmm0
	movups	xmmword ptr [rsp + 16], xmm0
	movups	xmmword ptr [rsp + 6], xmm0
let rem = len - i;

let t = &mut t as *mut _ as *mut u8;
Expand Down
26 changes: 26 additions & 0 deletions src/test/codegen/swap-small-types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -O

#![crate_type = "lib"]

use std::mem::swap;

type RGB48 = [u16; 3];

// CHECK-LABEL: @swap_rgb48
#[no_mangle]
pub fn swap_rgb48(x: &mut RGB48, y: &mut RGB48) {
// CHECK-NOT: alloca
// CHECK: load i48
// CHECK: store i48
swap(x, y)
}

0 comments on commit 7f5867e

Please sign in to comment.