Skip to content

Commit 7e10037

Browse files
authored
Merge pull request #696 from clarfonthey/lint_simd
Lint SIMD code, fix generic expectation failures
2 parents 74f69d4 + 7dd278e commit 7e10037

File tree

8 files changed

+74
-16
lines changed

8 files changed

+74
-16
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- uses: actions/checkout@v3
1212
- env:
1313
TARGET: x86_64-unknown-linux-gnu
14-
run: sh ci/miri.sh
14+
run: ci/miri.sh
1515

1616
rustfmt_clippy:
1717
runs-on: ubuntu-latest
@@ -21,7 +21,8 @@ jobs:
2121
run: curl -fsSL https://github.com/tamasfe/taplo/releases/latest/download/taplo-linux-x86_64.gz | gzip -d - | install -m 755 /dev/stdin /usr/local/bin/taplo
2222
- env:
2323
TARGET: i586-unknown-linux-gnu
24-
run: sh ci/tools.sh
24+
CHANNEL: nightly
25+
run: ci/tools.sh
2526

2627
basics:
2728
runs-on: ubuntu-latest
@@ -42,7 +43,7 @@ jobs:
4243
- env:
4344
TARGET: ${{ matrix.target }}
4445
CHANNEL: ${{ matrix.channel }}
45-
run: sh ci/run.sh
46+
run: ci/run.sh
4647
strategy:
4748
matrix:
4849
os: [ubuntu-latest]

ci/miri.sh

100644100755
File mode changed.

ci/run.sh

100644100755
File mode changed.

ci/tools.sh

100644100755
Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22

33
set -ex
44

@@ -36,7 +36,68 @@ if retry rustup component add rustfmt ; then
3636
fi
3737

3838
if retry rustup component add clippy ; then
39-
cargo clippy --all --tests --features serde,rayon -- -D warnings
39+
# we want all targets that have dedicated SIMD implementations,
40+
# plus one that uses the generic implementation,
41+
# since we can't lint cfg-disabled code
42+
TARGETS=()
43+
44+
# associative array of cfgs from rustc
45+
declare -A CFG
46+
for cfg in $(rustc --print cfg); do
47+
# bash is very upset about quotes and equal signs in keys
48+
cfg="${cfg//\"/}"
49+
cfg="${cfg//=/_}"
50+
printf "\n%s\n" "$cfg" >&2
51+
CFG["$cfg"]=1
52+
done
53+
54+
HOST_IS_GENERIC=1
55+
56+
# SSE2
57+
if (( CFG[target_feature_sse2] && (CFG[target_arch_x86] || CFG[target_arch_x86_64]) )); then
58+
printf "\nHost target supports SSE2\n" >&2
59+
TARGETS+=(--target "$(rustc --print host-tuple)")
60+
HOST_IS_GENERIC=0
61+
elif retry rustup target add x86_64-unknown-linux-gnu; then
62+
printf "\nTesting x86_64-unknown-linux-gnu\n" >&2
63+
TARGETS+=(--target x86_64-unknown-linux-gnu)
64+
fi
65+
66+
# NEON
67+
if (( CFG[target_arch_aarch64] && CFG[target_feature_neon] && CFG[target_endian_little] )); then
68+
printf "\nHost target supports NEON\n" >&2
69+
TARGETS+=(--target "$(rustc --print host-tuple)")
70+
HOST_IS_GENERIC=0
71+
elif retry rustup target add aarch64-unknown-linux-gnu; then
72+
printf "\nTesting aarch64-unknown-linux-gnu\n" >&2
73+
TARGETS+=(--target aarch64-unknown-linux-gnu)
74+
fi
75+
76+
# LSX
77+
if (( CFG[target_arch_loongarch64] && CFG[target_feature_lsx] )); then
78+
printf "\nHost target supports LSX\n" >&2
79+
TARGETS+=(--target "$(rustc --print host-tuple)")
80+
HOST_IS_GENERIC=0
81+
elif retry rustup target add loongarch64-unknown-linux-gnu; then
82+
printf "\nTesting loongarch64-unknown-linux-gnu\n" >&2
83+
TARGETS+=(--target loongarch64-unknown-linux-gnu)
84+
fi
85+
86+
# Generic
87+
if (( HOST_IS_GENERIC )); then
88+
printf "\nHost target support is generic\n" >&2
89+
TARGETS+=(--target "$(rustc --print host-tuple)")
90+
elif retry rustup target add i586-unknown-linux-gnu; then
91+
printf "\nTesting i586-unknown-linux-gnu\n" >&2
92+
TARGETS+=(--target i586-unknown-linux-gnu)
93+
fi
94+
95+
cargo clippy --all --tests --features serde,rayon "${TARGETS[@]}" -- -D warnings
96+
97+
# check nightly too
98+
if rustc --version | grep --quiet nightly ; then
99+
cargo +nightly clippy --all --tests --features serde,rayon,nightly "${TARGETS[@]}" -- -D warnings
100+
fi
40101
fi
41102

42103
if command -v taplo ; then

src/control/group/generic.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub(crate) type BitMaskWord = GroupWord;
2424
pub(crate) type NonZeroBitMaskWord = NonZeroGroupWord;
2525
pub(crate) const BITMASK_STRIDE: usize = 8;
2626
// We only care about the highest bit of each tag for the mask.
27-
#[expect(clippy::cast_possible_truncation, clippy::unnecessary_cast)]
2827
const BITMASK_MASK: BitMaskWord = u64::from_ne_bytes([Tag::DELETED.0; 8]) as GroupWord;
2928
pub(crate) const BITMASK_ITER_MASK: BitMaskWord = !0;
3029

@@ -70,15 +69,13 @@ impl Group {
7069

7170
/// Loads a group of tags starting at the given address.
7271
#[inline]
73-
#[expect(clippy::cast_ptr_alignment)] // unaligned load
7472
pub(crate) unsafe fn load(ptr: *const Tag) -> Self {
7573
unsafe { Group(ptr::read_unaligned(ptr.cast())) }
7674
}
7775

7876
/// Loads a group of tags starting at the given address, which must be
7977
/// aligned to `mem::align_of::<Group>()`.
8078
#[inline]
81-
#[expect(clippy::cast_ptr_alignment)]
8279
pub(crate) unsafe fn load_aligned(ptr: *const Tag) -> Self {
8380
debug_assert_eq!(ptr.align_offset(mem::align_of::<Self>()), 0);
8481
unsafe { Group(ptr::read(ptr.cast())) }
@@ -87,7 +84,6 @@ impl Group {
8784
/// Stores the group of tags to the given address, which must be
8885
/// aligned to `mem::align_of::<Group>()`.
8986
#[inline]
90-
#[expect(clippy::cast_ptr_alignment)]
9187
pub(crate) unsafe fn store_aligned(self, ptr: *mut Tag) {
9288
debug_assert_eq!(ptr.align_offset(mem::align_of::<Self>()), 0);
9389
unsafe {

src/control/group/lsx.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ impl Group {
2727
///
2828
/// This is guaranteed to be aligned to the group size.
2929
#[inline]
30-
#[expect(clippy::items_after_statements)]
3130
pub(crate) const fn static_empty() -> &'static [Tag; Group::WIDTH] {
3231
#[repr(C)]
3332
struct AlignedTags {
@@ -43,15 +42,13 @@ impl Group {
4342

4443
/// Loads a group of tags starting at the given address.
4544
#[inline]
46-
#[expect(clippy::cast_ptr_alignment)] // unaligned load
4745
pub(crate) unsafe fn load(ptr: *const Tag) -> Self {
4846
unsafe { Group(lsx_vld::<0>(ptr.cast())) }
4947
}
5048

5149
/// Loads a group of tags starting at the given address, which must be
5250
/// aligned to `mem::align_of::<Group>()`.
5351
#[inline]
54-
#[expect(clippy::cast_ptr_alignment)]
5552
pub(crate) unsafe fn load_aligned(ptr: *const Tag) -> Self {
5653
debug_assert_eq!(ptr.align_offset(mem::align_of::<Self>()), 0);
5754
unsafe { Group(lsx_vld::<0>(ptr.cast())) }
@@ -60,7 +57,6 @@ impl Group {
6057
/// Stores the group of tags to the given address, which must be
6158
/// aligned to `mem::align_of::<Group>()`.
6259
#[inline]
63-
#[expect(clippy::cast_ptr_alignment)]
6460
pub(crate) unsafe fn store_aligned(self, ptr: *mut Tag) {
6561
debug_assert_eq!(ptr.align_offset(mem::align_of::<Self>()), 0);
6662
unsafe {

src/control/group/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// TESTING NOTE:
2+
//
3+
// Because this module uses `cfg(..)` to select an implementation, it will not
4+
// be linted without being run on targets that actually load each of these
5+
// modules. Be sure to edit `ci/tools.sh` to add in the necessary cfgs if you
6+
// change these, so that your implementation gets properly linted.
7+
18
cfg_if! {
29
// Use the SSE2 implementation if possible: it allows us to scan 16 buckets
310
// at once instead of 8. We don't bother with AVX since it would require

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@
1313
#![cfg_attr(
1414
feature = "nightly",
1515
feature(
16-
test,
1716
core_intrinsics,
1817
dropck_eyepatch,
1918
min_specialization,
2019
trivial_clone,
2120
extend_one,
2221
allocator_api,
23-
slice_ptr_get,
24-
maybe_uninit_array_assume_init,
2522
strict_provenance_lints
2623
)
2724
)]

0 commit comments

Comments
 (0)