-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
225 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
version = "0.15.7" # remember to update html_root_url in src/lib.rs | ||
version = "0.15.8" # remember to update html_root_url in src/lib.rs | ||
authors = ["Yoan Lecoq <[email protected]>", "Joshua Barretto <[email protected]>", "Sunjay Varma <[email protected]>", "timokoesters <[email protected]>", "Imbris <[email protected]>"] | ||
description = "Generic 2D-3D math swiss army knife for game engines, with SIMD support and focus on convenience." | ||
documentation = "https://docs.rs/vek" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "simd_intrinsics_compile_errors" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
vek = { path = "../../", features = ["repr_simd", "platform_intrinsics"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use vek::vec::repr_simd::Vec4; | ||
|
||
fn main() { | ||
assert!(Vec4::broadcast(true).reduce_and()); | ||
assert!(Vec4::broadcast(true).reduce_or()); | ||
assert!(Vec4::broadcast(1i32).reduce_and()); | ||
assert!(Vec4::broadcast(1i32).reduce_or()); | ||
assert!(Vec4::broadcast(0f32).partial_cmplt(&Vec4::broadcast(1f32)) != Vec4::broadcast(false)); | ||
assert!(Vec4::broadcast(0f32).partial_cmpgt(&Vec4::broadcast(1f32)) == Vec4::broadcast(false)); | ||
assert!(Vec4::broadcast(0f32).partial_cmplt_simd(Vec4::broadcast(1f32)) != Vec4::zero()); | ||
assert!(Vec4::broadcast(0f32).partial_cmpgt_simd(Vec4::broadcast(1f32)) == Vec4::zero()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//! SIMD traits; they are useful when the features "repr_simd" and "platform_intrinsics" are enabled. | ||
use std::num::Wrapping; | ||
use num_traits; | ||
|
||
/// This trait should be implemented by scalar types, vectors of which are supported by SIMD intrinsics. | ||
/// For instance, i16 and f32 can implement this trait, as well as `#[repr(transparent)]` wrappers of these, but not hand-built numeric types. | ||
pub trait SimdElement { | ||
/// The corresponding mask type for this element type: this is usually the unsigned integer type with the same size. | ||
type SimdMaskType: SimdMask; | ||
} | ||
|
||
/// Implemented by unsigned integer types that can represent the result of SIMD comparison elements: semantically, these are booleans, but in their representation, zero is false and any other value is true. | ||
/// Typically, SIMD comparison of two vectors will yield a vector of mask elements, on which you can call `reduce_and()` or `reduce_or()`. | ||
pub trait SimdMask: num_traits::sign::Unsigned + num_traits::bounds::Bounded + num_traits::cast::FromPrimitive { | ||
/// Used for fallback code. | ||
#[inline] | ||
fn from_bool(b: bool) -> Self { | ||
Self::from_u8(b as _).unwrap() | ||
} | ||
} | ||
|
||
macro_rules! impl_simd_mask { | ||
($T:ty) => { | ||
impl SimdMask for $T {} | ||
} | ||
} | ||
|
||
macro_rules! impl_simd_element { | ||
($T:ty, $M:ty) => { | ||
impl SimdElement for $T { | ||
type SimdMaskType = $M; | ||
} | ||
} | ||
} | ||
|
||
impl_simd_mask!{u8} | ||
impl_simd_mask!{u16} | ||
impl_simd_mask!{u32} | ||
impl_simd_mask!{u64} | ||
|
||
impl<T: SimdMask> SimdMask for Wrapping<T> where Wrapping<T>: num_traits::sign::Unsigned {} | ||
|
||
impl_simd_element!{i8, u8} | ||
impl_simd_element!{i16, u16} | ||
impl_simd_element!{i32, u32} | ||
impl_simd_element!{i64, u64} | ||
impl_simd_element!{u8, u8} | ||
impl_simd_element!{u16, u16} | ||
impl_simd_element!{u32, u32} | ||
impl_simd_element!{u64, u64} | ||
impl_simd_element!{f32, u32} | ||
impl_simd_element!{f64, u64} | ||
|
||
impl<T: SimdElement> SimdElement for Wrapping<T> { | ||
type SimdMaskType = T::SimdMaskType; // Don't propagate the Wrapping<>, masks are only intended for reduction to booleans; it doesn't make sense to perform arithmetic on them. | ||
} |
Oops, something went wrong.