Skip to content

Commit 7b83e03

Browse files
committed
[clippy] fix clippy issues
1 parent 104a6b3 commit 7b83e03

16 files changed

+85
-64
lines changed

.appveyor.yml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ install:
1515
- if NOT "%TARGET%" == "x86_64-pc-windows-msvc" rustup target add %TARGET%
1616
- rustc -vV
1717
- cargo -vV
18-
- cargo install clippy
1918

2019
build: false
2120

.travis.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@ matrix:
1717
- install: true
1818
script: ci/dox.sh
1919
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
20+
script: |
21+
cargo install clippy
22+
cargo clippy --all -- -D clippy-pedantic
2023
allow_failures:
2124
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
2225
install:
2326
- if [ "$NO_ADD" == "" ]; then rustup target add $TARGET; fi
2427

2528
script:
2629
- cargo generate-lockfile
27-
- if [[ "${CLIPPY}" == "" ]]; then ci/run-docker.sh $TARGET; fi
28-
- |
29-
if [[ "${CLIPPY}" == "On" ]]; then
30-
cargo install clippy
31-
cargo clippy --all -- -D clippy-pedantic
32-
fi
30+
- ci/run-docker.sh $TARGET
3331

3432
notifications:
3533
email:

ci/run.sh

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ set -ex
44

55
cargo test --target $TARGET
66
cargo test --release --target $TARGET
7-
cargo clippy --all -- -D clippy-pedantic

examples/play.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#![feature(target_feature)]
22

3+
#![cfg_attr(feature = "cargo-clippy",
4+
allow(similar_names, missing_docs_in_private_items, cast_sign_loss,
5+
cast_possible_truncation, cast_possible_wrap, option_unwrap_used,
6+
use_debug, print_stdout,
7+
)
8+
)]
9+
310
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
411
mod example {
512

examples/types.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#![feature(target_feature)]
22

3+
#![cfg_attr(feature = "cargo-clippy",
4+
allow(missing_docs_in_private_items, result_unwrap_used,
5+
option_unwrap_used, print_stdout, use_debug
6+
)
7+
)]
8+
39
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
410
mod example {
511
extern crate stdsimd;

examples/wat.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#![feature(target_feature)]
22

3+
#![cfg_attr(feature = "cargo-clippy",
4+
allow(missing_docs_in_private_items, result_unwrap_used,
5+
option_unwrap_used, print_stdout, use_debug
6+
)
7+
)]
8+
39
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
410
mod example {
511
extern crate stdsimd;

src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! others at:
2727
//!
2828
//! * [i686](https://rust-lang-nursery.github.io/stdsimd/i686/stdsimd/)
29-
//! * [x86_64](https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/)
29+
//! * [`x86_64`](https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/)
3030
//! * [arm](https://rust-lang-nursery.github.io/stdsimd/arm/stdsimd/)
3131
//! * [aarch64](https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/)
3232
//!
@@ -117,6 +117,13 @@
117117
)]
118118
#![cfg_attr(test, feature(proc_macro, test))]
119119

120+
#![cfg_attr(feature = "cargo-clippy",
121+
allow(inline_always, too_many_arguments, missing_docs_in_private_items,
122+
cast_sign_loss, cast_lossless, cast_possible_wrap,
123+
cast_possible_truncation, cast_precision_loss, shadow_reuse,
124+
cyclomatic_complexity, similar_names
125+
))]
126+
120127
#[cfg(test)]
121128
extern crate stdsimd_test;
122129

src/x86/avx.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub unsafe fn _mm256_shuffle_pd(a: f64x4, b: f64x4, imm8: i32) -> f64x4 {
106106
}
107107
}
108108
}
109-
match (imm8 >> 0) & 0x1 {
109+
match imm8 & 0x1 {
110110
0 => shuffle1!(0),
111111
_ => shuffle1!(1),
112112
}
@@ -806,8 +806,8 @@ pub unsafe fn _mm_permutevar_ps(a: f32x4, b: i32x4) -> f32x4 {
806806
#[target_feature = "+avx"]
807807
#[cfg_attr(test, assert_instr(vpermilps, imm8 = 9))]
808808
pub unsafe fn _mm256_permute_ps(a: f32x8, imm8: i32) -> f32x8 {
809-
let imm8 = (imm8 & 0xFF) as u8;
810809
const fn add4(x: u32) -> u32 { x + 4 }
810+
let imm8 = (imm8 & 0xFF) as u8;
811811
macro_rules! shuffle4 {
812812
($a:expr, $b:expr, $c:expr, $d:expr) => {
813813
simd_shuffle8(a, _mm256_undefined_ps(), [
@@ -845,7 +845,7 @@ pub unsafe fn _mm256_permute_ps(a: f32x8, imm8: i32) -> f32x8 {
845845
}
846846
}
847847
}
848-
match (imm8 >> 0) & 0b11 {
848+
match imm8 & 0b11 {
849849
0b00 => shuffle1!(0),
850850
0b01 => shuffle1!(1),
851851
0b10 => shuffle1!(2),
@@ -899,7 +899,7 @@ pub unsafe fn _mm_permute_ps(a: f32x4, imm8: i32) -> f32x4 {
899899
}
900900
}
901901
}
902-
match (imm8 >> 0) & 0b11 {
902+
match imm8 & 0b11 {
903903
0b00 => shuffle1!(0),
904904
0b01 => shuffle1!(1),
905905
0b10 => shuffle1!(2),
@@ -959,7 +959,7 @@ pub unsafe fn _mm256_permute_pd(a: f64x4, imm8: i32) -> f64x4 {
959959
}
960960
}
961961
}
962-
match (imm8 >> 0) & 0x1 {
962+
match imm8 & 0x1 {
963963
0 => shuffle1!(0),
964964
_ => shuffle1!(1),
965965
}
@@ -987,7 +987,7 @@ pub unsafe fn _mm_permute_pd(a: f64x2, imm8: i32) -> f64x2 {
987987
}
988988
}
989989
}
990-
match (imm8 >> 0) & 0x1 {
990+
match imm8 & 0x1 {
991991
0 => shuffle1!(0),
992992
_ => shuffle1!(1),
993993
}

src/x86/avx2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub unsafe fn _mm256_adds_epu16(a: u16x16, b: u16x16) -> u16x16 {
100100
#[target_feature = "+avx2"]
101101
#[cfg_attr(test, assert_instr(vpalignr, n = 15))]
102102
pub unsafe fn _mm256_alignr_epi8(a: i8x32, b: i8x32, n: i32) -> i8x32 {
103+
const fn add(a: u32, b: u32) -> u32 { a + b }
103104
let n = n as u32;
104105
// If palignr is shifting the pair of vectors more than the size of two
105106
// lanes, emit zero.
@@ -114,7 +115,6 @@ pub unsafe fn _mm256_alignr_epi8(a: i8x32, b: i8x32, n: i32) -> i8x32 {
114115
(a, b, n)
115116
};
116117

117-
const fn add(a: u32, b: u32) -> u32 { a + b }
118118
macro_rules! shuffle {
119119
($shift:expr) => {
120120
simd_shuffle32(b, a, [

src/x86/bmi.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use stdsimd_test::assert_instr;
1616
#[target_feature = "+bmi"]
1717
#[cfg_attr(test, assert_instr(bextr))]
1818
pub unsafe fn _bextr_u32(a: u32, start: u32, len: u32) -> u32 {
19-
_bextr2_u32(a, (start & 0xffu32) | ((len & 0xffu32) << 8u32))
19+
_bextr2_u32(a, (start & 0xff_u32) | ((len & 0xff_u32) << 8_u32))
2020
}
2121

2222
/// Extracts bits in range [`start`, `start` + `length`) from `a` into
@@ -26,7 +26,7 @@ pub unsafe fn _bextr_u32(a: u32, start: u32, len: u32) -> u32 {
2626
#[cfg_attr(test, assert_instr(bextr))]
2727
#[cfg(not(target_arch = "x86"))]
2828
pub unsafe fn _bextr_u64(a: u64, start: u64, len: u64) -> u64 {
29-
_bextr2_u64(a, (start & 0xffu64) | ((len & 0xffu64) << 8u64))
29+
_bextr2_u64(a, (start & 0xff_u64) | ((len & 0xff_u64) << 8_u64))
3030
}
3131

3232
/// Extracts bits of `a` specified by `control` into
@@ -92,7 +92,7 @@ pub unsafe fn _blsi_u64(x: u64) -> u64 {
9292
#[target_feature = "+bmi"]
9393
#[cfg_attr(test, assert_instr(blsmsk))]
9494
pub unsafe fn _blsmsk_u32(x: u32) -> u32 {
95-
x ^ (x.wrapping_sub(1u32))
95+
x ^ (x.wrapping_sub(1_u32))
9696
}
9797

9898
/// Get mask up to lowest set bit.
@@ -101,7 +101,7 @@ pub unsafe fn _blsmsk_u32(x: u32) -> u32 {
101101
#[cfg_attr(test, assert_instr(blsmsk))]
102102
#[cfg(not(target_arch = "x86"))] // generates lots of instructions
103103
pub unsafe fn _blsmsk_u64(x: u64) -> u64 {
104-
x ^ (x.wrapping_sub(1u64))
104+
x ^ (x.wrapping_sub(1_u64))
105105
}
106106

107107
/// Resets the lowest set bit of `x`.

src/x86/runtime.rs

+19-22
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,18 @@ pub enum __Feature {
8585
__NonExhaustive
8686
}
8787

88+
/// Sets the `bit`-th bit of `x`.
8889
fn set_bit(x: usize, bit: u32) -> usize {
8990
debug_assert!(32 > bit);
9091
x | 1 << bit
9192
}
9293

94+
/// Tests the `bit`-th bit of `x`.
9395
fn test_bit(x: usize, bit: u32) -> bool {
9496
debug_assert!(32 > bit);
9597
x & (1 << bit) != 0
9698
}
9799

98-
fn inv_test_bit(v: usize, idx: u32) -> bool {
99-
debug_assert!(32 > idx);
100-
((v >> idx) & 1) != 0
101-
}
102-
103100
/// Run-time feature detection on x86 works by using the CPUID instruction.
104101
///
105102
/// The [CPUID Wikipedia page](https://en.wikipedia.org/wiki/CPUID) contains all
@@ -122,37 +119,37 @@ fn detect_features() -> usize {
122119
/// This gives us most of the CPU features in ECX and EDX (see below),
123120
asm!("cpuid"
124121
: "={ecx}"(ecx), "={edx}"(edx)
125-
: "{eax}"(0x00000001u32), "{ecx}"(0 as u32)
122+
: "{eax}"(0x0000_0001_u32), "{ecx}"(0 as u32)
126123
: :);
127124

128125
/// 2. EAX=7, ECX=0: Queries "Extended Features"
129126
/// This gives us information about bmi,bmi2, and avx2 support (see below).
130127
asm!("cpuid"
131128
: "={ebx}"(ebx)
132-
: "{eax}"(0x00000007u32), "{ecx}"(0 as u32)
129+
: "{eax}"(0x0000_0007_u32), "{ecx}"(0 as u32)
133130
: :);
134131
}
135132

136133
let mut value: usize = 0;
137134

138135
// CPUID call with EAX=7, ECX=0 => Extended Features in EBX and ECX (unneeded):
139-
if inv_test_bit(ebx, 3) { value = set_bit(value, __Feature::bmi as u32); }
140-
if inv_test_bit(ebx, 5) { value = set_bit(value, __Feature::avx2 as u32); }
141-
if inv_test_bit(ebx, 8) { value = set_bit(value, __Feature::bmi2 as u32); }
136+
if test_bit(ebx, 3) { value = set_bit(value, __Feature::bmi as u32); }
137+
if test_bit(ebx, 5) { value = set_bit(value, __Feature::avx2 as u32); }
138+
if test_bit(ebx, 8) { value = set_bit(value, __Feature::bmi2 as u32); }
142139

143140
// CPUID call with EAX=1 => feature bits in ECX and EDX:
144-
if inv_test_bit(ecx, 0) { value = set_bit(value, __Feature::sse3 as u32); }
145-
if inv_test_bit(ecx, 5) { value = set_bit(value, __Feature::abm as u32); }
146-
if inv_test_bit(ecx, 9) { value = set_bit(value, __Feature::ssse3 as u32); }
147-
if inv_test_bit(ecx, 12) { value = set_bit(value, __Feature::fma as u32); }
148-
if inv_test_bit(ecx, 19) { value = set_bit(value, __Feature::sse4_1 as u32); }
149-
if inv_test_bit(ecx, 20) { value = set_bit(value, __Feature::sse4_2 as u32); }
150-
if inv_test_bit(ecx, 21) { value = set_bit(value, __Feature::tbm as u32); }
151-
if inv_test_bit(ecx, 23) { value = set_bit(value, __Feature::popcnt as u32); }
152-
if inv_test_bit(ecx, 28) { value = set_bit(value, __Feature::avx as u32); }
153-
154-
if inv_test_bit(edx, 25) { value = set_bit(value, __Feature::sse as u32); }
155-
if inv_test_bit(edx, 26) { value = set_bit(value, __Feature::sse2 as u32); }
141+
if test_bit(ecx, 0) { value = set_bit(value, __Feature::sse3 as u32); }
142+
if test_bit(ecx, 5) { value = set_bit(value, __Feature::abm as u32); }
143+
if test_bit(ecx, 9) { value = set_bit(value, __Feature::ssse3 as u32); }
144+
if test_bit(ecx, 12) { value = set_bit(value, __Feature::fma as u32); }
145+
if test_bit(ecx, 19) { value = set_bit(value, __Feature::sse4_1 as u32); }
146+
if test_bit(ecx, 20) { value = set_bit(value, __Feature::sse4_2 as u32); }
147+
if test_bit(ecx, 21) { value = set_bit(value, __Feature::tbm as u32); }
148+
if test_bit(ecx, 23) { value = set_bit(value, __Feature::popcnt as u32); }
149+
if test_bit(ecx, 28) { value = set_bit(value, __Feature::avx as u32); }
150+
151+
if test_bit(edx, 25) { value = set_bit(value, __Feature::sse as u32); }
152+
if test_bit(edx, 26) { value = set_bit(value, __Feature::sse2 as u32); }
156153

157154
value
158155
}

src/x86/sse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ pub unsafe fn _mm_sfence() {
561561
#[target_feature = "+sse"]
562562
#[cfg_attr(test, assert_instr(stmxcsr))]
563563
pub unsafe fn _mm_getcsr() -> u32 {
564-
let mut result = 0i32;
564+
let mut result = 0_i32;
565565
stmxcsr((&mut result) as *mut _ as *mut i8);
566566
result as u32
567567
}

src/x86/sse2.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ pub unsafe fn _mm_subs_epu16(a: u16x8, b: u16x8) -> u16x8 {
316316
#[target_feature = "+sse2"]
317317
#[cfg_attr(test, assert_instr(pslldq, imm8 = 1))]
318318
pub unsafe fn _mm_slli_si128(a: __m128i, imm8: i32) -> __m128i {
319-
let (zero, imm8) = (__m128i::splat(0), imm8 as u32);
320319
const fn sub(a: u32, b: u32) -> u32 { a - b }
320+
let (zero, imm8) = (__m128i::splat(0), imm8 as u32);
321321
macro_rules! shuffle {
322322
($shift:expr) => {
323323
simd_shuffle16::<__m128i, __m128i>(zero, a, [
@@ -453,8 +453,8 @@ pub unsafe fn _mm_sra_epi32(a: i32x4, count: i32x4) -> i32x4 {
453453
#[target_feature = "+sse2"]
454454
#[cfg_attr(test, assert_instr(psrldq, imm8 = 1))]
455455
pub unsafe fn _mm_srli_si128(a: __m128i, imm8: i32) -> __m128i {
456-
let (zero, imm8) = (__m128i::splat(0), imm8 as u32);
457456
const fn add(a: u32, b: u32) -> u32 { a + b }
457+
let (zero, imm8) = (__m128i::splat(0), imm8 as u32);
458458
macro_rules! shuffle {
459459
($shift:expr) => {
460460
simd_shuffle16::<__m128i, __m128i>(a, zero, [
@@ -1074,10 +1074,9 @@ pub unsafe fn _mm_shuffle_epi32(a: i32x4, imm8: i32) -> i32x4 {
10741074
#[target_feature = "+sse2"]
10751075
#[cfg_attr(test, assert_instr(pshufhw, imm8 = 9))]
10761076
pub unsafe fn _mm_shufflehi_epi16(a: i16x8, imm8: i32) -> i16x8 {
1077+
const fn add4(x: u32) -> u32 { x + 4 }
10771078
// See _mm_shuffle_epi32.
10781079
let imm8 = (imm8 & 0xFF) as u8;
1079-
const fn add4(x: u32) -> u32 { x + 4 }
1080-
10811080
macro_rules! shuffle_done {
10821081
($x01:expr, $x23:expr, $x45:expr, $x67:expr) => {
10831082
simd_shuffle8(a, a, [

src/x86/sse42.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,41 @@ use v128::*;
55
use x86::__m128i;
66

77
/// String contains unsigned 8-bit characters *(Default)*
8-
pub const _SIDD_UBYTE_OPS: i8 = 0b00000000;
8+
pub const _SIDD_UBYTE_OPS: i8 = 0b0000_0000;
99
/// String contains unsigned 16-bit characters
10-
pub const _SIDD_UWORD_OPS: i8 = 0b00000001;
10+
pub const _SIDD_UWORD_OPS: i8 = 0b0000_0001;
1111
/// String contains signed 8-bit characters
12-
pub const _SIDD_SBYTE_OPS: i8 = 0b00000010;
12+
pub const _SIDD_SBYTE_OPS: i8 = 0b0000_0010;
1313
/// String contains unsigned 16-bit characters
14-
pub const _SIDD_SWORD_OPS: i8 = 0b00000011;
14+
pub const _SIDD_SWORD_OPS: i8 = 0b0000_0011;
1515

1616
/// For each character in `a`, find if it is in `b` *(Default)*
17-
pub const _SIDD_CMP_EQUAL_ANY: i8 = 0b00000000;
17+
pub const _SIDD_CMP_EQUAL_ANY: i8 = 0b0000_0000;
1818
/// For each character in `a`, determine if `b[0] <= c <= b[1] or b[1] <= c <= b[2]...`
19-
pub const _SIDD_CMP_RANGES: i8 = 0b00000100;
19+
pub const _SIDD_CMP_RANGES: i8 = 0b0000_0100;
2020
/// The strings defined by `a` and `b` are equal
21-
pub const _SIDD_CMP_EQUAL_EACH: i8 = 0b00001000;
21+
pub const _SIDD_CMP_EQUAL_EACH: i8 = 0b0000_1000;
2222
/// Search for the defined substring in the target
23-
pub const _SIDD_CMP_EQUAL_ORDERED: i8 = 0b00001100;
23+
pub const _SIDD_CMP_EQUAL_ORDERED: i8 = 0b0000_1100;
2424

2525
/// Do not negate results *(Default)*
26-
pub const _SIDD_POSITIVE_POLARITY: i8 = 0b00000000;
26+
pub const _SIDD_POSITIVE_POLARITY: i8 = 0b0000_0000;
2727
/// Negate results
28-
pub const _SIDD_NEGATIVE_POLARITY: i8 = 0b00010000;
28+
pub const _SIDD_NEGATIVE_POLARITY: i8 = 0b0001_0000;
2929
/// Do not negate results before the end of the string
30-
pub const _SIDD_MASKED_POSITIVE_POLARITY: i8 = 0b00100000;
30+
pub const _SIDD_MASKED_POSITIVE_POLARITY: i8 = 0b0010_0000;
3131
/// Negate results only before the end of the string
32-
pub const _SIDD_MASKED_NEGATIVE_POLARITY: i8 = 0b00110000;
32+
pub const _SIDD_MASKED_NEGATIVE_POLARITY: i8 = 0b0011_0000;
3333

3434
/// **Index only**: return the least significant bit *(Default)*
35-
pub const _SIDD_LEAST_SIGNIFICANT: i8 = 0b00000000;
35+
pub const _SIDD_LEAST_SIGNIFICANT: i8 = 0b0000_0000;
3636
/// **Index only**: return the most significant bit
37-
pub const _SIDD_MOST_SIGNIFICANT: i8 = 0b01000000;
37+
pub const _SIDD_MOST_SIGNIFICANT: i8 = 0b0100_0000;
3838

3939
/// **Mask only**: return the bit mask
40-
pub const _SIDD_BIT_MASK: i8 = 0b00000000;
40+
pub const _SIDD_BIT_MASK: i8 = 0b0000_0000;
4141
/// **Mask only**: return the byte mask
42-
pub const _SIDD_UNIT_MASK: i8 = 0b01000000;
42+
pub const _SIDD_UNIT_MASK: i8 = 0b0100_0000;
4343

4444
/// Compare packed strings with implicit lengths in `a` and `b` using the
4545
/// control in `imm8`, and return the generated mask.

src/x86/ssse3.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub unsafe fn _mm_shuffle_epi8(a: u8x16, b: u8x16) -> u8x16 {
6868
#[target_feature = "+ssse3"]
6969
#[cfg_attr(test, assert_instr(palignr, n = 15))]
7070
pub unsafe fn _mm_alignr_epi8(a: i8x16, b: i8x16, n: i32) -> i8x16 {
71+
const fn add(a: u32, b: u32) -> u32 { a + b }
72+
7173
let n = n as u32;
7274
// If palignr is shifting the pair of vectors more than the size of two
7375
// lanes, emit zero.
@@ -82,7 +84,6 @@ pub unsafe fn _mm_alignr_epi8(a: i8x16, b: i8x16, n: i32) -> i8x16 {
8284
(a, b, n)
8385
};
8486

85-
const fn add(a: u32, b: u32) -> u32 { a + b }
8687
macro_rules! shuffle {
8788
($shift:expr) => {
8889
simd_shuffle16(b, a, [

0 commit comments

Comments
 (0)