Skip to content

Commit

Permalink
auto merge of #11717 : DiamondLovesYou/rust/master, r=alexcrichton
Browse files Browse the repository at this point in the history
Note that it still doesn't allow generic types to be marked with #[simd].
  • Loading branch information
bors committed Feb 4, 2014
2 parents e99fe7e + 7becc0f commit 10de762
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/librustc/middle/trans/adt.rs
Expand Up @@ -46,6 +46,7 @@
use std::container::Map;
use std::libc::c_ulonglong;
use std::option::{Option, Some, None};
use std::num::{Bitwise};

use lib::llvm::{ValueRef, True, IntEQ, IntNE};
use middle::trans::_match;
Expand Down Expand Up @@ -424,19 +425,22 @@ fn generic_type_of(cx: &CrateContext, r: &Repr, name: Option<&str>, sizing: bool
let align = most_aligned.align;
let discr_ty = ll_inttype(cx, ity);
let discr_size = machine::llsize_of_alloc(cx, discr_ty) as u64;
let align_units = (size + align - 1) / align - 1;
let pad_ty = match align {
1 => Type::i8(),
2 => Type::i16(),
4 => Type::i32(),
8 if machine::llalign_of_min(cx, Type::i64()) == 8 => Type::i64(),
1 => Type::array(&Type::i8(), align_units),
2 => Type::array(&Type::i16(), align_units),
4 => Type::array(&Type::i32(), align_units),
8 if machine::llalign_of_min(cx, Type::i64()) == 8 =>
Type::array(&Type::i64(), align_units),
a if a.population_count() == 1 => Type::array(&Type::vector(&Type::i32(), a / 4),
align_units),
_ => fail!("Unsupported enum alignment: {:?}", align)
};
assert_eq!(machine::llalign_of_min(cx, pad_ty) as u64, align);
let align_units = (size + align - 1) / align;
assert_eq!(align % discr_size, 0);
let fields = ~[discr_ty,
Type::array(&discr_ty, align / discr_size - 1),
Type::array(&pad_ty, align_units - 1)];
Type::array(&discr_ty, align / discr_size - 1),
pad_ty];
match name {
None => Type::struct_(fields, false),
Some(name) => {
Expand Down
38 changes: 38 additions & 0 deletions src/test/run-pass/simd-generics.rs
@@ -0,0 +1,38 @@
// Copyright 2013 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.

// xfail-fast

#[feature(simd)];

use std::ops;

#[simd] struct f32x4(f32, f32, f32, f32);

fn add<T: ops::Add<T, T>>(lhs: T, rhs: T) -> T {
lhs + rhs
}

impl ops::Add<f32x4, f32x4> for f32x4 {
fn add(&self, rhs: &f32x4) -> f32x4 {
*self + *rhs
}
}

pub fn main() {
let lr = f32x4(1.0f32, 2.0f32, 3.0f32, 4.0f32);

// lame-o
let f32x4(x, y, z, w) = add(lr, lr);
assert_eq!(x, 2.0f32);
assert_eq!(y, 4.0f32);
assert_eq!(z, 6.0f32);
assert_eq!(w, 8.0f32);
}
18 changes: 18 additions & 0 deletions src/test/run-pass/simd-issue-10604.rs
@@ -0,0 +1,18 @@
// Copyright 2013 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.

// xfail-fast

#[allow(experimental)];
#[feature(simd)];

pub fn main() {
let _o = None::<std::unstable::simd::i32x4>;
}

0 comments on commit 10de762

Please sign in to comment.