Skip to content

Commit 10de762

Browse files
committed
auto merge of #11717 : DiamondLovesYou/rust/master, r=alexcrichton
Note that it still doesn't allow generic types to be marked with #[simd].
2 parents e99fe7e + 7becc0f commit 10de762

File tree

3 files changed

+67
-7
lines changed

3 files changed

+67
-7
lines changed

src/librustc/middle/trans/adt.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
use std::container::Map;
4747
use std::libc::c_ulonglong;
4848
use std::option::{Option, Some, None};
49+
use std::num::{Bitwise};
4950

5051
use lib::llvm::{ValueRef, True, IntEQ, IntNE};
5152
use middle::trans::_match;
@@ -424,19 +425,22 @@ fn generic_type_of(cx: &CrateContext, r: &Repr, name: Option<&str>, sizing: bool
424425
let align = most_aligned.align;
425426
let discr_ty = ll_inttype(cx, ity);
426427
let discr_size = machine::llsize_of_alloc(cx, discr_ty) as u64;
428+
let align_units = (size + align - 1) / align - 1;
427429
let pad_ty = match align {
428-
1 => Type::i8(),
429-
2 => Type::i16(),
430-
4 => Type::i32(),
431-
8 if machine::llalign_of_min(cx, Type::i64()) == 8 => Type::i64(),
430+
1 => Type::array(&Type::i8(), align_units),
431+
2 => Type::array(&Type::i16(), align_units),
432+
4 => Type::array(&Type::i32(), align_units),
433+
8 if machine::llalign_of_min(cx, Type::i64()) == 8 =>
434+
Type::array(&Type::i64(), align_units),
435+
a if a.population_count() == 1 => Type::array(&Type::vector(&Type::i32(), a / 4),
436+
align_units),
432437
_ => fail!("Unsupported enum alignment: {:?}", align)
433438
};
434439
assert_eq!(machine::llalign_of_min(cx, pad_ty) as u64, align);
435-
let align_units = (size + align - 1) / align;
436440
assert_eq!(align % discr_size, 0);
437441
let fields = ~[discr_ty,
438-
Type::array(&discr_ty, align / discr_size - 1),
439-
Type::array(&pad_ty, align_units - 1)];
442+
Type::array(&discr_ty, align / discr_size - 1),
443+
pad_ty];
440444
match name {
441445
None => Type::struct_(fields, false),
442446
Some(name) => {

src/test/run-pass/simd-generics.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-fast
12+
13+
#[feature(simd)];
14+
15+
use std::ops;
16+
17+
#[simd] struct f32x4(f32, f32, f32, f32);
18+
19+
fn add<T: ops::Add<T, T>>(lhs: T, rhs: T) -> T {
20+
lhs + rhs
21+
}
22+
23+
impl ops::Add<f32x4, f32x4> for f32x4 {
24+
fn add(&self, rhs: &f32x4) -> f32x4 {
25+
*self + *rhs
26+
}
27+
}
28+
29+
pub fn main() {
30+
let lr = f32x4(1.0f32, 2.0f32, 3.0f32, 4.0f32);
31+
32+
// lame-o
33+
let f32x4(x, y, z, w) = add(lr, lr);
34+
assert_eq!(x, 2.0f32);
35+
assert_eq!(y, 4.0f32);
36+
assert_eq!(z, 6.0f32);
37+
assert_eq!(w, 8.0f32);
38+
}

src/test/run-pass/simd-issue-10604.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-fast
12+
13+
#[allow(experimental)];
14+
#[feature(simd)];
15+
16+
pub fn main() {
17+
let _o = None::<std::unstable::simd::i32x4>;
18+
}

0 commit comments

Comments
 (0)