Skip to content

Commit 227a9d9

Browse files
committed
Fix layout of non-power-of-two length vectors
1 parent c79585c commit 227a9d9

File tree

8 files changed

+52
-75
lines changed

8 files changed

+52
-75
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -245,34 +245,6 @@ jobs:
245245
- name: Test (release)
246246
run: cross test --verbose --target=${{ matrix.target }} --release
247247

248-
features:
249-
name: "Test cargo features (${{ matrix.simd }} × ${{ matrix.features }})"
250-
runs-on: ubuntu-latest
251-
strategy:
252-
fail-fast: false
253-
matrix:
254-
simd:
255-
- ""
256-
- "avx512"
257-
features:
258-
- ""
259-
- "--features std"
260-
- "--features all_lane_counts"
261-
- "--all-features"
262-
263-
steps:
264-
- uses: actions/checkout@v2
265-
- name: Detect AVX512
266-
run: echo "CPU_FEATURE=$(lscpu | grep -o avx512[a-z]* | sed s/avx/+avx/ | tr '\n' ',' )" >> $GITHUB_ENV
267-
- name: Check build
268-
if: ${{ matrix.simd == '' }}
269-
run: RUSTFLAGS="-Dwarnings" cargo test --all-targets --no-default-features ${{ matrix.features }}
270-
- name: Check AVX
271-
if: ${{ matrix.simd == 'avx512' && contains(env.CPU_FEATURE, 'avx512') }}
272-
run: |
273-
echo "Found AVX features: $CPU_FEATURE"
274-
RUSTFLAGS="-Dwarnings -Ctarget-feature=$CPU_FEATURE" cargo test --all-targets --no-default-features ${{ matrix.features }}
275-
276248
miri:
277249
runs-on: ubuntu-latest
278250
steps:

crates/core_simd/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ categories = ["hardware-support", "no-std"]
99
license = "MIT OR Apache-2.0"
1010

1111
[features]
12-
default = ["as_crate"]
12+
default = ["as_crate", "std"]
1313
as_crate = []
1414
std = []
15-
all_lane_counts = []
1615

1716
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
1817
wasm-bindgen = "0.2"

crates/core_simd/src/lane_count.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ macro_rules! supported_lane_count {
3333
};
3434
}
3535

36-
supported_lane_count!(1, 2, 4, 8, 16, 32, 64);
37-
#[cfg(feature = "all_lane_counts")]
3836
supported_lane_count!(
39-
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,
40-
31, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
41-
56, 57, 58, 59, 60, 61, 62, 63
37+
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,
38+
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
39+
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
4240
);

crates/core_simd/src/vector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ use crate::simd::{
9999
// directly constructing an instance of the type (i.e. `let vector = Simd(array)`) should be
100100
// avoided, as it will likely become illegal on `#[repr(simd)]` structs in the future. It also
101101
// causes rustc to emit illegal LLVM IR in some cases.
102-
#[repr(simd)]
102+
#[repr(simd, packed)]
103103
pub struct Simd<T, const N: usize>([T; N])
104104
where
105105
LaneCount<N>: SupportedLaneCount,

crates/core_simd/tests/layout.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![feature(portable_simd)]
2+
3+
macro_rules! layout_tests {
4+
{ $($mod:ident, $ty:ty,)* } => {
5+
$(
6+
mod $mod {
7+
test_helpers::test_lanes! {
8+
fn no_padding<const LANES: usize>() {
9+
assert_eq!(
10+
core::mem::size_of::<core_simd::simd::Simd::<$ty, LANES>>(),
11+
core::mem::size_of::<[$ty; LANES]>(),
12+
);
13+
}
14+
}
15+
}
16+
)*
17+
}
18+
}
19+
20+
layout_tests! {
21+
i8, i8,
22+
i16, i16,
23+
i32, i32,
24+
i64, i64,
25+
isize, isize,
26+
u8, u8,
27+
u16, u16,
28+
u32, u32,
29+
u64, u64,
30+
usize, usize,
31+
f32, f32,
32+
f64, f64,
33+
mut_ptr, *mut (),
34+
const_ptr, *const (),
35+
}

crates/core_simd/tests/masks.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ macro_rules! test_mask_api {
9999
assert_eq!(Mask::<$type, 2>::from_bitmask(bitmask), mask);
100100
}
101101

102-
#[cfg(feature = "all_lane_counts")]
103102
#[test]
104103
fn roundtrip_bitmask_conversion_odd() {
105104
let values = [

crates/test_helpers/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,3 @@ publish = false
66

77
[dependencies]
88
proptest = { version = "0.10", default-features = false, features = ["alloc"] }
9-
10-
[features]
11-
all_lane_counts = []

crates/test_helpers/src/lib.rs

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -539,39 +539,25 @@ macro_rules! test_lanes {
539539
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)];
540540
lanes_1 1;
541541
lanes_2 2;
542+
lanes_3 3; // test one non-power-of-2 length on miri
542543
);
543544

544545
#[cfg(not(miri))] // Miri intrinsic implementations are uniform and larger tests are sloooow
545546
$crate::test_lanes_helper!(
546547
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)];
547548
lanes_4 4;
548-
lanes_8 8;
549-
lanes_16 16;
550-
lanes_32 32;
551-
lanes_64 64;
552-
);
553-
554-
#[cfg(feature = "all_lane_counts")]
555-
$crate::test_lanes_helper!(
556-
// test one non-power-of-2 length on miri
557-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)];
558-
lanes_3 3;
559-
);
560-
561-
#[cfg(feature = "all_lane_counts")]
562-
#[cfg(not(miri))] // Miri intrinsic implementations are uniform and larger tests are sloooow
563-
$crate::test_lanes_helper!(
564-
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)];
565549
lanes_5 5;
566550
lanes_6 6;
567551
lanes_7 7;
552+
lanes_8 8;
568553
lanes_9 9;
569554
lanes_10 10;
570555
lanes_11 11;
571556
lanes_12 12;
572557
lanes_13 13;
573558
lanes_14 14;
574559
lanes_15 15;
560+
lanes_16 16;
575561
lanes_17 17;
576562
lanes_18 18;
577563
lanes_19 19;
@@ -587,6 +573,7 @@ macro_rules! test_lanes {
587573
lanes_29 29;
588574
lanes_30 30;
589575
lanes_31 31;
576+
lanes_32 32;
590577
lanes_33 33;
591578
lanes_34 34;
592579
lanes_35 35;
@@ -618,6 +605,7 @@ macro_rules! test_lanes {
618605
lanes_61 61;
619606
lanes_62 62;
620607
lanes_63 63;
608+
lanes_64 64;
621609
);
622610
}
623611
)*
@@ -639,43 +627,30 @@ macro_rules! test_lanes_panic {
639627
core_simd::simd::LaneCount<$lanes>: core_simd::simd::SupportedLaneCount,
640628
$body
641629

630+
// test some odd and even non-power-of-2 lengths on miri
642631
$crate::test_lanes_helper!(
643632
#[should_panic];
644633
lanes_1 1;
645634
lanes_2 2;
646-
lanes_4 4;
647-
);
648-
649-
#[cfg(not(miri))] // Miri intrinsic implementations are uniform and larger tests are sloooow
650-
$crate::test_lanes_helper!(
651-
#[should_panic];
652-
lanes_8 8;
653-
lanes_16 16;
654-
lanes_32 32;
655-
lanes_64 64;
656-
);
657-
658-
#[cfg(feature = "all_lane_counts")]
659-
$crate::test_lanes_helper!(
660-
// test some odd and even non-power-of-2 lengths on miri
661-
#[should_panic];
662635
lanes_3 3;
636+
lanes_4 4;
663637
lanes_5 5;
664-
lanes_6 6;
665638
);
666639

667-
#[cfg(feature = "all_lane_counts")]
668640
#[cfg(not(miri))] // Miri intrinsic implementations are uniform and larger tests are sloooow
669641
$crate::test_lanes_helper!(
670642
#[should_panic];
643+
lanes_6 6;
671644
lanes_7 7;
645+
lanes_8 8;
672646
lanes_9 9;
673647
lanes_10 10;
674648
lanes_11 11;
675649
lanes_12 12;
676650
lanes_13 13;
677651
lanes_14 14;
678652
lanes_15 15;
653+
lanes_16 16;
679654
lanes_17 17;
680655
lanes_18 18;
681656
lanes_19 19;
@@ -691,6 +666,7 @@ macro_rules! test_lanes_panic {
691666
lanes_29 29;
692667
lanes_30 30;
693668
lanes_31 31;
669+
lanes_32 32;
694670
lanes_33 33;
695671
lanes_34 34;
696672
lanes_35 35;
@@ -722,6 +698,7 @@ macro_rules! test_lanes_panic {
722698
lanes_61 61;
723699
lanes_62 62;
724700
lanes_63 63;
701+
lanes_64 64;
725702
);
726703
}
727704
)*

0 commit comments

Comments
 (0)