Skip to content

[ci] enable clippy #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ matrix:
script: |
cargo install rustfmt-nightly
cargo fmt --all -- --write-mode=diff
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
script: |
cargo install clippy
cargo clippy --all -- -D clippy-pedantic
allow_failures:
- env: RUSTFMT=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1

- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
install:
- if [ "$NO_ADD" == "" ]; then rustup target add $TARGET; fi

Expand Down
29 changes: 18 additions & 11 deletions examples/nbody.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
//! n-body benchmark from the [benchmarks game][bg].
//!
//! [bg]: https://benchmarksgame.alioth.debian.org/u64q/nbody-description.
//! html#nbody

#![cfg_attr(feature = "strict", deny(warnings))]
#![feature(cfg_target_feature)]
#![feature(target_feature)]
#![cfg_attr(feature = "cargo-clippy",
allow(similar_names, missing_docs_in_private_items,
shadow_reuse, print_stdout))]

extern crate stdsimd;
use self::stdsimd::simd;
use simd::f64x2;

const PI: f64 = 3.141592653589793;
const PI: f64 = std::f64::consts::PI;
const SOLAR_MASS: f64 = 4.0 * PI * PI;
const DAYS_PER_YEAR: f64 = 365.24;

Expand All @@ -29,7 +37,7 @@ impl Frsqrt for f64x2 {
f32x4::new(t.extract(0), t.extract(1), 0., 0.),
).as_f64x4()
};
f64x2::new(u.extract(0), u.extract(1))
Self::new(u.extract(0), u.extract(1))
}
#[cfg(all(any(target_arch = "arm", target_arch = "aarch64"),
target_feature = "neon"))]
Expand Down Expand Up @@ -61,8 +69,8 @@ struct Body {
impl Body {
fn new(
x0: f64, x1: f64, x2: f64, v0: f64, v1: f64, v2: f64, mass: f64
) -> Body {
Body {
) -> Self {
Self {
x: [x0, x1, x2],
_fill: 0.0,
v: [v0, v1, v2],
Expand Down Expand Up @@ -103,8 +111,8 @@ fn advance(bodies: &mut [Body; N_BODIES], dt: f64) {

i = 0;
while i < N {
for m in 0..3 {
dx[m] = f64x2::new(r[i][m], r[i + 1][m]);
for (m, dx) in dx.iter_mut().enumerate() {
*dx = f64x2::new(r[i][m], r[i + 1][m]);
}

dsquared = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2];
Expand Down Expand Up @@ -144,11 +152,10 @@ fn energy(bodies: &[Body; N_BODIES]) -> f64 {
e += bi.mass
* (bi.v[0] * bi.v[0] + bi.v[1] * bi.v[1] + bi.v[2] * bi.v[2])
/ 2.0;
for j in i + 1..N_BODIES {
let bj = &bodies[j];
for bj in bodies.iter().take(N_BODIES).skip(i + 1) {
let mut dx = [0.0; 3];
for k in 0..3 {
dx[k] = bi.x[k] - bj.x[k];
for (k, dx) in dx.iter_mut().enumerate() {
*dx = bi.x[k] - bj.x[k];
}
let mut distance = 0.0;
for &d in &dx {
Expand Down Expand Up @@ -210,7 +217,7 @@ fn main() {
.nth(1)
.expect("need one arg")
.parse()
.unwrap();
.expect("argument should be a usize");

offset_momentum(&mut bodies);
println!("{:.9}", energy(&bodies));
Expand Down
5 changes: 5 additions & 0 deletions examples/play.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#![cfg_attr(feature = "strict", deny(warnings))]
#![feature(target_feature)]
#![cfg_attr(feature = "cargo-clippy",
allow(similar_names, missing_docs_in_private_items,
cast_sign_loss, cast_possible_truncation,
cast_possible_wrap, option_unwrap_used, use_debug,
print_stdout))]

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod example {
Expand Down
3 changes: 3 additions & 0 deletions examples/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![cfg_attr(feature = "strict", deny(warnings))]
#![feature(target_feature)]
#![cfg_attr(feature = "cargo-clippy",
allow(missing_docs_in_private_items, result_unwrap_used,
option_unwrap_used, print_stdout, use_debug))]

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod example {
Expand Down
3 changes: 3 additions & 0 deletions examples/wat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![cfg_attr(feature = "strict", deny(warnings))]
#![feature(target_feature)]
#![cfg_attr(feature = "cargo-clippy",
allow(missing_docs_in_private_items, result_unwrap_used,
option_unwrap_used, print_stdout, use_debug))]

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod example {
Expand Down
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//! others at:
//!
//! * [i686](https://rust-lang-nursery.github.io/stdsimd/i686/stdsimd/)
//! * [x86_64](https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/)
//! * [`x86_64`](https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/)
//! * [arm](https://rust-lang-nursery.github.io/stdsimd/arm/stdsimd/)
//! * [aarch64](https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/)
//!
Expand Down Expand Up @@ -122,6 +122,12 @@
simd_ffi, target_feature, cfg_target_feature, i128_type, asm,
const_atomic_usize_new, stmt_expr_attributes)]
#![cfg_attr(test, feature(proc_macro, test))]
#![cfg_attr(feature = "cargo-clippy",
allow(inline_always, too_many_arguments, cast_sign_loss,
cast_lossless, cast_possible_wrap,
cast_possible_truncation, cast_precision_loss,
shadow_reuse, cyclomatic_complexity, similar_names,
doc_markdown, many_single_char_names))]

#[cfg(test)]
extern crate stdsimd_test;
Expand Down
2 changes: 2 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Utility macros

macro_rules! define_ty {
($name:ident, $($elty:ident),+) => {
#[repr(simd)]
Expand Down
4 changes: 4 additions & 0 deletions src/simd_llvm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! LLVM's simd platform intrinsics
//!
//! TODO: should use `link_llvm_intrinsic` instead: issue #112

extern "platform-intrinsic" {
pub fn simd_eq<T, U>(x: T, y: T) -> U;
pub fn simd_ne<T, U>(x: T, y: T) -> U;
Expand Down
2 changes: 2 additions & 0 deletions src/v128.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! 128-bit wide vector types

use simd_llvm::*;

define_ty! { f64x2, f64, f64 }
Expand Down
2 changes: 2 additions & 0 deletions src/v256.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! 256-bit wide vector types

use simd_llvm::*;

define_ty! { f64x4, f64, f64, f64, f64 }
Expand Down
2 changes: 2 additions & 0 deletions src/v512.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! 512-bit wide vector types

use simd_llvm::*;

define_ty! { f64x8, f64, f64, f64, f64, f64, f64, f64, f64 }
Expand Down
2 changes: 2 additions & 0 deletions src/v64.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! 64-bit wide vector types

use simd_llvm::*;

define_ty_doc! {
Expand Down
101 changes: 57 additions & 44 deletions src/x86/avx.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
//! Advanced Vector Extensions (AVX)
//!
//! The references are:
//!
//! - [Intel 64 and IA-32 Architectures Software Developer's Manual Volume 2:
//! Instruction Set Reference, A-Z][intel64_ref]. - [AMD64 Architecture
//! Programmer's Manual, Volume 3: General-Purpose and System
//! Instructions][amd64_ref].
//!
//! [Wikipedia][wiki] provides a quick overview of the instructions available.
//!
//! [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
//! [amd64_ref]: http://support.amd.com/TechDocs/24594.pdf
//! [wiki]: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions

use std::mem;
use std::ptr;

Expand Down Expand Up @@ -113,7 +128,7 @@ pub unsafe fn _mm256_shuffle_pd(a: f64x4, b: f64x4, imm8: i32) -> f64x4 {
}
}
}
match (imm8 >> 0) & 0x1 {
match imm8 & 0x1 {
0 => shuffle1!(0),
_ => shuffle1!(1),
}
Expand Down Expand Up @@ -161,7 +176,7 @@ pub unsafe fn _mm256_shuffle_ps(a: f32x8, b: f32x8, imm8: i32) -> f32x8 {
}
}
}
match (imm8 >> 0) & 0x3 {
match imm8 & 0x3 {
0 => shuffle1!(0, 4),
1 => shuffle1!(1, 5),
2 => shuffle1!(2, 6),
Expand Down Expand Up @@ -594,69 +609,69 @@ pub unsafe fn _mm256_xor_ps(a: f32x8, b: f32x8) -> f32x8 {
mem::transmute(a ^ b)
}

// Equal (ordered, non-signaling)
/// Equal (ordered, non-signaling)
pub const _CMP_EQ_OQ: u8 = 0x00;
// Less-than (ordered, signaling)
/// Less-than (ordered, signaling)
pub const _CMP_LT_OS: u8 = 0x01;
// Less-than-or-equal (ordered, signaling)
/// Less-than-or-equal (ordered, signaling)
pub const _CMP_LE_OS: u8 = 0x02;
// Unordered (non-signaling)
/// Unordered (non-signaling)
pub const _CMP_UNORD_Q: u8 = 0x03;
// Not-equal (unordered, non-signaling)
/// Not-equal (unordered, non-signaling)
pub const _CMP_NEQ_UQ: u8 = 0x04;
// Not-less-than (unordered, signaling)
/// Not-less-than (unordered, signaling)
pub const _CMP_NLT_US: u8 = 0x05;
// Not-less-than-or-equal (unordered, signaling)
/// Not-less-than-or-equal (unordered, signaling)
pub const _CMP_NLE_US: u8 = 0x06;
// Ordered (non-signaling)
/// Ordered (non-signaling)
pub const _CMP_ORD_Q: u8 = 0x07;
// Equal (unordered, non-signaling)
/// Equal (unordered, non-signaling)
pub const _CMP_EQ_UQ: u8 = 0x08;
// Not-greater-than-or-equal (unordered, signaling)
/// Not-greater-than-or-equal (unordered, signaling)
pub const _CMP_NGE_US: u8 = 0x09;
// Not-greater-than (unordered, signaling)
/// Not-greater-than (unordered, signaling)
pub const _CMP_NGT_US: u8 = 0x0a;
// False (ordered, non-signaling)
/// False (ordered, non-signaling)
pub const _CMP_FALSE_OQ: u8 = 0x0b;
// Not-equal (ordered, non-signaling)
/// Not-equal (ordered, non-signaling)
pub const _CMP_NEQ_OQ: u8 = 0x0c;
// Greater-than-or-equal (ordered, signaling)
/// Greater-than-or-equal (ordered, signaling)
pub const _CMP_GE_OS: u8 = 0x0d;
// Greater-than (ordered, signaling)
/// Greater-than (ordered, signaling)
pub const _CMP_GT_OS: u8 = 0x0e;
// True (unordered, non-signaling)
/// True (unordered, non-signaling)
pub const _CMP_TRUE_UQ: u8 = 0x0f;
// Equal (ordered, signaling)
/// Equal (ordered, signaling)
pub const _CMP_EQ_OS: u8 = 0x10;
// Less-than (ordered, non-signaling)
/// Less-than (ordered, non-signaling)
pub const _CMP_LT_OQ: u8 = 0x11;
// Less-than-or-equal (ordered, non-signaling)
/// Less-than-or-equal (ordered, non-signaling)
pub const _CMP_LE_OQ: u8 = 0x12;
// Unordered (signaling)
/// Unordered (signaling)
pub const _CMP_UNORD_S: u8 = 0x13;
// Not-equal (unordered, signaling)
/// Not-equal (unordered, signaling)
pub const _CMP_NEQ_US: u8 = 0x14;
// Not-less-than (unordered, non-signaling)
/// Not-less-than (unordered, non-signaling)
pub const _CMP_NLT_UQ: u8 = 0x15;
// Not-less-than-or-equal (unordered, non-signaling)
/// Not-less-than-or-equal (unordered, non-signaling)
pub const _CMP_NLE_UQ: u8 = 0x16;
// Ordered (signaling)
/// Ordered (signaling)
pub const _CMP_ORD_S: u8 = 0x17;
// Equal (unordered, signaling)
/// Equal (unordered, signaling)
pub const _CMP_EQ_US: u8 = 0x18;
// Not-greater-than-or-equal (unordered, non-signaling)
/// Not-greater-than-or-equal (unordered, non-signaling)
pub const _CMP_NGE_UQ: u8 = 0x19;
// Not-greater-than (unordered, non-signaling)
/// Not-greater-than (unordered, non-signaling)
pub const _CMP_NGT_UQ: u8 = 0x1a;
// False (ordered, signaling)
/// False (ordered, signaling)
pub const _CMP_FALSE_OS: u8 = 0x1b;
// Not-equal (ordered, signaling)
/// Not-equal (ordered, signaling)
pub const _CMP_NEQ_OS: u8 = 0x1c;
// Greater-than-or-equal (ordered, non-signaling)
/// Greater-than-or-equal (ordered, non-signaling)
pub const _CMP_GE_OQ: u8 = 0x1d;
// Greater-than (ordered, non-signaling)
/// Greater-than (ordered, non-signaling)
pub const _CMP_GT_OQ: u8 = 0x1e;
// True (unordered, signaling)
/// True (unordered, signaling)
pub const _CMP_TRUE_US: u8 = 0x1f;

/// Compare packed double-precision (64-bit) floating-point
Expand Down Expand Up @@ -920,13 +935,10 @@ pub unsafe fn _mm_permutevar_ps(a: f32x4, b: i32x4) -> f32x4 {
#[cfg_attr(test, assert_instr(vpermilps, imm8 = 9))]
pub unsafe fn _mm256_permute_ps(a: f32x8, imm8: i32) -> f32x8 {
let imm8 = (imm8 & 0xFF) as u8;
const fn add4(x: u32) -> u32 {
x + 4
}
macro_rules! shuffle4 {
($a:expr, $b:expr, $c:expr, $d:expr) => {
simd_shuffle8(a, _mm256_undefined_ps(), [
$a, $b, $c, $d, add4($a), add4($b), add4($c), add4($d)
$a, $b, $c, $d, $a + 4, $b + 4, $c + 4, $d + 4
])
}
}
Expand Down Expand Up @@ -960,7 +972,7 @@ pub unsafe fn _mm256_permute_ps(a: f32x8, imm8: i32) -> f32x8 {
}
}
}
match (imm8 >> 0) & 0b11 {
match imm8 & 0b11 {
0b00 => shuffle1!(0),
0b01 => shuffle1!(1),
0b10 => shuffle1!(2),
Expand Down Expand Up @@ -1014,14 +1026,16 @@ pub unsafe fn _mm_permute_ps(a: f32x4, imm8: i32) -> f32x4 {
}
}
}
match (imm8 >> 0) & 0b11 {
match imm8 & 0b11 {
0b00 => shuffle1!(0),
0b01 => shuffle1!(1),
0b10 => shuffle1!(2),
_ => shuffle1!(3),
}
}

/// Shuffle double-precision (64-bit) floating-point elements in `a`
/// within 256-bit lanes using the control in `b`.
#[inline(always)]
#[target_feature = "+avx"]
#[cfg_attr(test, assert_instr(vpermilpd))]
Expand Down Expand Up @@ -1074,7 +1088,7 @@ pub unsafe fn _mm256_permute_pd(a: f64x4, imm8: i32) -> f64x4 {
}
}
}
match (imm8 >> 0) & 0x1 {
match imm8 & 0x1 {
0 => shuffle1!(0),
_ => shuffle1!(1),
}
Expand Down Expand Up @@ -1102,7 +1116,7 @@ pub unsafe fn _mm_permute_pd(a: f64x2, imm8: i32) -> f64x2 {
}
}
}
match (imm8 >> 0) & 0x1 {
match imm8 & 0x1 {
0 => shuffle1!(0),
_ => shuffle1!(1),
}
Expand Down Expand Up @@ -2750,8 +2764,7 @@ mod tests {
let a = f32x8::new(4., 9., 16., 25., 4., 9., 16., 25.);
let b = f32x8::new(4., 3., 2., 5., 8., 9., 64., 50.);
let r = avx::_mm256_dp_ps(a, b, 0xFF);
let e =
f32x8::new(200., 200., 200., 200., 2387., 2387., 2387., 2387.);
let e = f32x8::new(200., 200., 200., 200., 2387., 2387., 2387., 2387.);
assert_eq!(r, e);
}

Expand Down
Loading