-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Allow SIMD types in generics. Closes #10604 #11717
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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. | ||
|
||
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 | ||
} | ||
} | ||
|
||
fn main() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will similarly need |
||
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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// 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. | ||
|
||
fn main() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need to be |
||
let _o = None::<std::unstable::simd::i32x4>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if
size == n * align
? Doesn't this given - 1
? (Is this correct?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be
(n * align - 1) / align
. Either way, all that was changed was I moved that line from 435 to 428 and added the minus one from 439. That was so I could use it in the match arms.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is
n - 1
, which is right — this patch also changesalign_units
from being the size of the entire object to the size of the padding.