Skip to content

Commit 1cbd309

Browse files
gnzlbgalexcrichton
authored andcommitted
[ci] enable clippy (#62)
* [ci] enable clippy * [clippy] fix clippy issues
1 parent 46d64f0 commit 1cbd309

25 files changed

+352
-222
lines changed

.travis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ matrix:
2121
script: |
2222
cargo install rustfmt-nightly
2323
cargo fmt --all -- --write-mode=diff
24+
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
25+
script: |
26+
cargo install clippy
27+
cargo clippy --all -- -D clippy-pedantic
2428
allow_failures:
2529
- env: RUSTFMT=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
26-
30+
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
2731
install:
2832
- if [ "$NO_ADD" == "" ]; then rustup target add $TARGET; fi
2933

examples/nbody.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
//! n-body benchmark from the [benchmarks game][bg].
2+
//!
3+
//! [bg]: https://benchmarksgame.alioth.debian.org/u64q/nbody-description.
4+
//! html#nbody
5+
16
#![cfg_attr(feature = "strict", deny(warnings))]
27
#![feature(cfg_target_feature)]
38
#![feature(target_feature)]
9+
#![cfg_attr(feature = "cargo-clippy",
10+
allow(similar_names, missing_docs_in_private_items,
11+
shadow_reuse, print_stdout))]
412

513
extern crate stdsimd;
614
use self::stdsimd::simd;
715
use simd::f64x2;
816

9-
const PI: f64 = 3.141592653589793;
17+
const PI: f64 = std::f64::consts::PI;
1018
const SOLAR_MASS: f64 = 4.0 * PI * PI;
1119
const DAYS_PER_YEAR: f64 = 365.24;
1220

@@ -29,7 +37,7 @@ impl Frsqrt for f64x2 {
2937
f32x4::new(t.extract(0), t.extract(1), 0., 0.),
3038
).as_f64x4()
3139
};
32-
f64x2::new(u.extract(0), u.extract(1))
40+
Self::new(u.extract(0), u.extract(1))
3341
}
3442
#[cfg(all(any(target_arch = "arm", target_arch = "aarch64"),
3543
target_feature = "neon"))]
@@ -61,8 +69,8 @@ struct Body {
6169
impl Body {
6270
fn new(
6371
x0: f64, x1: f64, x2: f64, v0: f64, v1: f64, v2: f64, mass: f64
64-
) -> Body {
65-
Body {
72+
) -> Self {
73+
Self {
6674
x: [x0, x1, x2],
6775
_fill: 0.0,
6876
v: [v0, v1, v2],
@@ -103,8 +111,8 @@ fn advance(bodies: &mut [Body; N_BODIES], dt: f64) {
103111

104112
i = 0;
105113
while i < N {
106-
for m in 0..3 {
107-
dx[m] = f64x2::new(r[i][m], r[i + 1][m]);
114+
for (m, dx) in dx.iter_mut().enumerate() {
115+
*dx = f64x2::new(r[i][m], r[i + 1][m]);
108116
}
109117

110118
dsquared = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2];
@@ -144,11 +152,10 @@ fn energy(bodies: &[Body; N_BODIES]) -> f64 {
144152
e += bi.mass
145153
* (bi.v[0] * bi.v[0] + bi.v[1] * bi.v[1] + bi.v[2] * bi.v[2])
146154
/ 2.0;
147-
for j in i + 1..N_BODIES {
148-
let bj = &bodies[j];
155+
for bj in bodies.iter().take(N_BODIES).skip(i + 1) {
149156
let mut dx = [0.0; 3];
150-
for k in 0..3 {
151-
dx[k] = bi.x[k] - bj.x[k];
157+
for (k, dx) in dx.iter_mut().enumerate() {
158+
*dx = bi.x[k] - bj.x[k];
152159
}
153160
let mut distance = 0.0;
154161
for &d in &dx {
@@ -210,7 +217,7 @@ fn main() {
210217
.nth(1)
211218
.expect("need one arg")
212219
.parse()
213-
.unwrap();
220+
.expect("argument should be a usize");
214221

215222
offset_momentum(&mut bodies);
216223
println!("{:.9}", energy(&bodies));

examples/play.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![cfg_attr(feature = "strict", deny(warnings))]
22
#![feature(target_feature)]
3+
#![cfg_attr(feature = "cargo-clippy",
4+
allow(similar_names, missing_docs_in_private_items,
5+
cast_sign_loss, cast_possible_truncation,
6+
cast_possible_wrap, option_unwrap_used, use_debug,
7+
print_stdout))]
38

49
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
510
mod example {

examples/types.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![cfg_attr(feature = "strict", deny(warnings))]
22
#![feature(target_feature)]
3+
#![cfg_attr(feature = "cargo-clippy",
4+
allow(missing_docs_in_private_items, result_unwrap_used,
5+
option_unwrap_used, print_stdout, use_debug))]
36

47
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
58
mod example {

examples/wat.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![cfg_attr(feature = "strict", deny(warnings))]
22
#![feature(target_feature)]
3+
#![cfg_attr(feature = "cargo-clippy",
4+
allow(missing_docs_in_private_items, result_unwrap_used,
5+
option_unwrap_used, print_stdout, use_debug))]
36

47
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
58
mod example {

src/lib.rs

+7-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
//!
@@ -122,6 +122,12 @@
122122
simd_ffi, target_feature, cfg_target_feature, i128_type, asm,
123123
const_atomic_usize_new, stmt_expr_attributes)]
124124
#![cfg_attr(test, feature(proc_macro, test))]
125+
#![cfg_attr(feature = "cargo-clippy",
126+
allow(inline_always, too_many_arguments, cast_sign_loss,
127+
cast_lossless, cast_possible_wrap,
128+
cast_possible_truncation, cast_precision_loss,
129+
shadow_reuse, cyclomatic_complexity, similar_names,
130+
doc_markdown, many_single_char_names))]
125131

126132
#[cfg(test)]
127133
extern crate stdsimd_test;

src/macros.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Utility macros
2+
13
macro_rules! define_ty {
24
($name:ident, $($elty:ident),+) => {
35
#[repr(simd)]

src/simd_llvm.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! LLVM's simd platform intrinsics
2+
//!
3+
//! TODO: should use `link_llvm_intrinsic` instead: issue #112
4+
15
extern "platform-intrinsic" {
26
pub fn simd_eq<T, U>(x: T, y: T) -> U;
37
pub fn simd_ne<T, U>(x: T, y: T) -> U;

src/v128.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! 128-bit wide vector types
2+
13
use simd_llvm::*;
24

35
define_ty! { f64x2, f64, f64 }

src/v256.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! 256-bit wide vector types
2+
13
use simd_llvm::*;
24

35
define_ty! { f64x4, f64, f64, f64, f64 }

src/v512.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! 512-bit wide vector types
2+
13
use simd_llvm::*;
24

35
define_ty! { f64x8, f64, f64, f64, f64, f64, f64, f64, f64 }

src/v64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! 64-bit wide vector types
2+
13
use simd_llvm::*;
24

35
define_ty_doc! {

src/x86/avx.rs

+57-44
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
//! Advanced Vector Extensions (AVX)
2+
//!
3+
//! The references are:
4+
//!
5+
//! - [Intel 64 and IA-32 Architectures Software Developer's Manual Volume 2:
6+
//! Instruction Set Reference, A-Z][intel64_ref]. - [AMD64 Architecture
7+
//! Programmer's Manual, Volume 3: General-Purpose and System
8+
//! Instructions][amd64_ref].
9+
//!
10+
//! [Wikipedia][wiki] provides a quick overview of the instructions available.
11+
//!
12+
//! [intel64_ref]: http://www.intel.de/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf
13+
//! [amd64_ref]: http://support.amd.com/TechDocs/24594.pdf
14+
//! [wiki]: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions
15+
116
use std::mem;
217
use std::ptr;
318

@@ -113,7 +128,7 @@ pub unsafe fn _mm256_shuffle_pd(a: f64x4, b: f64x4, imm8: i32) -> f64x4 {
113128
}
114129
}
115130
}
116-
match (imm8 >> 0) & 0x1 {
131+
match imm8 & 0x1 {
117132
0 => shuffle1!(0),
118133
_ => shuffle1!(1),
119134
}
@@ -161,7 +176,7 @@ pub unsafe fn _mm256_shuffle_ps(a: f32x8, b: f32x8, imm8: i32) -> f32x8 {
161176
}
162177
}
163178
}
164-
match (imm8 >> 0) & 0x3 {
179+
match imm8 & 0x3 {
165180
0 => shuffle1!(0, 4),
166181
1 => shuffle1!(1, 5),
167182
2 => shuffle1!(2, 6),
@@ -594,69 +609,69 @@ pub unsafe fn _mm256_xor_ps(a: f32x8, b: f32x8) -> f32x8 {
594609
mem::transmute(a ^ b)
595610
}
596611

597-
// Equal (ordered, non-signaling)
612+
/// Equal (ordered, non-signaling)
598613
pub const _CMP_EQ_OQ: u8 = 0x00;
599-
// Less-than (ordered, signaling)
614+
/// Less-than (ordered, signaling)
600615
pub const _CMP_LT_OS: u8 = 0x01;
601-
// Less-than-or-equal (ordered, signaling)
616+
/// Less-than-or-equal (ordered, signaling)
602617
pub const _CMP_LE_OS: u8 = 0x02;
603-
// Unordered (non-signaling)
618+
/// Unordered (non-signaling)
604619
pub const _CMP_UNORD_Q: u8 = 0x03;
605-
// Not-equal (unordered, non-signaling)
620+
/// Not-equal (unordered, non-signaling)
606621
pub const _CMP_NEQ_UQ: u8 = 0x04;
607-
// Not-less-than (unordered, signaling)
622+
/// Not-less-than (unordered, signaling)
608623
pub const _CMP_NLT_US: u8 = 0x05;
609-
// Not-less-than-or-equal (unordered, signaling)
624+
/// Not-less-than-or-equal (unordered, signaling)
610625
pub const _CMP_NLE_US: u8 = 0x06;
611-
// Ordered (non-signaling)
626+
/// Ordered (non-signaling)
612627
pub const _CMP_ORD_Q: u8 = 0x07;
613-
// Equal (unordered, non-signaling)
628+
/// Equal (unordered, non-signaling)
614629
pub const _CMP_EQ_UQ: u8 = 0x08;
615-
// Not-greater-than-or-equal (unordered, signaling)
630+
/// Not-greater-than-or-equal (unordered, signaling)
616631
pub const _CMP_NGE_US: u8 = 0x09;
617-
// Not-greater-than (unordered, signaling)
632+
/// Not-greater-than (unordered, signaling)
618633
pub const _CMP_NGT_US: u8 = 0x0a;
619-
// False (ordered, non-signaling)
634+
/// False (ordered, non-signaling)
620635
pub const _CMP_FALSE_OQ: u8 = 0x0b;
621-
// Not-equal (ordered, non-signaling)
636+
/// Not-equal (ordered, non-signaling)
622637
pub const _CMP_NEQ_OQ: u8 = 0x0c;
623-
// Greater-than-or-equal (ordered, signaling)
638+
/// Greater-than-or-equal (ordered, signaling)
624639
pub const _CMP_GE_OS: u8 = 0x0d;
625-
// Greater-than (ordered, signaling)
640+
/// Greater-than (ordered, signaling)
626641
pub const _CMP_GT_OS: u8 = 0x0e;
627-
// True (unordered, non-signaling)
642+
/// True (unordered, non-signaling)
628643
pub const _CMP_TRUE_UQ: u8 = 0x0f;
629-
// Equal (ordered, signaling)
644+
/// Equal (ordered, signaling)
630645
pub const _CMP_EQ_OS: u8 = 0x10;
631-
// Less-than (ordered, non-signaling)
646+
/// Less-than (ordered, non-signaling)
632647
pub const _CMP_LT_OQ: u8 = 0x11;
633-
// Less-than-or-equal (ordered, non-signaling)
648+
/// Less-than-or-equal (ordered, non-signaling)
634649
pub const _CMP_LE_OQ: u8 = 0x12;
635-
// Unordered (signaling)
650+
/// Unordered (signaling)
636651
pub const _CMP_UNORD_S: u8 = 0x13;
637-
// Not-equal (unordered, signaling)
652+
/// Not-equal (unordered, signaling)
638653
pub const _CMP_NEQ_US: u8 = 0x14;
639-
// Not-less-than (unordered, non-signaling)
654+
/// Not-less-than (unordered, non-signaling)
640655
pub const _CMP_NLT_UQ: u8 = 0x15;
641-
// Not-less-than-or-equal (unordered, non-signaling)
656+
/// Not-less-than-or-equal (unordered, non-signaling)
642657
pub const _CMP_NLE_UQ: u8 = 0x16;
643-
// Ordered (signaling)
658+
/// Ordered (signaling)
644659
pub const _CMP_ORD_S: u8 = 0x17;
645-
// Equal (unordered, signaling)
660+
/// Equal (unordered, signaling)
646661
pub const _CMP_EQ_US: u8 = 0x18;
647-
// Not-greater-than-or-equal (unordered, non-signaling)
662+
/// Not-greater-than-or-equal (unordered, non-signaling)
648663
pub const _CMP_NGE_UQ: u8 = 0x19;
649-
// Not-greater-than (unordered, non-signaling)
664+
/// Not-greater-than (unordered, non-signaling)
650665
pub const _CMP_NGT_UQ: u8 = 0x1a;
651-
// False (ordered, signaling)
666+
/// False (ordered, signaling)
652667
pub const _CMP_FALSE_OS: u8 = 0x1b;
653-
// Not-equal (ordered, signaling)
668+
/// Not-equal (ordered, signaling)
654669
pub const _CMP_NEQ_OS: u8 = 0x1c;
655-
// Greater-than-or-equal (ordered, non-signaling)
670+
/// Greater-than-or-equal (ordered, non-signaling)
656671
pub const _CMP_GE_OQ: u8 = 0x1d;
657-
// Greater-than (ordered, non-signaling)
672+
/// Greater-than (ordered, non-signaling)
658673
pub const _CMP_GT_OQ: u8 = 0x1e;
659-
// True (unordered, signaling)
674+
/// True (unordered, signaling)
660675
pub const _CMP_TRUE_US: u8 = 0x1f;
661676

662677
/// Compare packed double-precision (64-bit) floating-point
@@ -920,13 +935,10 @@ pub unsafe fn _mm_permutevar_ps(a: f32x4, b: i32x4) -> f32x4 {
920935
#[cfg_attr(test, assert_instr(vpermilps, imm8 = 9))]
921936
pub unsafe fn _mm256_permute_ps(a: f32x8, imm8: i32) -> f32x8 {
922937
let imm8 = (imm8 & 0xFF) as u8;
923-
const fn add4(x: u32) -> u32 {
924-
x + 4
925-
}
926938
macro_rules! shuffle4 {
927939
($a:expr, $b:expr, $c:expr, $d:expr) => {
928940
simd_shuffle8(a, _mm256_undefined_ps(), [
929-
$a, $b, $c, $d, add4($a), add4($b), add4($c), add4($d)
941+
$a, $b, $c, $d, $a + 4, $b + 4, $c + 4, $d + 4
930942
])
931943
}
932944
}
@@ -960,7 +972,7 @@ pub unsafe fn _mm256_permute_ps(a: f32x8, imm8: i32) -> f32x8 {
960972
}
961973
}
962974
}
963-
match (imm8 >> 0) & 0b11 {
975+
match imm8 & 0b11 {
964976
0b00 => shuffle1!(0),
965977
0b01 => shuffle1!(1),
966978
0b10 => shuffle1!(2),
@@ -1014,14 +1026,16 @@ pub unsafe fn _mm_permute_ps(a: f32x4, imm8: i32) -> f32x4 {
10141026
}
10151027
}
10161028
}
1017-
match (imm8 >> 0) & 0b11 {
1029+
match imm8 & 0b11 {
10181030
0b00 => shuffle1!(0),
10191031
0b01 => shuffle1!(1),
10201032
0b10 => shuffle1!(2),
10211033
_ => shuffle1!(3),
10221034
}
10231035
}
10241036

1037+
/// Shuffle double-precision (64-bit) floating-point elements in `a`
1038+
/// within 256-bit lanes using the control in `b`.
10251039
#[inline(always)]
10261040
#[target_feature = "+avx"]
10271041
#[cfg_attr(test, assert_instr(vpermilpd))]
@@ -1074,7 +1088,7 @@ pub unsafe fn _mm256_permute_pd(a: f64x4, imm8: i32) -> f64x4 {
10741088
}
10751089
}
10761090
}
1077-
match (imm8 >> 0) & 0x1 {
1091+
match imm8 & 0x1 {
10781092
0 => shuffle1!(0),
10791093
_ => shuffle1!(1),
10801094
}
@@ -1102,7 +1116,7 @@ pub unsafe fn _mm_permute_pd(a: f64x2, imm8: i32) -> f64x2 {
11021116
}
11031117
}
11041118
}
1105-
match (imm8 >> 0) & 0x1 {
1119+
match imm8 & 0x1 {
11061120
0 => shuffle1!(0),
11071121
_ => shuffle1!(1),
11081122
}
@@ -2750,8 +2764,7 @@ mod tests {
27502764
let a = f32x8::new(4., 9., 16., 25., 4., 9., 16., 25.);
27512765
let b = f32x8::new(4., 3., 2., 5., 8., 9., 64., 50.);
27522766
let r = avx::_mm256_dp_ps(a, b, 0xFF);
2753-
let e =
2754-
f32x8::new(200., 200., 200., 200., 2387., 2387., 2387., 2387.);
2767+
let e = f32x8::new(200., 200., 200., 200., 2387., 2387., 2387., 2387.);
27552768
assert_eq!(r, e);
27562769
}
27572770

0 commit comments

Comments
 (0)