Skip to content

Commit 7b7822f

Browse files
committed
[clippy] fix clippy issues
1 parent 5fc94d1 commit 7b7822f

File tree

12 files changed

+84
-38
lines changed

12 files changed

+84
-38
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

examples/play.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#![cfg_attr(feature = "strict", deny(warnings))]
22
#![feature(target_feature)]
33

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

examples/types.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#![cfg_attr(feature = "strict", deny(warnings))]
22
#![feature(target_feature)]
33

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

examples/wat.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#![cfg_attr(feature = "strict", deny(warnings))]
22
#![feature(target_feature)]
33

4+
#![cfg_attr(feature = "cargo-clippy",
5+
allow(missing_docs_in_private_items, result_unwrap_used,
6+
option_unwrap_used, print_stdout, use_debug
7+
)
8+
)]
9+
410
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
511
mod example {
612
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
//!
@@ -123,6 +123,13 @@
123123
const_atomic_usize_new, stmt_expr_attributes)]
124124
#![cfg_attr(test, feature(proc_macro, test))]
125125

126+
#![cfg_attr(feature = "cargo-clippy",
127+
allow(inline_always, too_many_arguments, missing_docs_in_private_items,
128+
cast_sign_loss, cast_lossless, cast_possible_wrap,
129+
cast_possible_truncation, cast_precision_loss, shadow_reuse,
130+
cyclomatic_complexity, similar_names
131+
))]
132+
126133
#[cfg(test)]
127134
extern crate stdsimd_test;
128135

src/x86/avx.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub unsafe fn _mm256_shuffle_pd(a: f64x4, b: f64x4, imm8: i32) -> f64x4 {
113113
}
114114
}
115115
}
116-
match (imm8 >> 0) & 0x1 {
116+
match imm8 & 0x1 {
117117
0 => shuffle1!(0),
118118
_ => shuffle1!(1),
119119
}
@@ -860,7 +860,7 @@ pub unsafe fn _mm256_permute_ps(a: f32x8, imm8: i32) -> f32x8 {
860860
}
861861
}
862862
}
863-
match (imm8 >> 0) & 0b11 {
863+
match imm8 & 0b11 {
864864
0b00 => shuffle1!(0),
865865
0b01 => shuffle1!(1),
866866
0b10 => shuffle1!(2),
@@ -914,7 +914,7 @@ pub unsafe fn _mm_permute_ps(a: f32x4, imm8: i32) -> f32x4 {
914914
}
915915
}
916916
}
917-
match (imm8 >> 0) & 0b11 {
917+
match imm8 & 0b11 {
918918
0b00 => shuffle1!(0),
919919
0b01 => shuffle1!(1),
920920
0b10 => shuffle1!(2),
@@ -974,7 +974,7 @@ pub unsafe fn _mm256_permute_pd(a: f64x4, imm8: i32) -> f64x4 {
974974
}
975975
}
976976
}
977-
match (imm8 >> 0) & 0x1 {
977+
match imm8 & 0x1 {
978978
0 => shuffle1!(0),
979979
_ => shuffle1!(1),
980980
}
@@ -1002,7 +1002,7 @@ pub unsafe fn _mm_permute_pd(a: f64x2, imm8: i32) -> f64x2 {
10021002
}
10031003
}
10041004
}
1005-
match (imm8 >> 0) & 0x1 {
1005+
match imm8 & 0x1 {
10061006
0 => shuffle1!(0),
10071007
_ => shuffle1!(1),
10081008
}

src/x86/bmi.rs

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

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

3737
/// Extracts bits of `a` specified by `control` into
@@ -97,7 +97,7 @@ pub unsafe fn _blsi_u64(x: u64) -> u64 {
9797
#[target_feature = "+bmi"]
9898
#[cfg_attr(test, assert_instr(blsmsk))]
9999
pub unsafe fn _blsmsk_u32(x: u32) -> u32 {
100-
x ^ (x.wrapping_sub(1u32))
100+
x ^ (x.wrapping_sub(1_u32))
101101
}
102102

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

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

src/x86/runtime.rs

+25-7
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,18 @@ pub enum __Feature {
131131
#[doc(hidden)] __NonExhaustive,
132132
}
133133

134+
/// Sets the `bit`-th bit of `x`.
134135
fn set_bit(x: usize, bit: u32) -> usize {
135136
debug_assert!(32 > bit);
136137
x | 1 << bit
137138
}
138139

140+
/// Tests the `bit`-th bit of `x`.
139141
fn test_bit(x: usize, bit: u32) -> bool {
140142
debug_assert!(32 > bit);
141143
x & (1 << bit) != 0
142144
}
143145

144-
fn inv_test_bit(v: usize, idx: u32) -> bool {
145-
debug_assert!(32 > idx);
146-
((v >> idx) & 1) != 0
147-
}
148-
149146
/// Run-time feature detection on x86 works by using the CPUID instruction.
150147
///
151148
/// The [CPUID Wikipedia page][wiki_cpuid] contains
@@ -174,20 +171,21 @@ fn detect_features() -> usize {
174171
/// below),
175172
asm!("cpuid"
176173
: "={ecx}"(ecx), "={edx}"(edx)
177-
: "{eax}"(0x00000001u32), "{ecx}"(0 as u32)
174+
: "{eax}"(0x0000_0001_u32), "{ecx}"(0 as u32)
178175
: :);
179176

180177
/// 2. EAX=7, ECX=0: Queries "Extended Features"
181178
/// This gives us information about bmi,bmi2, and avx2 support
182179
/// (see below).
183180
asm!("cpuid"
184181
: "={ebx}"(ebx)
185-
: "{eax}"(0x00000007u32), "{ecx}"(0 as u32)
182+
: "{eax}"(0x0000_0007_u32), "{ecx}"(0 as u32)
186183
: :);
187184
}
188185

189186
let mut value: usize = 0;
190187

188+
<<<<<<< HEAD
191189
// CPUID call with EAX=7, ECX=0 => Extended Features in EBX and ECX
192190
// (the result in ECX is not currently needed):
193191
if inv_test_bit(ebx, 3) {
@@ -235,6 +233,26 @@ fn detect_features() -> usize {
235233
if inv_test_bit(edx, 26) {
236234
value = set_bit(value, __Feature::sse2 as u32);
237235
}
236+
=======
237+
// CPUID call with EAX=7, ECX=0 => Extended Features in EBX and ECX (unneeded):
238+
if test_bit(ebx, 3) { value = set_bit(value, __Feature::bmi as u32); }
239+
if test_bit(ebx, 5) { value = set_bit(value, __Feature::avx2 as u32); }
240+
if test_bit(ebx, 8) { value = set_bit(value, __Feature::bmi2 as u32); }
241+
242+
// CPUID call with EAX=1 => feature bits in ECX and EDX:
243+
if test_bit(ecx, 0) { value = set_bit(value, __Feature::sse3 as u32); }
244+
if test_bit(ecx, 5) { value = set_bit(value, __Feature::abm as u32); }
245+
if test_bit(ecx, 9) { value = set_bit(value, __Feature::ssse3 as u32); }
246+
if test_bit(ecx, 12) { value = set_bit(value, __Feature::fma as u32); }
247+
if test_bit(ecx, 19) { value = set_bit(value, __Feature::sse4_1 as u32); }
248+
if test_bit(ecx, 20) { value = set_bit(value, __Feature::sse4_2 as u32); }
249+
if test_bit(ecx, 21) { value = set_bit(value, __Feature::tbm as u32); }
250+
if test_bit(ecx, 23) { value = set_bit(value, __Feature::popcnt as u32); }
251+
if test_bit(ecx, 28) { value = set_bit(value, __Feature::avx as u32); }
252+
253+
if test_bit(edx, 25) { value = set_bit(value, __Feature::sse as u32); }
254+
if test_bit(edx, 26) { value = set_bit(value, __Feature::sse2 as u32); }
255+
>>>>>>> [clippy] fix clippy issues
238256

239257
value
240258
}

src/x86/sse2.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,6 @@ pub unsafe fn _mm_shufflehi_epi16(a: i16x8, imm8: i32) -> i16x8 {
11051105
const fn add4(x: u32) -> u32 {
11061106
x + 4
11071107
}
1108-
11091108
macro_rules! shuffle_done {
11101109
($x01:expr, $x23:expr, $x45:expr, $x67:expr) => {
11111110
simd_shuffle8(a, a, [

src/x86/sse42.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,42 @@ 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;
18-
/// For each character in `a`, determine if `b[0] <= c <= b[1] or b[1] <= c <=
19-
/// b[2]...`
20-
pub const _SIDD_CMP_RANGES: i8 = 0b00000100;
17+
pub const _SIDD_CMP_EQUAL_ANY: i8 = 0b0000_0000;
18+
/// For each character in `a`, determine if
19+
/// `b[0] <= c <= b[1] or b[1] <= c <= b[2]...`
20+
pub const _SIDD_CMP_RANGES: i8 = 0b0000_0100;
2121
/// The strings defined by `a` and `b` are equal
22-
pub const _SIDD_CMP_EQUAL_EACH: i8 = 0b00001000;
22+
pub const _SIDD_CMP_EQUAL_EACH: i8 = 0b0000_1000;
2323
/// Search for the defined substring in the target
24-
pub const _SIDD_CMP_EQUAL_ORDERED: i8 = 0b00001100;
24+
pub const _SIDD_CMP_EQUAL_ORDERED: i8 = 0b0000_1100;
2525

2626
/// Do not negate results *(Default)*
27-
pub const _SIDD_POSITIVE_POLARITY: i8 = 0b00000000;
27+
pub const _SIDD_POSITIVE_POLARITY: i8 = 0b0000_0000;
2828
/// Negate results
29-
pub const _SIDD_NEGATIVE_POLARITY: i8 = 0b00010000;
29+
pub const _SIDD_NEGATIVE_POLARITY: i8 = 0b0001_0000;
3030
/// Do not negate results before the end of the string
31-
pub const _SIDD_MASKED_POSITIVE_POLARITY: i8 = 0b00100000;
31+
pub const _SIDD_MASKED_POSITIVE_POLARITY: i8 = 0b0010_0000;
3232
/// Negate results only before the end of the string
33-
pub const _SIDD_MASKED_NEGATIVE_POLARITY: i8 = 0b00110000;
33+
pub const _SIDD_MASKED_NEGATIVE_POLARITY: i8 = 0b0011_0000;
3434

3535
/// **Index only**: return the least significant bit *(Default)*
36-
pub const _SIDD_LEAST_SIGNIFICANT: i8 = 0b00000000;
36+
pub const _SIDD_LEAST_SIGNIFICANT: i8 = 0b0000_0000;
3737
/// **Index only**: return the most significant bit
38-
pub const _SIDD_MOST_SIGNIFICANT: i8 = 0b01000000;
38+
pub const _SIDD_MOST_SIGNIFICANT: i8 = 0b0100_0000;
3939

4040
/// **Mask only**: return the bit mask
41-
pub const _SIDD_BIT_MASK: i8 = 0b00000000;
41+
pub const _SIDD_BIT_MASK: i8 = 0b0000_0000;
4242
/// **Mask only**: return the byte mask
43-
pub const _SIDD_UNIT_MASK: i8 = 0b01000000;
43+
pub const _SIDD_UNIT_MASK: i8 = 0b0100_0000;
4444

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

src/x86/ssse3.rs

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ pub unsafe fn _mm_shuffle_epi8(a: u8x16, b: u8x16) -> u8x16 {
7070
#[target_feature = "+ssse3"]
7171
#[cfg_attr(test, assert_instr(palignr, n = 15))]
7272
pub unsafe fn _mm_alignr_epi8(a: i8x16, b: i8x16, n: i32) -> i8x16 {
73+
const fn add(a: u32, b: u32) -> u32 { a + b }
74+
7375
let n = n as u32;
7476
// If palignr is shifting the pair of vectors more than the size of two
7577
// lanes, emit zero.

tests/cpu-detection.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#![cfg_attr(feature = "strict", deny(warnings))]
21
#![feature(cfg_target_feature)]
2+
#![cfg_attr(feature = "strict", deny(warnings))]
3+
#![cfg_attr(feature = "cargo-clippy", allow(option_unwrap_used))]
34

45
extern crate cupid;
6+
57
#[macro_use]
68
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
79
extern crate stdsimd;

0 commit comments

Comments
 (0)