Skip to content

Commit

Permalink
vec: always use repr(C) for non-power-of-two-length vectors, fixes #66
Browse files Browse the repository at this point in the history
  • Loading branch information
yoanlcq committed Feb 7, 2021
1 parent 7a3bca7 commit 3274010
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
version = "0.13.1" # remember to update html_root_url in src/lib.rs
version = "0.14.0" # remember to update html_root_url in src/lib.rs
authors = ["Yoan Lecoq <yoanlecoq.io@gmail.com>", "Joshua Barretto <joshua.s.barretto@gmail.com>", "Sunjay Varma <varma.sunjay@gmail.com>", "timokoesters <timo@koesters.xyz>", "Imbris <imbrisf@gmail.com>"]
description = "Generic 2D-3D math swiss army knife for game engines, with SIMD support and focus on convenience."
documentation = "https://docs.rs/vek"
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#![no_std]
#![doc(
test(attr(deny(warnings))),
html_root_url = "https://docs.rs/vek/0.13.1",
html_root_url = "https://docs.rs/vek/0.14.0",
//html_logo_url = "https://yoanlcq.github.io/vek/logo.png",
//html_favicon_url = "https://yoanlcq.github.io/vek/favicon.ico",
)]
Expand Down
40 changes: 16 additions & 24 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2740,7 +2740,7 @@ macro_rules! vec_impl_mint {

/// Calls `vec_impl_vec!{}` on each appropriate vector type.
macro_rules! vec_impl_all_vecs {
($c_or_simd:ident $(#[$repr_attrs:meta])+) => {
($c_or_simd:ident #[$repr_for_power_of_two_length:meta] #[$repr_for_non_power_of_two_length:meta]) => {

/// Vector type suited for 2D spatial coordinates.
pub mod vec2 {
Expand All @@ -2749,7 +2749,7 @@ macro_rules! vec_impl_all_vecs {
#[allow(missing_docs)]
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_power_of_two_length]
pub struct Vec2<T> { pub x:T, pub y:T }
vec_impl_vec!($c_or_simd struct Vec2 vec2 (2) ("({...}, {...})") ("") (x y) (x y) (0 1) (T,T));
vec_impl_mint!(Vec2, Vector2, (x y));
Expand Down Expand Up @@ -2790,7 +2790,7 @@ macro_rules! vec_impl_all_vecs {
#[allow(missing_docs)]
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_non_power_of_two_length]
pub struct Vec3<T> { pub x:T, pub y:T, pub z:T }
vec_impl_vec!($c_or_simd struct Vec3 vec3 (3) ("({...}, {...}, {...})") ("") (x y z) (x y z) (0 1 2) (T,T,T));
vec_impl_mint!(Vec3, Vector3, (x y z));
Expand Down Expand Up @@ -2847,7 +2847,7 @@ macro_rules! vec_impl_all_vecs {
#[allow(missing_docs)]
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_power_of_two_length]
pub struct Vec4<T> {
pub x:T, pub y:T, pub z:T,
/// In homogeneous 3D-space coordinates, `w` is often set to
Expand Down Expand Up @@ -2920,7 +2920,7 @@ macro_rules! vec_impl_all_vecs {
/// If you find yourself needing them, use other crates such as `llvmint` or `x86intrin`.
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_power_of_two_length]
pub struct Vec8<T>(pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T);
vec_impl_vec!($c_or_simd tuple Vec8 vec8 (8) ("({...}, {...}, {...}, {...}, {...}, {...}, {...}, {...})") ("") (0 1 2 3 4 5 6 7) (m0 m1 m2 m3 m4 m5 m6 m7) (0 1 2 3 4 5 6 7) (T,T,T,T,T,T,T,T));
vec_impl_spatial!(Vec8);
Expand All @@ -2942,7 +2942,7 @@ macro_rules! vec_impl_all_vecs {
/// If you find yourself needing them, use other crates such as `llvmint` or `x86intrin`.
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_power_of_two_length]
pub struct Vec16<T>(pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T);
vec_impl_vec!($c_or_simd tuple Vec16 vec16 (16) ("({...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...})") ("") (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) (m0 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15) (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) (T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T));
vec_impl_spatial!(Vec16);
Expand All @@ -2964,7 +2964,7 @@ macro_rules! vec_impl_all_vecs {
/// If you find yourself needing them, use other crates such as `llvmint` or `x86intrin`.
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_power_of_two_length]
pub struct Vec32<T>(pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T);
vec_impl_vec!($c_or_simd tuple Vec32 vec32 (32) ("({...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...})") ("") (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) (m0 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19 m20 m21 m22 m23 m24 m25 m26 m27 m28 m29 m30 m31) (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) (T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T));
vec_impl_spatial!(Vec32);
Expand All @@ -2987,7 +2987,7 @@ macro_rules! vec_impl_all_vecs {
/// If you find yourself needing them, use other crates such as `llvmint` or `x86intrin`.
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_power_of_two_length]
pub struct Vec64<T>(pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T, pub T);
vec_impl_vec!($c_or_simd tuple Vec64 vec64 (64) ("({...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...})") ("") (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63) (m0 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19 m20 m21 m22 m23 m24 m25 m26 m27 m28 m29 m30 m31 m32 m33 m34 m35 m36 m37 m38 m39 m40 m41 m42 m43 m44 m45 m46 m47 m48 m49 m50 m51 m52 m53 m54 m55 m56 m57 m58 m59 m60 m61 m62 m63) (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63) (T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T));
vec_impl_spatial!(Vec64);
Expand All @@ -3009,7 +3009,7 @@ macro_rules! vec_impl_all_vecs {
#[allow(missing_docs)]
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_non_power_of_two_length]
pub struct Extent3<T> { pub w:T, pub h:T, pub d:T }
vec_impl_vec!($c_or_simd struct Extent3 extent3 (3) ("({...}, {...}, {...})") ("") (w h d) (w h d) (0 1 2) (T,T,T));
vec_impl_spatial!(Extent3);
Expand All @@ -3036,7 +3036,7 @@ macro_rules! vec_impl_all_vecs {
#[allow(missing_docs)]
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_power_of_two_length]
pub struct Extent2<T> { pub w:T, pub h:T }
vec_impl_vec!($c_or_simd struct Extent2 extent2 (2) ("({...}, {...})") ("") (w h) (w h) (0 1) (T,T));
vec_impl_spatial!(Extent2);
Expand All @@ -3060,7 +3060,7 @@ macro_rules! vec_impl_all_vecs {
#[allow(missing_docs)]
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_power_of_two_length]
pub struct Rgba<T> { pub r:T, pub g:T, pub b:T, pub a:T }
vec_impl_vec!($c_or_simd struct Rgba rgba (4) ("rgba({...}, {...}, {...}, {...})") ("rgba") (r g b a) (r g b a) (0 1 2 3) (T,T,T,T));
vec_impl_color_rgba!{Rgba}
Expand Down Expand Up @@ -3099,7 +3099,7 @@ macro_rules! vec_impl_all_vecs {
#[allow(missing_docs)]
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_non_power_of_two_length]
pub struct Rgb<T> { pub r:T, pub g:T, pub b:T }
vec_impl_vec!($c_or_simd struct Rgb rgb (3) ("rgb({...}, {...}, {...})") ("rgb") (r g b) (r g b) (0 1 2) (T,T,T));
vec_impl_color_rgb!{Rgb}
Expand Down Expand Up @@ -3127,7 +3127,7 @@ macro_rules! vec_impl_all_vecs {
#[allow(missing_docs)]
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_non_power_of_two_length]
pub struct Uvw<T> { pub u:T, pub v:T, pub w:T }
vec_impl_vec!($c_or_simd struct Uvw uvw (3) ("({...}, {...}, {...})") ("") (u v w) (u v w) (0 1 2) (T,T,T));

Expand All @@ -3148,7 +3148,7 @@ macro_rules! vec_impl_all_vecs {
#[allow(missing_docs)]
#[derive(Debug, Default, Clone, Copy, Hash, Eq, PartialEq/*, Ord, PartialOrd*/)]
#[cfg_attr(feature="serde", derive(Serialize, Deserialize))]
$(#[$repr_attrs])+
#[$repr_for_power_of_two_length]
pub struct Uv<T> { pub u:T, pub v:T }
vec_impl_vec!($c_or_simd struct Uv uv (2) ("({...}, {...})") ("") (u v) (u v) (0 1) (T,T));

Expand All @@ -3160,7 +3160,6 @@ macro_rules! vec_impl_all_vecs {
}
#[cfg(feature="uv")]
pub use self::uv::Uv;

}
}

Expand All @@ -3170,23 +3169,16 @@ pub mod repr_c {
//! See also the `repr_simd` neighbour module, which is available on Nightly
//! with the `repr_simd` feature enabled.


use super::*;
vec_impl_all_vecs!{
c
#[repr(C)]
}
vec_impl_all_vecs!{c #[repr(C)] #[repr(C)]}
}

#[cfg(all(nightly, feature="repr_simd"))]
pub mod repr_simd {
//! Vector types which are marked `#[repr(simd)]`.

use super::*;
vec_impl_all_vecs!{
simd
#[repr(simd)]
}
vec_impl_all_vecs!{simd #[repr(simd)] #[repr(C)]}
}

pub use self::repr_c::*;
Expand Down

0 comments on commit 3274010

Please sign in to comment.