Skip to content

Commit

Permalink
Fix layout of non-power-of-two length vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
calebzulawski committed Jun 17, 2024
1 parent c79585c commit 227a9d9
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 75 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,34 +245,6 @@ jobs:
- name: Test (release)
run: cross test --verbose --target=${{ matrix.target }} --release

features:
name: "Test cargo features (${{ matrix.simd }} × ${{ matrix.features }})"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
simd:
- ""
- "avx512"
features:
- ""
- "--features std"
- "--features all_lane_counts"
- "--all-features"

steps:
- uses: actions/checkout@v2
- name: Detect AVX512
run: echo "CPU_FEATURE=$(lscpu | grep -o avx512[a-z]* | sed s/avx/+avx/ | tr '\n' ',' )" >> $GITHUB_ENV
- name: Check build
if: ${{ matrix.simd == '' }}
run: RUSTFLAGS="-Dwarnings" cargo test --all-targets --no-default-features ${{ matrix.features }}
- name: Check AVX
if: ${{ matrix.simd == 'avx512' && contains(env.CPU_FEATURE, 'avx512') }}
run: |
echo "Found AVX features: $CPU_FEATURE"
RUSTFLAGS="-Dwarnings -Ctarget-feature=$CPU_FEATURE" cargo test --all-targets --no-default-features ${{ matrix.features }}
miri:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 1 addition & 2 deletions crates/core_simd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ categories = ["hardware-support", "no-std"]
license = "MIT OR Apache-2.0"

[features]
default = ["as_crate"]
default = ["as_crate", "std"]
as_crate = []
std = []
all_lane_counts = []

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen = "0.2"
Expand Down
8 changes: 3 additions & 5 deletions crates/core_simd/src/lane_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ macro_rules! supported_lane_count {
};
}

supported_lane_count!(1, 2, 4, 8, 16, 32, 64);
#[cfg(feature = "all_lane_counts")]
supported_lane_count!(
3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 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
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, 64
);
2 changes: 1 addition & 1 deletion crates/core_simd/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ use crate::simd::{
// directly constructing an instance of the type (i.e. `let vector = Simd(array)`) should be
// avoided, as it will likely become illegal on `#[repr(simd)]` structs in the future. It also
// causes rustc to emit illegal LLVM IR in some cases.
#[repr(simd)]
#[repr(simd, packed)]
pub struct Simd<T, const N: usize>([T; N])
where
LaneCount<N>: SupportedLaneCount,
Expand Down
35 changes: 35 additions & 0 deletions crates/core_simd/tests/layout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![feature(portable_simd)]

macro_rules! layout_tests {
{ $($mod:ident, $ty:ty,)* } => {
$(
mod $mod {
test_helpers::test_lanes! {
fn no_padding<const LANES: usize>() {
assert_eq!(
core::mem::size_of::<core_simd::simd::Simd::<$ty, LANES>>(),
core::mem::size_of::<[$ty; LANES]>(),
);
}
}
}
)*
}
}

layout_tests! {
i8, i8,
i16, i16,
i32, i32,
i64, i64,
isize, isize,
u8, u8,
u16, u16,
u32, u32,
u64, u64,
usize, usize,
f32, f32,
f64, f64,
mut_ptr, *mut (),
const_ptr, *const (),
}
1 change: 0 additions & 1 deletion crates/core_simd/tests/masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ macro_rules! test_mask_api {
assert_eq!(Mask::<$type, 2>::from_bitmask(bitmask), mask);
}

#[cfg(feature = "all_lane_counts")]
#[test]
fn roundtrip_bitmask_conversion_odd() {
let values = [
Expand Down
3 changes: 0 additions & 3 deletions crates/test_helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@ publish = false

[dependencies]
proptest = { version = "0.10", default-features = false, features = ["alloc"] }

[features]
all_lane_counts = []
47 changes: 12 additions & 35 deletions crates/test_helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,39 +539,25 @@ macro_rules! test_lanes {
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)];
lanes_1 1;
lanes_2 2;
lanes_3 3; // test one non-power-of-2 length on miri
);

#[cfg(not(miri))] // Miri intrinsic implementations are uniform and larger tests are sloooow
$crate::test_lanes_helper!(
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)];
lanes_4 4;
lanes_8 8;
lanes_16 16;
lanes_32 32;
lanes_64 64;
);

#[cfg(feature = "all_lane_counts")]
$crate::test_lanes_helper!(
// test one non-power-of-2 length on miri
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)];
lanes_3 3;
);

#[cfg(feature = "all_lane_counts")]
#[cfg(not(miri))] // Miri intrinsic implementations are uniform and larger tests are sloooow
$crate::test_lanes_helper!(
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)];
lanes_5 5;
lanes_6 6;
lanes_7 7;
lanes_8 8;
lanes_9 9;
lanes_10 10;
lanes_11 11;
lanes_12 12;
lanes_13 13;
lanes_14 14;
lanes_15 15;
lanes_16 16;
lanes_17 17;
lanes_18 18;
lanes_19 19;
Expand All @@ -587,6 +573,7 @@ macro_rules! test_lanes {
lanes_29 29;
lanes_30 30;
lanes_31 31;
lanes_32 32;
lanes_33 33;
lanes_34 34;
lanes_35 35;
Expand Down Expand Up @@ -618,6 +605,7 @@ macro_rules! test_lanes {
lanes_61 61;
lanes_62 62;
lanes_63 63;
lanes_64 64;
);
}
)*
Expand All @@ -639,43 +627,30 @@ macro_rules! test_lanes_panic {
core_simd::simd::LaneCount<$lanes>: core_simd::simd::SupportedLaneCount,
$body

// test some odd and even non-power-of-2 lengths on miri
$crate::test_lanes_helper!(
#[should_panic];
lanes_1 1;
lanes_2 2;
lanes_4 4;
);

#[cfg(not(miri))] // Miri intrinsic implementations are uniform and larger tests are sloooow
$crate::test_lanes_helper!(
#[should_panic];
lanes_8 8;
lanes_16 16;
lanes_32 32;
lanes_64 64;
);

#[cfg(feature = "all_lane_counts")]
$crate::test_lanes_helper!(
// test some odd and even non-power-of-2 lengths on miri
#[should_panic];
lanes_3 3;
lanes_4 4;
lanes_5 5;
lanes_6 6;
);

#[cfg(feature = "all_lane_counts")]
#[cfg(not(miri))] // Miri intrinsic implementations are uniform and larger tests are sloooow
$crate::test_lanes_helper!(
#[should_panic];
lanes_6 6;
lanes_7 7;
lanes_8 8;
lanes_9 9;
lanes_10 10;
lanes_11 11;
lanes_12 12;
lanes_13 13;
lanes_14 14;
lanes_15 15;
lanes_16 16;
lanes_17 17;
lanes_18 18;
lanes_19 19;
Expand All @@ -691,6 +666,7 @@ macro_rules! test_lanes_panic {
lanes_29 29;
lanes_30 30;
lanes_31 31;
lanes_32 32;
lanes_33 33;
lanes_34 34;
lanes_35 35;
Expand Down Expand Up @@ -722,6 +698,7 @@ macro_rules! test_lanes_panic {
lanes_61 61;
lanes_62 62;
lanes_63 63;
lanes_64 64;
);
}
)*
Expand Down

0 comments on commit 227a9d9

Please sign in to comment.