Skip to content

Commit

Permalink
[ci] check formatting (rust-lang#64)
Browse files Browse the repository at this point in the history
* [ci] check formatting

* [rustfmt] reformat the whole library
  • Loading branch information
gnzlbg authored and alexcrichton committed Oct 27, 2017
1 parent 48b7bac commit afc0549
Show file tree
Hide file tree
Showing 35 changed files with 2,211 additions and 1,409 deletions.
14 changes: 13 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@ matrix:
script: ci/run.sh
- install: true
script: ci/dox.sh
- env: RUSTFMT=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
script: |
cargo install rustfmt-nightly
cargo fmt -- --write-mode=diff
cd stdsimd
cargo fmt -- --write-mode=diff
cd assert-instr-macro
cargo fmt -- --write-mode=diff
cd ../simd-test-macro
cargo fmt -- --write-mode=diff
allow_failures:
- env: RUSTFMT=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1

install:
- if [ "$NO_ADD" = "" ]; then rustup target add $TARGET; fi
- if [ "$NO_ADD" == "" ]; then rustup target add $TARGET; fi

script:
- cargo generate-lockfile
Expand Down
121 changes: 67 additions & 54 deletions examples/nbody.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ impl Frsqrt for f64x2 {

let u = unsafe {
vendor::_mm_rsqrt_ps(
f32x4::new(t.extract(0), t.extract(1), 0., 0.)).as_f64x4()
f32x4::new(t.extract(0), t.extract(1), 0., 0.),
).as_f64x4()
};
f64x2::new(u.extract(0), u.extract(1))
}
Expand All @@ -36,11 +37,12 @@ impl Frsqrt for f64x2 {
use self::stdsimd::vendor;
unsafe { vendor::vrsqrte_f32(self.as_f32x2()).as_f64x2() }
}
#[cfg(not(any(all(any(target_arch = "x86", target_arch = "x86_64"),
#[cfg(not(any(all(any(target_arch = "x86",
target_arch = "x86_64"),
target_feature = "sse"),
all(any(target_arch = "arm", target_arch = "aarch64"),
target_feature = "neon")
)))]
all(any(target_arch = "arm",
target_arch = "aarch64"),
target_feature = "neon"))))]
{
self.replace(0, 1. / self.extract(0).sqrt());
self.replace(1, 1. / self.extract(1).sqrt());
Expand All @@ -57,9 +59,9 @@ struct Body {
}

impl Body {
fn new(x0: f64, x1: f64, x2: f64,
v0: f64, v1: f64, v2: f64,
mass: f64) -> Body {
fn new(
x0: f64, x1: f64, x2: f64, v0: f64, v1: f64, v2: f64, mass: f64
) -> Body {
Body {
x: [x0, x1, x2],
_fill: 0.0,
Expand Down Expand Up @@ -91,7 +93,7 @@ fn advance(bodies: &mut [Body; N_BODIES], dt: f64) {

let mut i = 0;
for j in 0..N_BODIES {
for k in j+1..N_BODIES {
for k in j + 1..N_BODIES {
for m in 0..3 {
r[i][m] = bodies[j].x[m] - bodies[k].x[m];
}
Expand All @@ -102,14 +104,15 @@ 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]);
dx[m] = f64x2::new(r[i][m], r[i + 1][m]);
}

dsquared = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2];
distance = dsquared.frsqrt();
for _ in 0..2 {
distance = distance * f64x2::splat(1.5) -
((f64x2::splat(0.5) * dsquared) * distance) * (distance * distance)
distance = distance * f64x2::splat(1.5)
- ((f64x2::splat(0.5) * dsquared) * distance)
* (distance * distance)
}
dmag = f64x2::splat(dt) / dsquared * distance;
dmag.store(&mut mag, i);
Expand All @@ -119,7 +122,7 @@ fn advance(bodies: &mut [Body; N_BODIES], dt: f64) {

i = 0;
for j in 0..N_BODIES {
for k in j+1..N_BODIES {
for k in j + 1..N_BODIES {
for m in 0..3 {
bodies[j].v[m] -= r[i][m] * bodies[k].mass * mag[i];
bodies[k].v[m] += r[i][m] * bodies[j].mass * mag[i];
Expand All @@ -138,15 +141,19 @@ fn energy(bodies: &[Body; N_BODIES]) -> f64 {
let mut e = 0.0;
for i in 0..N_BODIES {
let bi = &bodies[i];
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 {
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];
let mut dx = [0.0; 3];
for k in 0..3 {
dx[k] = bi.x[k] - bj.x[k];
}
let mut distance = 0.0;
for &d in &dx { distance += d * d }
for &d in &dx {
distance += d * d
}
e -= bi.mass * bj.mass / distance.sqrt()
}
}
Expand All @@ -156,48 +163,54 @@ fn energy(bodies: &[Body; N_BODIES]) -> f64 {
fn main() {
let mut bodies: [Body; N_BODIES] = [
/* sun */
Body::new(0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
SOLAR_MASS),
Body::new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, SOLAR_MASS),
/* jupiter */
Body::new(4.84143144246472090e+00,
-1.16032004402742839e+00,
-1.03622044471123109e-01 ,
1.66007664274403694e-03 * DAYS_PER_YEAR,
7.69901118419740425e-03 * DAYS_PER_YEAR,
-6.90460016972063023e-05 * DAYS_PER_YEAR ,
9.54791938424326609e-04 * SOLAR_MASS
),
Body::new(
4.84143144246472090e+00,
-1.16032004402742839e+00,
-1.03622044471123109e-01,
1.66007664274403694e-03 * DAYS_PER_YEAR,
7.69901118419740425e-03 * DAYS_PER_YEAR,
-6.90460016972063023e-05 * DAYS_PER_YEAR,
9.54791938424326609e-04 * SOLAR_MASS,
),
/* saturn */
Body::new(8.34336671824457987e+00,
4.12479856412430479e+00,
-4.03523417114321381e-01 ,
-2.76742510726862411e-03 * DAYS_PER_YEAR,
4.99852801234917238e-03 * DAYS_PER_YEAR,
2.30417297573763929e-05 * DAYS_PER_YEAR ,
2.85885980666130812e-04 * SOLAR_MASS
),
Body::new(
8.34336671824457987e+00,
4.12479856412430479e+00,
-4.03523417114321381e-01,
-2.76742510726862411e-03 * DAYS_PER_YEAR,
4.99852801234917238e-03 * DAYS_PER_YEAR,
2.30417297573763929e-05 * DAYS_PER_YEAR,
2.85885980666130812e-04 * SOLAR_MASS,
),
/* uranus */
Body::new(1.28943695621391310e+01,
-1.51111514016986312e+01,
-2.23307578892655734e-01 ,
2.96460137564761618e-03 * DAYS_PER_YEAR,
2.37847173959480950e-03 * DAYS_PER_YEAR,
-2.96589568540237556e-05 * DAYS_PER_YEAR ,
4.36624404335156298e-05 * SOLAR_MASS
),
Body::new(
1.28943695621391310e+01,
-1.51111514016986312e+01,
-2.23307578892655734e-01,
2.96460137564761618e-03 * DAYS_PER_YEAR,
2.37847173959480950e-03 * DAYS_PER_YEAR,
-2.96589568540237556e-05 * DAYS_PER_YEAR,
4.36624404335156298e-05 * SOLAR_MASS,
),
/* neptune */
Body::new(1.53796971148509165e+01,
-2.59193146099879641e+01,
1.79258772950371181e-01 ,
2.68067772490389322e-03 * DAYS_PER_YEAR,
1.62824170038242295e-03 * DAYS_PER_YEAR,
-9.51592254519715870e-05 * DAYS_PER_YEAR ,
5.15138902046611451e-05 * SOLAR_MASS
)
];

let n: usize = std::env::args().nth(1).expect("need one arg").parse().unwrap();
Body::new(
1.53796971148509165e+01,
-2.59193146099879641e+01,
1.79258772950371181e-01,
2.68067772490389322e-03 * DAYS_PER_YEAR,
1.62824170038242295e-03 * DAYS_PER_YEAR,
-9.51592254519715870e-05 * DAYS_PER_YEAR,
5.15138902046611451e-05 * SOLAR_MASS,
),
];

let n: usize = std::env::args()
.nth(1)
.expect("need one arg")
.parse()
.unwrap();

offset_momentum(&mut bodies);
println!("{:.9}", energy(&bodies));
Expand Down
8 changes: 6 additions & 2 deletions examples/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ mod example {

unsafe {
vendor::_mm_cmpestri(
vneedle, needle_len as i32, vhaystack, hay_len as i32,
vendor::_SIDD_CMP_EQUAL_ORDERED) as usize
vneedle,
needle_len as i32,
vhaystack,
hay_len as i32,
vendor::_SIDD_CMP_EQUAL_ORDERED,
) as usize
}
}

Expand Down
5 changes: 5 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
max_width = 79
fn_call_width = 79
wrap_comments = true
error_on_line_overflow = false
fn_args_density = "Compressed"
4 changes: 3 additions & 1 deletion src/arm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//! The reference for NEON is [ARM's NEON Intrinsics Reference][arm_ref]. The
//! [ARM's NEON Intrinsics Online Database][arm_dat] is also useful.
//!
//! [arm_ref]: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0073a/IHI0073A_arm_neon_intrinsics_ref.pdf
//! [arm_ref]:
//! http://infocenter.arm.com/help/topic/com.arm.doc.
//! ihi0073a/IHI0073A_arm_neon_intrinsics_ref.pdf
//! [arm_dat]: https://developer.arm.com/technologies/neon/intrinsics
pub use self::v6::*;
Expand Down
19 changes: 13 additions & 6 deletions src/arm/v6.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! ARMv6 intrinsics.
//!
//! The reference is [ARMv6-M Architecture Reference
//! Manual](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0419c/index.html).
//! The reference is [ARMv6-M Architecture Reference Manual][armv6m].
//!
//! [armv6m]:
//! http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0419c/index.
//! html
#[cfg(test)]
use stdsimd_test::assert_instr;
Expand All @@ -27,16 +30,20 @@ mod tests {
#[test]
fn _rev_u16() {
unsafe {
assert_eq!(v6::_rev_u16(0b0000_0000_1111_1111_u16), 0b1111_1111_0000_0000_u16);
assert_eq!(
v6::_rev_u16(0b0000_0000_1111_1111_u16),
0b1111_1111_0000_0000_u16
);
}
}

#[test]
fn _rev_u32() {
unsafe {
assert_eq!(v6::_rev_u32(
0b0000_0000_1111_1111_0000_0000_1111_1111_u32
), 0b1111_1111_0000_0000_1111_1111_0000_0000_u32);
assert_eq!(
v6::_rev_u32(0b0000_0000_1111_1111_0000_0000_1111_1111_u32),
0b1111_1111_0000_0000_1111_1111_0000_0000_u32
);
}
}
}
14 changes: 10 additions & 4 deletions src/arm/v7.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//! ARMv7 intrinsics.
//!
//! The reference is [ARMv7-M Architecture Reference Manual (Issue
//! E.b)](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0403e.b/index.html).
//! E.b)][armv7m].
//!
//! [armv7m]:
//! http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0403e.
//! b/index.html
pub use super::v6::*;

Expand Down Expand Up @@ -39,7 +43,7 @@ pub unsafe fn _rbit_u32(x: u32) -> u32 {

#[allow(dead_code)]
extern "C" {
#[link_name="llvm.bitreverse.i32"]
#[link_name = "llvm.bitreverse.i32"]
fn rbit_u32(i: i32) -> i32;
}

Expand Down Expand Up @@ -72,8 +76,10 @@ mod tests {
#[test]
fn _rbit_u32() {
unsafe {
assert_eq!(v7::_rbit_u32(0b0000_1010u32),
0b0101_0000_0000_0000_0000_0000_0000_0000u32);
assert_eq!(
v7::_rbit_u32(0b0000_1010u32),
0b0101_0000_0000_0000_0000_0000_0000_0000u32
);
}
}
}
Loading

0 comments on commit afc0549

Please sign in to comment.