Fix existing tests for new #[repr(simd)].

This commit is contained in:
Huon Wilson 2015-08-12 16:09:02 -07:00
parent 8b68f58fef
commit 3e500673cc
21 changed files with 43 additions and 604 deletions

View File

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(simd, core_simd)]
#![allow(dead_code)]
#![feature(repr_simd, core_simd)]
#![allow(dead_code, deprecated)]
use std::simd::f32x4;
#[simd] #[derive(Copy, Clone)] #[repr(C)] struct LocalSimd(u8, u8);
#[repr(simd)] #[derive(Copy, Clone)] #[repr(C)] struct LocalSimd(u8, u8);
extern {
fn foo() -> f32x4; //~ ERROR use of SIMD type

View File

@ -1,14 +0,0 @@
// Copyright 2014 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.
#[simd]
pub struct i64x2(i64, i64); //~ ERROR: SIMD types are experimental
fn main() {}

View File

@ -1,37 +0,0 @@
// Copyright 2014 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.
// ignore-tidy-linelength
#![feature(core)]
use std::simd::f32x4;
fn main() {
let _ = f32x4(0.0, 0.0, 0.0, 0.0) == f32x4(0.0, 0.0, 0.0, 0.0);
//~^ ERROR binary comparison operation `==` not supported for floating point SIMD vector `core::simd::f32x4`
let _ = f32x4(0.0, 0.0, 0.0, 0.0) != f32x4(0.0, 0.0, 0.0, 0.0);
//~^ ERROR binary comparison operation `!=` not supported for floating point SIMD vector `core::simd::f32x4`
let _ = f32x4(0.0, 0.0, 0.0, 0.0) < f32x4(0.0, 0.0, 0.0, 0.0);
//~^ ERROR binary comparison operation `<` not supported for floating point SIMD vector `core::simd::f32x4`
let _ = f32x4(0.0, 0.0, 0.0, 0.0) <= f32x4(0.0, 0.0, 0.0, 0.0);
//~^ ERROR binary comparison operation `<=` not supported for floating point SIMD vector `core::simd::f32x4`
let _ = f32x4(0.0, 0.0, 0.0, 0.0) >= f32x4(0.0, 0.0, 0.0, 0.0);
//~^ ERROR binary comparison operation `>=` not supported for floating point SIMD vector `core::simd::f32x4`
let _ = f32x4(0.0, 0.0, 0.0, 0.0) > f32x4(0.0, 0.0, 0.0, 0.0);
//~^ ERROR binary comparison operation `>` not supported for floating point SIMD vector `core::simd::f32x4`
}

View File

@ -8,18 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(simd)]
#![feature(repr_simd)]
#[simd]
struct vec4<T>(T, T, T, T); //~ ERROR SIMD vector cannot be generic
#[simd]
#[repr(simd)]
struct empty; //~ ERROR SIMD vector cannot be empty
#[simd]
#[repr(simd)]
struct i64f64(i64, f64); //~ ERROR SIMD vector should be homogeneous
#[simd]
#[repr(simd)]
struct int4(isize, isize, isize, isize); //~ ERROR SIMD vector element type should be machine type
fn main() {}

View File

@ -1,23 +0,0 @@
// Copyright 2015 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.
// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
// compile-flags: -C debug-assertions
#![feature(core_simd)]
use std::simd::i32x4;
// (Work around constant-evaluation)
fn id<T>(x: T) -> T { x }
fn main() {
let _x = i32x4(1, 0, 0, 0) << id(i32x4(32, 0, 0, 0));
}

View File

@ -1,23 +0,0 @@
// Copyright 2015 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.
// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
// compile-flags: -C debug-assertions
#![feature(core_simd)]
use std::simd::i32x4;
// (Work around constant-evaluation)
fn id<T>(x: T) -> T { x }
fn main() {
let _x = i32x4(1, 0, 0, 0) << id(i32x4(-1, 0, 0, 0));
}

View File

@ -1,23 +0,0 @@
// Copyright 2015 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.
// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
// compile-flags: -C debug-assertions
#![feature(core_simd)]
use std::simd::u64x2;
// (Work around constant-evaluation)
fn id<T>(x: T) -> T { x }
fn main() {
let _x = u64x2(1, 0) << id(u64x2(64, 0));
}

View File

@ -1,49 +0,0 @@
// Copyright 2015 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.
// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
// compile-flags: -C debug-assertions
// This function is checking that our automatic truncation does not
// sidestep the overflow checking.
#![feature(core_simd)]
use std::simd::i8x16;
fn eq_i8x16(i8x16(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15): i8x16,
i8x16(y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15): i8x16)
-> bool
{
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
&& (x4 == y4) && (x5 == y5) && (x6 == y6) && (x7 == y7)
&& (x8 == y8) && (x9 == y9) && (x10 == y10) && (x11 == y11)
&& (x12 == y12) && (x13 == y13) && (x14 == y14) && (x15 == y15)
}
// (Work around constant-evaluation)
fn id<T>(x: T) -> T { x }
fn main() {
// this signals overflow when checking is on
let x = i8x16(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
<< id(i8x16(17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
// ... but when checking is off, the fallback will truncate the
// input to its lower three bits (= 1). Note that this is *not*
// the behavior of the x86 processor for 8- and 16-bit types,
// but it is necessary to avoid undefined behavior from LLVM.
//
// We check that here, by ensuring the result has only been
// shifted by one place; if overflow checking is turned off, then
// this assertion will pass (and the compiletest driver will
// report that the test did not produce the error expected above).
assert!(eq_i8x16(x, i8x16(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
}

View File

@ -1,23 +0,0 @@
// Copyright 2015 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.
// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
// compile-flags: -C debug-assertions
#![feature(core_simd)]
use std::simd::i32x4;
// (Work around constant-evaluation)
fn id<T>(x: T) -> T { x }
fn main() {
let _x = i32x4(-1, 0, 0, 0) >> id(i32x4(32, 0, 0, 0));
}

View File

@ -1,23 +0,0 @@
// Copyright 2015 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.
// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
// compile-flags: -C debug-assertions
#![feature(core_simd)]
use std::simd::i32x4;
// (Work around constant-evaluation)
fn id<T>(x: T) -> T { x }
fn main() {
let _x = i32x4(0, 0, 0, -1) >> id(i32x4(0, 0, 0, -1));
}

View File

@ -1,23 +0,0 @@
// Copyright 2015 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.
// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
// compile-flags: -C debug-assertions
#![feature(core_simd)]
use std::simd::i64x2;
// (Work around constant-evaluation)
fn id<T>(x: T) -> T { x }
fn main() {
let _x = i64x2(0, -1) >> id(i64x2(0, 64));
}

View File

@ -1,49 +0,0 @@
// Copyright 2015 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.
// error-pattern:thread '<main>' panicked at 'shift operation overflowed'
// compile-flags: -C debug-assertions
// This function is checking that our (type-based) automatic
// truncation does not sidestep the overflow checking.
#![feature(core_simd)]
use std::simd::i8x16;
fn eq_i8x16(i8x16(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15): i8x16,
i8x16(y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15): i8x16)
-> bool
{
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
&& (x4 == y4) && (x5 == y5) && (x6 == y6) && (x7 == y7)
&& (x8 == y8) && (x9 == y9) && (x10 == y10) && (x11 == y11)
&& (x12 == y12) && (x13 == y13) && (x14 == y14) && (x15 == y15)
}
// (Work around constant-evaluation)
fn id<T>(x: T) -> T { x }
fn main() {
// this signals overflow when checking is on
let x = i8x16(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
>> id(i8x16(17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
// ... but when checking is off, the fallback will truncate the
// input to its lower three bits (= 1). Note that this is *not*
// the behavior of the x86 processor for 8- and 16-bit types,
// but it is necessary to avoid undefined behavior from LLVM.
//
// We check that here, by ensuring the result is not zero; if
// overflow checking is turned off, then this assertion will pass
// (and the compiletest driver will report that the test did not
// produce the error expected above).
assert!(eq_i8x16(x, i8x16(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
}

View File

@ -15,12 +15,12 @@
#![feature(no_core)]
#![no_core]
#![feature(simd, simd_ffi, link_llvm_intrinsics, lang_items)]
#![feature(repr_simd, simd_ffi, link_llvm_intrinsics, lang_items)]
#[repr(C)]
#[derive(Copy)]
#[simd]
#[repr(simd)]
pub struct f32x4(f32, f32, f32, f32);
@ -35,7 +35,7 @@ pub fn foo(x: f32x4) -> f32x4 {
#[repr(C)]
#[derive(Copy)]
#[simd]
#[repr(simd)]
pub struct i32x4(i32, i32, i32, i32);

View File

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(simd)]
#![feature(repr_simd)]
#[simd]
#[repr(simd)]
struct T(f64, f64, f64);
static X: T = T(0.0, 0.0, 0.0);

View File

@ -1,19 +0,0 @@
// Copyright 2015 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.
#![feature(core_simd)]
use std::simd::i32x4;
fn main() {
let foo = i32x4(1,2,3,4);
let bar = i32x4(40,30,20,10);
let baz = foo + bar;
assert!(baz.0 == 41 && baz.1 == 32 && baz.2 == 23 && baz.3 == 14);
}

View File

@ -1,26 +0,0 @@
// Copyright 2015 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: -C debug-assertions
#![feature(core_simd)]
use std::simd::u32x4;
// (Work around constant-evaluation)
fn id<T>(x: T) -> T { x }
fn eq_u32x4(u32x4(x0, x1, x2, x3): u32x4, u32x4(y0, y1, y2, y3): u32x4) -> bool {
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
}
fn main() {
assert!(eq_u32x4(u32x4(1, 1, 1, 1) << id(u32x4(1, 1, 1, 1)), u32x4(2, 2, 2, 2)));
}

View File

@ -1,76 +0,0 @@
// Copyright 2013-2014 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.
#![feature(core_simd)]
use std::simd::{i32x4, f32x4, u32x4};
fn eq_u32x4(u32x4(x0, x1, x2, x3): u32x4, u32x4(y0, y1, y2, y3): u32x4) -> bool {
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
}
fn eq_f32x4(f32x4(x0, x1, x2, x3): f32x4, f32x4(y0, y1, y2, y3): f32x4) -> bool {
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
}
fn eq_i32x4(i32x4(x0, x1, x2, x3): i32x4, i32x4(y0, y1, y2, y3): i32x4) -> bool {
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
}
pub fn main() {
// arithmetic operators
assert!(eq_u32x4(u32x4(1, 2, 3, 4) + u32x4(4, 3, 2, 1), u32x4(5, 5, 5, 5)));
assert!(eq_u32x4(u32x4(4, 5, 6, 7) - u32x4(4, 3, 2, 1), u32x4(0, 2, 4, 6)));
assert!(eq_u32x4(u32x4(1, 2, 3, 4) * u32x4(4, 3, 2, 1), u32x4(4, 6, 6, 4)));
assert!(eq_u32x4(u32x4(1, 2, 3, 4) / u32x4(4, 3, 2, 1), u32x4(0, 0, 1, 4)));
assert!(eq_u32x4(u32x4(1, 2, 3, 4) & u32x4(4, 3, 2, 1), u32x4(0, 2, 2, 0)));
assert!(eq_u32x4(u32x4(1, 2, 3, 4) | u32x4(4, 3, 2, 1), u32x4(5, 3, 3, 5)));
assert!(eq_u32x4(u32x4(1, 2, 3, 4) ^ u32x4(4, 3, 2, 1), u32x4(5, 1, 1, 5)));
assert!(eq_u32x4(u32x4(1, 2, 3, 4) << u32x4(4, 3, 2, 1), u32x4(16, 16, 12, 8)));
assert!(eq_u32x4(u32x4(1, 2, 3, 4) >> u32x4(4, 3, 2, 1), u32x4(0, 0, 0, 2)));
assert!(eq_i32x4(i32x4(1, 2, 3, 4) + i32x4(4, 3, 2, 1), i32x4(5, 5, 5, 5)));
assert!(eq_i32x4(i32x4(1, 2, 3, 4) - i32x4(4, 3, 2, 1), i32x4(-3, -1, 1, 3)));
assert!(eq_i32x4(i32x4(1, 2, 3, 4) * i32x4(4, 3, 2, 1), i32x4(4, 6, 6, 4)));
assert!(eq_i32x4(i32x4(1, 2, 3, 4) / i32x4(4, 3, 2, 1), i32x4(0, 0, 1, 4)));
assert!(eq_i32x4(i32x4(1, 2, 3, 4) & i32x4(4, 3, 2, 1), i32x4(0, 2, 2, 0)));
assert!(eq_i32x4(i32x4(1, 2, 3, 4) | i32x4(4, 3, 2, 1), i32x4(5, 3, 3, 5)));
assert!(eq_i32x4(i32x4(1, 2, 3, 4) ^ i32x4(4, 3, 2, 1), i32x4(5, 1, 1, 5)));
assert!(eq_i32x4(i32x4(1, 2, 3, 4) << i32x4(4, 3, 2, 1), i32x4(16, 16, 12, 8)));
assert!(eq_i32x4(i32x4(1, 2, 3, 4) >> i32x4(4, 3, 2, 1), i32x4(0, 0, 0, 2)));
assert!(eq_f32x4(f32x4(1.0, 2.0, 3.0, 4.0) + f32x4(4.0, 3.0, 2.0, 1.0),
f32x4(5.0, 5.0, 5.0, 5.0)));
assert!(eq_f32x4(f32x4(1.0, 2.0, 3.0, 4.0) - f32x4(4.0, 3.0, 2.0, 1.0),
f32x4(-3.0, -1.0, 1.0, 3.0)));
assert!(eq_f32x4(f32x4(1.0, 2.0, 3.0, 4.0) * f32x4(4.0, 3.0, 2.0, 1.0),
f32x4(4.0, 6.0, 6.0, 4.0)));
assert!(eq_f32x4(f32x4(1.0, 2.0, 3.0, 4.0) / f32x4(4.0, 4.0, 2.0, 1.0),
f32x4(0.25, 0.5, 1.5, 4.0)));
// comparison operators
// check !0/-1 to ensure operators are using the correct signedness.
assert!(eq_u32x4(u32x4(1, 2, 3, !0) == u32x4(3, 2, 1, 0), u32x4(0, !0, 0, 0)));
assert!(eq_u32x4(u32x4(1, 2, 3, !0) != u32x4(3, 2, 1, 0), u32x4(!0, 0, !0, !0)));
assert!(eq_u32x4(u32x4(1, 2, 3, !0) < u32x4(3, 2, 1, 0), u32x4(!0, 0, 0, 0)));
assert!(eq_u32x4(u32x4(1, 2, 3, !0) <= u32x4(3, 2, 1, 0), u32x4(!0, !0, 0, 0)));
assert!(eq_u32x4(u32x4(1, 2, 3, !0) >= u32x4(3, 2, 1, 0), u32x4(0, !0, !0, !0)));
assert!(eq_u32x4(u32x4(1, 2, 3, !0) > u32x4(3, 2, 1, 0), u32x4(0, 0, !0, !0)));
assert!(eq_i32x4(i32x4(1, 2, 3, -1) == i32x4(3, 2, 1, 0), i32x4(0, !0, 0, 0)));
assert!(eq_i32x4(i32x4(1, 2, 3, -1) != i32x4(3, 2, 1, 0), i32x4(!0, 0, !0, !0)));
assert!(eq_i32x4(i32x4(1, 2, 3, -1) < i32x4(3, 2, 1, 0), i32x4(!0, 0, 0, !0)));
assert!(eq_i32x4(i32x4(1, 2, 3, -1) <= i32x4(3, 2, 1, 0), i32x4(!0, !0, 0, !0)));
assert!(eq_i32x4(i32x4(1, 2, 3, -1) >= i32x4(3, 2, 1, 0), i32x4(0, !0, !0, 0)));
assert!(eq_i32x4(i32x4(1, 2, 3, -1) > i32x4(3, 2, 1, 0), i32x4(0, 0, !0, 0)));
}

View File

@ -10,14 +10,18 @@
#![feature(simd)]
#![feature(repr_simd, platform_intrinsics)]
use std::ops;
#[simd]
#[repr(simd)]
#[derive(Copy, Clone)]
struct f32x4(f32, f32, f32, f32);
extern "platform-intrinsic" {
fn simd_add<T>(x: T, y: T) -> T;
}
fn add<T: ops::Add<Output=T>>(lhs: T, rhs: T) -> T {
lhs + rhs
}
@ -26,7 +30,7 @@ impl ops::Add for f32x4 {
type Output = f32x4;
fn add(self, rhs: f32x4) -> f32x4 {
self + rhs
unsafe {simd_add(self, rhs)}
}
}

View File

@ -1,154 +0,0 @@
// Copyright 2015 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: -C debug-assertions
// Check that we do *not* overflow on a number of edge cases.
// (compare with test/run-fail/overflowing-{lsh,rsh}*.rs)
#![feature(core_simd)]
use std::simd::{i8x16, i16x8, i32x4, i64x2, u8x16, u16x8, u32x4, u64x2};
// (Work around constant-evaluation)
fn id<T>(x: T) -> T { x }
fn single_i8x16(x: i8) -> i8x16 { i8x16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, x) }
fn single_u8x16(x: u8) -> u8x16 { u8x16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, x) }
fn single_i16x8(x: i16) -> i16x8 { i16x8(0, 0, 0, 0, 0, 0, 0, x) }
fn single_u16x8(x: u16) -> u16x8 { u16x8(0, 0, 0, 0, 0, 0, 0, x) }
fn single_i32x4(x: i32) -> i32x4 { i32x4(0, 0, 0, x) }
fn single_u32x4(x: u32) -> u32x4 { u32x4(0, 0, 0, x) }
fn single_i64x2(x: i64) -> i64x2 { i64x2(0, x) }
fn single_u64x2(x: u64) -> u64x2 { u64x2(0, x) }
fn eq_i8x16(i8x16(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15): i8x16,
i8x16(y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15): i8x16)
-> bool {
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
&& (x4 == y4) && (x5 == y5) && (x6 == y6) && (x7 == y7)
&& (x8 == y8) && (x9 == y9) && (x10 == y10) && (x11 == y11)
&& (x12 == y12) && (x13 == y13) && (x14 == y14) && (x15 == y15)
}
fn eq_u8x16(u8x16(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15): u8x16,
u8x16(y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15): u8x16)
-> bool {
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
&& (x4 == y4) && (x5 == y5) && (x6 == y6) && (x7 == y7)
&& (x8 == y8) && (x9 == y9) && (x10 == y10) && (x11 == y11)
&& (x12 == y12) && (x13 == y13) && (x14 == y14) && (x15 == y15)
}
fn eq_i16x8(i16x8(x0, x1, x2, x3, x4, x5, x6, x7): i16x8,
i16x8(y0, y1, y2, y3, y4, y5, y6, y7): i16x8) -> bool {
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
&& (x4 == y4) && (x5 == y5) && (x6 == y6) && (x7 == y7)
}
fn eq_u16x8(u16x8(x0, x1, x2, x3, x4, x5, x6, x7): u16x8,
u16x8(y0, y1, y2, y3, y4, y5, y6, y7): u16x8) -> bool {
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
&& (x4 == y4) && (x5 == y5) && (x6 == y6) && (x7 == y7)
}
fn eq_i32x4(i32x4(x0, x1, x2, x3): i32x4, i32x4(y0, y1, y2, y3): i32x4) -> bool {
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
}
fn eq_u32x4(u32x4(x0, x1, x2, x3): u32x4, u32x4(y0, y1, y2, y3): u32x4) -> bool {
(x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3)
}
fn eq_i64x2(i64x2(x0, x1): i64x2, i64x2(y0, y1): i64x2) -> bool {
(x0 == y0) && (x1 == y1)
}
fn eq_u64x2(u64x2(x0, x1): u64x2, u64x2(y0, y1): u64x2) -> bool {
(x0 == y0) && (x1 == y1)
}
fn main() {
test_left_shift();
test_right_shift();
}
fn test_left_shift() {
// negative rhs can panic, but values in [0,N-1] are okay for iN
macro_rules! tests {
($single:ident, $eq:ident, $max_rhs:expr, $expect:expr) => { {
let x = $single(1) << id($single(0));
assert!($eq(x, $single(1)));
let x = $single(1) << id($single($max_rhs));
assert!($eq(x, $single($expect)));
// high-order bits on LHS are silently discarded without panic.
let x = $single(3) << id($single($max_rhs));
assert!($eq(x, $single($expect)));
} }
}
let x = single_i8x16(1) << id(single_i8x16(0));
assert!(eq_i8x16(x, single_i8x16(1)));
let x = single_u8x16(1) << id(single_u8x16(0));
assert!(eq_u8x16(x, single_u8x16(1)));
let x = single_i8x16(1) << id(single_i8x16(7));
assert!(eq_i8x16(x, single_i8x16(std::i8::MIN)));
let x = single_u8x16(1) << id(single_u8x16(7));
assert!(eq_u8x16(x, single_u8x16(0x80)));
// high-order bits on LHS are silently discarded without panic.
let x = single_i8x16(3) << id(single_i8x16(7));
assert!(eq_i8x16(x, single_i8x16(std::i8::MIN)));
let x = single_u8x16(3) << id(single_u8x16(7));
assert!(eq_u8x16(x, single_u8x16(0x80)));
// above is (approximately) expanded from:
tests!(single_i8x16, eq_i8x16, 7, std::i8::MIN);
tests!(single_u8x16, eq_u8x16, 7, 0x80_u8);
tests!(single_i16x8, eq_i16x8, 15, std::i16::MIN);
tests!(single_u16x8, eq_u16x8, 15, 0x8000_u16);
tests!(single_i32x4, eq_i32x4, 31, std::i32::MIN);
tests!(single_u32x4, eq_u32x4, 31, 0x8000_0000_u32);
tests!(single_i64x2, eq_i64x2, 63, std::i64::MIN);
tests!(single_u64x2, eq_u64x2, 63, 0x8000_0000_0000_0000_u64);
}
fn test_right_shift() {
// negative rhs can panic, but values in [0,N-1] are okay for iN
macro_rules! tests {
($single_i:ident, $eq_i:ident, $single_u:ident, $eq_u:ident,
$max_rhs:expr, $signbit_i:expr, $highbit_i:expr, $highbit_u:expr) => { {
let x = $single_i(1) >> id($single_i(0));
assert!($eq_i(x, $single_i(1)));
let x = $single_u(1) >> id($single_u(0));
assert!($eq_u(x, $single_u(1)));
let x = $single_u($highbit_i) >> id($single_u($max_rhs-1));
assert!($eq_u(x, $single_u(1)));
let x = $single_u($highbit_u) >> id($single_u($max_rhs));
assert!($eq_u(x, $single_u(1)));
// sign-bit is carried by arithmetic right shift
let x = $single_i($signbit_i) >> id($single_i($max_rhs));
assert!($eq_i(x, $single_i(-1)));
// low-order bits on LHS are silently discarded without panic.
let x = $single_u($highbit_i + 1) >> id($single_u($max_rhs-1));
assert!($eq_u(x, $single_u(1)));
let x = $single_u($highbit_u + 1) >> id($single_u($max_rhs));
assert!($eq_u(x, $single_u(1)));
let x = $single_i($signbit_i + 1) >> id($single_i($max_rhs));
assert!($eq_i(x, $single_i(-1)));
} }
}
tests!(single_i8x16, eq_i8x16, single_u8x16, eq_u8x16,
7, std::i8::MIN, 0x40_u8, 0x80_u8);
tests!(single_i16x8, eq_i16x8, single_u16x8, eq_u16x8,
15, std::i16::MIN, 0x4000_u16, 0x8000_u16);
tests!(single_i32x4, eq_i32x4, single_u32x4, eq_u32x4,
31, std::i32::MIN, 0x4000_0000_u32, 0x8000_0000_u32);
tests!(single_i64x2, eq_i64x2, single_u64x2, eq_u64x2,
63, std::i64::MIN, 0x4000_0000_0000_0000_u64, 0x8000_0000_0000_0000_u64);
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
#![feature(simd)]
#![feature(repr_simd)]
#![allow(non_camel_case_types)]
use std::mem;
@ -46,26 +46,26 @@ fn main() {
check::<f32x8>();
}
#[simd] struct u8x2(u8, u8);
#[simd] struct u8x3(u8, u8, u8);
#[simd] struct u8x4(u8, u8, u8, u8);
#[simd] struct u8x5(u8, u8, u8, u8, u8);
#[simd] struct u8x6(u8, u8, u8, u8, u8, u8);
#[simd] struct u8x7(u8, u8, u8, u8, u8, u8, u8);
#[simd] struct u8x8(u8, u8, u8, u8, u8, u8, u8, u8);
#[repr(simd)] struct u8x2(u8, u8);
#[repr(simd)] struct u8x3(u8, u8, u8);
#[repr(simd)] struct u8x4(u8, u8, u8, u8);
#[repr(simd)] struct u8x5(u8, u8, u8, u8, u8);
#[repr(simd)] struct u8x6(u8, u8, u8, u8, u8, u8);
#[repr(simd)] struct u8x7(u8, u8, u8, u8, u8, u8, u8);
#[repr(simd)] struct u8x8(u8, u8, u8, u8, u8, u8, u8, u8);
#[simd] struct i16x2(i16, i16);
#[simd] struct i16x3(i16, i16, i16);
#[simd] struct i16x4(i16, i16, i16, i16);
#[simd] struct i16x5(i16, i16, i16, i16, i16);
#[simd] struct i16x6(i16, i16, i16, i16, i16, i16);
#[simd] struct i16x7(i16, i16, i16, i16, i16, i16, i16);
#[simd] struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
#[repr(simd)] struct i16x2(i16, i16);
#[repr(simd)] struct i16x3(i16, i16, i16);
#[repr(simd)] struct i16x4(i16, i16, i16, i16);
#[repr(simd)] struct i16x5(i16, i16, i16, i16, i16);
#[repr(simd)] struct i16x6(i16, i16, i16, i16, i16, i16);
#[repr(simd)] struct i16x7(i16, i16, i16, i16, i16, i16, i16);
#[repr(simd)] struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
#[simd] struct f32x2(f32, f32);
#[simd] struct f32x3(f32, f32, f32);
#[simd] struct f32x4(f32, f32, f32, f32);
#[simd] struct f32x5(f32, f32, f32, f32, f32);
#[simd] struct f32x6(f32, f32, f32, f32, f32, f32);
#[simd] struct f32x7(f32, f32, f32, f32, f32, f32, f32);
#[simd] struct f32x8(f32, f32, f32, f32, f32, f32, f32, f32);
#[repr(simd)] struct f32x2(f32, f32);
#[repr(simd)] struct f32x3(f32, f32, f32);
#[repr(simd)] struct f32x4(f32, f32, f32, f32);
#[repr(simd)] struct f32x5(f32, f32, f32, f32, f32);
#[repr(simd)] struct f32x6(f32, f32, f32, f32, f32, f32);
#[repr(simd)] struct f32x7(f32, f32, f32, f32, f32, f32, f32);
#[repr(simd)] struct f32x8(f32, f32, f32, f32, f32, f32, f32, f32);

View File

@ -11,9 +11,9 @@
// pretty-expanded FIXME #23616
#![feature(simd)]
#![feature(repr_simd)]
#[simd]
#[repr(simd)]
struct RGBA {
r: f32,
g: f32,