From 8544574d32723457d348505c289a8df908cbc5b5 Mon Sep 17 00:00:00 2001
From: Kyle Siefring <kylesiefring@gmail.com>
Date: Thu, 6 Sep 2018 16:03:27 -0400
Subject: [PATCH] Do low impact rust format (#550)

---
 benches/comparative/mod.rs |   5 +-
 src/bin/common.rs          |   4 +-
 src/bin/rav1e.rs           |  66 ++++---
 src/bin/rav1repl.rs        |   2 +-
 src/ec.rs                  |  80 ++++----
 src/encoder.rs             |  21 +--
 src/me.rs                  |  19 +-
 src/partition.rs           | 373 ++++++++++++++++++++++---------------
 src/plane.rs               | 118 ++++++++----
 src/predict.rs             |  41 ++--
 src/quantize.rs            |  19 +-
 src/rdo.rs                 | 173 ++++++++++++-----
 src/test_encode_decode.rs  |   2 +-
 src/transform.rs           |  57 +++---
 src/util.rs                |  25 ++-
 15 files changed, 605 insertions(+), 400 deletions(-)

diff --git a/benches/comparative/mod.rs b/benches/comparative/mod.rs
index 3b465647..f366f20c 100755
--- a/benches/comparative/mod.rs
+++ b/benches/comparative/mod.rs
@@ -13,7 +13,4 @@ mod predict;
 
 use criterion::Criterion;
 
-criterion_group!(
-  intra_prediction,
-  predict::intra_bench,
-);
+criterion_group!(intra_prediction, predict::intra_bench);
diff --git a/src/bin/common.rs b/src/bin/common.rs
index 5a450788..abdcc32e 100644
--- a/src/bin/common.rs
+++ b/src/bin/common.rs
@@ -1,10 +1,10 @@
-use y4m;
+use clap::{App, Arg};
 use rav1e::*;
 use std::fs::File;
 use std::io;
 use std::io::prelude::*;
 use std::slice;
-use clap::{App, Arg};
+use y4m;
 
 pub struct EncoderIO {
     pub input: Box<dyn Read>,
diff --git a/src/bin/rav1e.rs b/src/bin/rav1e.rs
index 2b311b07..183fb586 100755
--- a/src/bin/rav1e.rs
+++ b/src/bin/rav1e.rs
@@ -7,15 +7,15 @@
 // Media Patent License 1.0 was not distributed with this source code in the
 // PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 
+extern crate clap;
 extern crate rav1e;
 extern crate y4m;
-extern crate clap;
 
 mod common;
 use common::*;
 
-use rav1e::*;
 use rav1e::partition::LAST_FRAME;
+use rav1e::*;
 
 fn main() {
   let (mut io, config) = EncoderConfig::from_cli();
@@ -25,33 +25,35 @@ fn main() {
   let framerate = y4m_dec.get_framerate();
   let color_space = y4m_dec.get_colorspace();
   let mut y4m_enc = match io.rec.as_mut() {
-    Some(rec) =>
-      Some(y4m::encode(width, height, framerate)
-		    .with_colorspace(color_space).write_header(rec).unwrap()),
+    Some(rec) => Some(
+      y4m::encode(width, height, framerate)
+        .with_colorspace(color_space)
+        .write_header(rec)
+        .unwrap()
+    ),
     None => None
   };
 
   let mut fi = FrameInvariants::new(width, height, config);
 
   let chroma_sampling = match color_space {
-    y4m::Colorspace::C420 |
-    y4m::Colorspace::C420jpeg |
-    y4m::Colorspace::C420paldv |
-    y4m::Colorspace::C420mpeg2 |
-    y4m::Colorspace::C420p10 |
-    y4m::Colorspace::C420p12 => ChromaSampling::Cs420,
-    y4m::Colorspace::C422 |
-    y4m::Colorspace::C422p10 |
-    y4m::Colorspace::C422p12 => ChromaSampling::Cs422,
-    y4m::Colorspace::C444 |
-    y4m::Colorspace::C444p10 |
-    y4m::Colorspace::C444p12 => ChromaSampling::Cs444,
-    _ => {
-        panic!("Chroma sampling unknown for the specified color space.")
-    }
+    y4m::Colorspace::C420
+    | y4m::Colorspace::C420jpeg
+    | y4m::Colorspace::C420paldv
+    | y4m::Colorspace::C420mpeg2
+    | y4m::Colorspace::C420p10
+    | y4m::Colorspace::C420p12 => ChromaSampling::Cs420,
+    y4m::Colorspace::C422
+    | y4m::Colorspace::C422p10
+    | y4m::Colorspace::C422p12 => ChromaSampling::Cs422,
+    y4m::Colorspace::C444
+    | y4m::Colorspace::C444p10
+    | y4m::Colorspace::C444p12 => ChromaSampling::Cs444,
+    _ => panic!("Chroma sampling unknown for the specified color space.")
   };
-  
-  let mut sequence = Sequence::new(width, height, color_space.get_bit_depth(), chroma_sampling);
+
+  let mut sequence =
+    Sequence::new(width, height, color_space.get_bit_depth(), chroma_sampling);
   write_ivf_header(
     &mut io.output,
     width,
@@ -64,20 +66,22 @@ fn main() {
     fi.frame_type =
       if fi.number % 30 == 0 { FrameType::KEY } else { FrameType::INTER };
 
-    fi.base_q_idx =
-      if fi.frame_type == FrameType::KEY {
-        let q_boost = 15;
-        fi.config.quantizer.max(1 + q_boost).min(255 + q_boost) - q_boost
-      } else {
-        fi.config.quantizer.max(1).min(255)
-      } as u8;
+    fi.base_q_idx = if fi.frame_type == FrameType::KEY {
+      let q_boost = 15;
+      fi.config.quantizer.max(1 + q_boost).min(255 + q_boost) - q_boost
+    } else {
+      fi.config.quantizer.max(1).min(255)
+    } as u8;
 
     fi.refresh_frame_flags =
       if fi.frame_type == FrameType::KEY { ALL_REF_FRAMES_MASK } else { 1 };
     fi.intra_only = fi.frame_type == FrameType::KEY
       || fi.frame_type == FrameType::INTRA_ONLY;
-    fi.primary_ref_frame =
-      if fi.intra_only || fi.error_resilient { PRIMARY_REF_NONE } else { (LAST_FRAME - LAST_FRAME) as u32 };
+    fi.primary_ref_frame = if fi.intra_only || fi.error_resilient {
+      PRIMARY_REF_NONE
+    } else {
+      (LAST_FRAME - LAST_FRAME) as u32
+    };
 
     if !process_frame(
       &mut sequence,
diff --git a/src/bin/rav1repl.rs b/src/bin/rav1repl.rs
index cae2c40b..efcb1942 100644
--- a/src/bin/rav1repl.rs
+++ b/src/bin/rav1repl.rs
@@ -7,9 +7,9 @@
 // Media Patent License 1.0 was not distributed with this source code in the
 // PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 
+extern crate clap;
 extern crate rustyline;
 extern crate y4m;
-extern crate clap;
 
 extern crate rav1e;
 
diff --git a/src/ec.rs b/src/ec.rs
index 264c60a8..430bafba 100644
--- a/src/ec.rs
+++ b/src/ec.rs
@@ -14,8 +14,8 @@
 #![cfg_attr(feature = "cargo-clippy", allow(needless_range_loop))]
 
 use bitstream_io::{BitWriter, BE};
-use util::ILog;
 use std;
+use util::ILog;
 
 pub const OD_BITRES: u8 = 3;
 const EC_PROB_SHIFT: u32 = 6;
@@ -99,7 +99,7 @@ pub struct WriterEncoder {
   /// A buffer for output bytes with their associated carry flags.
   precarry: Vec<u16>,
   /// The low end of the current range.
-  low: ec_window,
+  low: ec_window
 }
 
 #[derive(Clone)]
@@ -111,35 +111,27 @@ pub struct WriterCheckpoint {
   /// Saved number of values in the current range.
   rng: u16,
   /// Saved number of bits of data in the current value.
-  cnt: i16,
+  cnt: i16
 }
 
 /// Constructor for a counting Writer
 impl WriterCounter {
-  pub fn new () -> WriterBase<WriterCounter> {
-    WriterBase::new(WriterCounter {
-      bytes: 0
-    })
+  pub fn new() -> WriterBase<WriterCounter> {
+    WriterBase::new(WriterCounter { bytes: 0 })
   }
 }
 
 /// Constructor for a recording Writer
 impl WriterRecorder {
-  pub fn new () -> WriterBase<WriterRecorder> {
-    WriterBase::new(WriterRecorder {
-      storage: Vec::new(),
-      bytes: 0
-    })
+  pub fn new() -> WriterBase<WriterRecorder> {
+    WriterBase::new(WriterRecorder { storage: Vec::new(), bytes: 0 })
   }
 }
 
 /// Constructor for a encoding Writer
 impl WriterEncoder {
-  pub fn new () -> WriterBase<WriterEncoder> {
-    WriterBase::new(WriterEncoder {
-      precarry: Vec::new(),
-      low: 0
-    })
+  pub fn new() -> WriterBase<WriterEncoder> {
+    WriterBase::new(WriterEncoder { precarry: Vec::new(), low: 0 })
   }
 }
 
@@ -165,14 +157,14 @@ impl StorageBackend for WriterBase<WriterCounter> {
     self.cnt = s;
   }
   fn stream_bytes(&mut self) -> usize {
-      self.s.bytes
+    self.s.bytes
   }
   fn checkpoint(&mut self) -> WriterCheckpoint {
     WriterCheckpoint {
       stream_bytes: self.s.bytes,
       backend_var: 0,
       rng: self.rng,
-      cnt: self.cnt,
+      cnt: self.cnt
     }
   }
   fn rollback(&mut self, checkpoint: &WriterCheckpoint) {
@@ -207,14 +199,14 @@ impl StorageBackend for WriterBase<WriterRecorder> {
     self.s.storage.push((fl, fh, nms));
   }
   fn stream_bytes(&mut self) -> usize {
-      self.s.bytes
+    self.s.bytes
   }
   fn checkpoint(&mut self) -> WriterCheckpoint {
     WriterCheckpoint {
       stream_bytes: self.s.bytes,
       backend_var: self.s.storage.len(),
       rng: self.rng,
-      cnt: self.cnt,
+      cnt: self.cnt
     }
   }
   fn rollback(&mut self, checkpoint: &WriterCheckpoint) {
@@ -255,14 +247,14 @@ impl StorageBackend for WriterBase<WriterEncoder> {
     self.cnt = s;
   }
   fn stream_bytes(&mut self) -> usize {
-      self.s.precarry.len()
+    self.s.precarry.len()
   }
   fn checkpoint(&mut self) -> WriterCheckpoint {
     WriterCheckpoint {
-        stream_bytes: self.s.precarry.len(),
-        backend_var: self.s.low as usize,
-        rng: self.rng,
-        cnt: self.cnt,
+      stream_bytes: self.s.precarry.len(),
+      backend_var: self.s.low as usize,
+      rng: self.rng,
+      cnt: self.cnt
     }
   }
   fn rollback(&mut self, checkpoint: &WriterCheckpoint) {
@@ -275,33 +267,28 @@ impl StorageBackend for WriterBase<WriterEncoder> {
 
 /// A few local helper functions needed by the Writer that are not
 /// part of the public interface.
-impl<S> WriterBase<S>{
+impl<S> WriterBase<S> {
   /// Internal constructor called by the subtypes that implement the
   /// actual encoder and Recorder.
   fn new(storage: S) -> Self {
-    WriterBase {
-      rng: 0x8000,
-      cnt: -9,
-      debug: false,
-      s: storage
-    }
+    WriterBase { rng: 0x8000, cnt: -9, debug: false, s: storage }
   }
   /// Compute low and range values from token cdf values and local state
-  fn lr_compute (&mut self, fl: u16, fh: u16, nms: u16) -> (ec_window, u16){
+  fn lr_compute(&mut self, fl: u16, fh: u16, nms: u16) -> (ec_window, u16) {
     let u: u32;
     let v: u32;
     let mut r = self.rng as u32;
     debug_assert!(32768 <= r);
     if fl < 32768 {
       u = (((r >> 8) * (fl as u32 >> EC_PROB_SHIFT)) >> (7 - EC_PROB_SHIFT))
-            + EC_MIN_PROB * nms as u32;
+        + EC_MIN_PROB * nms as u32;
       v = (((r >> 8) * (fh as u32 >> EC_PROB_SHIFT)) >> (7 - EC_PROB_SHIFT))
-            + EC_MIN_PROB * (nms - 1) as u32;
+        + EC_MIN_PROB * (nms - 1) as u32;
       (r - u, (u - v) as u16)
     } else {
-        r -= (((r >> 8) * (fh as u32 >> EC_PROB_SHIFT)) >> (7 - EC_PROB_SHIFT))
-            + EC_MIN_PROB * (nms - 1) as u32;
-        (0, r as u16)
+      r -= (((r >> 8) * (fh as u32 >> EC_PROB_SHIFT)) >> (7 - EC_PROB_SHIFT))
+        + EC_MIN_PROB * (nms - 1) as u32;
+      (0, r as u16)
     }
   }
   /// Given the current total integer number of bits used and the current value of
@@ -441,14 +428,17 @@ impl WriterBase<WriterEncoder> {
 }
 
 /// Generic/shared implementation for Writers with StorageBackends (ie, Encoders and Recorders)
-impl<S> Writer for WriterBase<S> where WriterBase<S>: StorageBackend {
+impl<S> Writer for WriterBase<S>
+where
+  WriterBase<S>: StorageBackend
+{
   /// Encode a single binary value.
   /// `val`: The value to encode (0 or 1).
   /// `f`: The probability that the val is one, scaled by 32768.
   fn bool(&mut self, val: bool, f: u16) {
     debug_assert!(0 < f);
     debug_assert!(f < 32768);
-    self.symbol(if val {1} else {0}, &[f, 0]);
+    self.symbol(if val { 1 } else { 0 }, &[f, 0]);
   }
   /// Encode a single boolean value.
   /// `val`: The value to encode (false or true).
@@ -473,7 +463,7 @@ impl<S> Writer for WriterBase<S> where WriterBase<S>: StorageBackend {
   ///       must be exactly 32768. There should be at most 16 values.
   fn symbol(&mut self, s: u32, cdf: &[u16]) {
     debug_assert!(cdf[cdf.len() - 1] == 0);
-    let nms =  cdf.len() - s as usize;
+    let nms = cdf.len() - s as usize;
     let fl = if s > 0 { cdf[s as usize - 1] } else { 32768 };
     let fh = cdf[s as usize];
     debug_assert!(fh <= fl);
@@ -546,13 +536,13 @@ impl<S> Writer for WriterBase<S> where WriterBase<S>: StorageBackend {
   /// be restored later.  A WriterCheckpoint can be generated for an
   /// Encoder or Recorder, but can only be used to rollback the Writer
   /// instance from which it was generated.
-  fn checkpoint (&mut self) -> WriterCheckpoint {
+  fn checkpoint(&mut self) -> WriterCheckpoint {
     StorageBackend::checkpoint(self)
   }
   /// Roll back a given Writer to the state saved in the WriterCheckpoint
   /// 'wc': Saved Writer state/posiiton to restore
-  fn rollback (&mut self, wc: &WriterCheckpoint) {
-    StorageBackend::rollback(self,wc)
+  fn rollback(&mut self, wc: &WriterCheckpoint) {
+    StorageBackend::rollback(self, wc)
   }
 }
 
diff --git a/src/encoder.rs b/src/encoder.rs
index 2ad98b61..b92f879e 100644
--- a/src/encoder.rs
+++ b/src/encoder.rs
@@ -1,21 +1,20 @@
-
+use cdef::*;
 use context::*;
+use deblock::*;
+use ec::*;
 use partition::*;
-use transform::*;
-use quantize::*;
 use plane::*;
+use quantize::*;
 use rdo::*;
-use ec::*;
 use std::fmt;
+use transform::*;
 use util::*;
-use deblock::*;
-use cdef::*;
 
-use bitstream_io::{BE, LE, BitWriter};
-use std::rc::Rc;
-use std::io::*;
-use std::io;
+use bitstream_io::{BitWriter, BE, LE};
 use std;
+use std::io;
+use std::io::*;
+use std::rc::Rc;
 
 extern {
     pub fn av1_rtcd();
@@ -48,7 +47,7 @@ impl Frame {
 #[derive(Debug, Clone)]
 pub struct ReferenceFrame {
   pub frame: Frame,
-  pub cdfs: CDFContext,
+  pub cdfs: CDFContext
 }
 
 #[derive(Debug)]
diff --git a/src/me.rs b/src/me.rs
index 2c1b4c94..0d086485 100644
--- a/src/me.rs
+++ b/src/me.rs
@@ -7,22 +7,29 @@
 // Media Patent License 1.0 was not distributed with this source code in the
 // PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 
-use FrameInvariants;
-use FrameState;
-use partition::*;
 use context::BlockOffset;
-use plane::*;
 use context::BLOCK_TO_PLANE_SHIFT;
+use partition::*;
+use plane::*;
+use FrameInvariants;
+use FrameState;
 
 #[inline(always)]
-pub fn get_sad(plane_org: &mut PlaneSlice, plane_ref: &mut PlaneSlice, blk_h: usize, blk_w: usize) -> u32 {
+pub fn get_sad(
+  plane_org: &mut PlaneSlice, plane_ref: &mut PlaneSlice, blk_h: usize,
+  blk_w: usize
+) -> u32 {
   let mut sum = 0 as u32;
 
   for _r in 0..blk_h {
     {
       let slice_org = plane_org.as_slice_w_width(blk_w);
       let slice_ref = plane_ref.as_slice_w_width(blk_w);
-      sum += slice_org.iter().zip(slice_ref).map(|(&a, &b)| (a as i32 - b as i32).abs() as u32).sum::<u32>();
+      sum += slice_org
+        .iter()
+        .zip(slice_ref)
+        .map(|(&a, &b)| (a as i32 - b as i32).abs() as u32)
+        .sum::<u32>();
     }
     plane_org.y += 1;
     plane_ref.y += 1;
diff --git a/src/partition.rs b/src/partition.rs
index 2fbcefa7..0ebd1995 100755
--- a/src/partition.rs
+++ b/src/partition.rs
@@ -24,15 +24,15 @@ pub const BWDREF_FRAME: usize = 5;
 pub const ALTREF2_FRAME: usize = 6;
 pub const ALTREF_FRAME: usize = 7;
 
-pub const LAST_LAST2_FRAMES: usize = 0;      // { LAST_FRAME, LAST2_FRAME }
-pub const LAST_LAST3_FRAMES: usize = 1;      // { LAST_FRAME, LAST3_FRAME }
-pub const LAST_GOLDEN_FRAMES: usize = 2;     // { LAST_FRAME, GOLDEN_FRAME }
-pub const BWDREF_ALTREF_FRAMES: usize = 3;   // { BWDREF_FRAME, ALTREF_FRAME }
-pub const LAST2_LAST3_FRAMES: usize = 4;     // { LAST2_FRAME, LAST3_FRAME }
-pub const LAST2_GOLDEN_FRAMES: usize = 5;    // { LAST2_FRAME, GOLDEN_FRAME }
-pub const LAST3_GOLDEN_FRAMES: usize = 6;    // { LAST3_FRAME, GOLDEN_FRAME }
-pub const BWDREF_ALTREF2_FRAMES: usize = 7;  // { BWDREF_FRAME, ALTREF2_FRAME }
-pub const ALTREF2_ALTREF_FRAMES: usize = 8;  // { ALTREF2_FRAME, ALTREF_FRAME }
+pub const LAST_LAST2_FRAMES: usize = 0; // { LAST_FRAME, LAST2_FRAME }
+pub const LAST_LAST3_FRAMES: usize = 1; // { LAST_FRAME, LAST3_FRAME }
+pub const LAST_GOLDEN_FRAMES: usize = 2; // { LAST_FRAME, GOLDEN_FRAME }
+pub const BWDREF_ALTREF_FRAMES: usize = 3; // { BWDREF_FRAME, ALTREF_FRAME }
+pub const LAST2_LAST3_FRAMES: usize = 4; // { LAST2_FRAME, LAST3_FRAME }
+pub const LAST2_GOLDEN_FRAMES: usize = 5; // { LAST2_FRAME, GOLDEN_FRAME }
+pub const LAST3_GOLDEN_FRAMES: usize = 6; // { LAST3_FRAME, GOLDEN_FRAME }
+pub const BWDREF_ALTREF2_FRAMES: usize = 7; // { BWDREF_FRAME, ALTREF2_FRAME }
+pub const ALTREF2_ALTREF_FRAMES: usize = 8; // { ALTREF2_FRAME, ALTREF_FRAME }
 pub const TOTAL_UNIDIR_COMP_REFS: usize = 9;
 
 // NOTE: UNIDIR_COMP_REFS is the number of uni-directional reference pairs
@@ -44,7 +44,8 @@ pub const BWD_REFS: usize = ALTREF_FRAME - BWDREF_FRAME + 1;
 pub const SINGLE_REFS: usize = FWD_REFS + BWD_REFS;
 pub const TOTAL_REFS_PER_FRAME: usize = ALTREF_FRAME - INTRA_FRAME + 1;
 pub const INTER_REFS_PER_FRAME: usize = ALTREF_FRAME - LAST_FRAME + 1;
-pub const TOTAL_COMP_REFS: usize = FWD_REFS * BWD_REFS + TOTAL_UNIDIR_COMP_REFS;
+pub const TOTAL_COMP_REFS: usize =
+  FWD_REFS * BWD_REFS + TOTAL_UNIDIR_COMP_REFS;
 
 pub const REF_FRAMES_LOG2: usize = 3;
 pub const REF_FRAMES: usize = 1 << REF_FRAMES_LOG2;
@@ -58,12 +59,12 @@ pub enum PartitionType {
   PARTITION_HORZ,
   PARTITION_VERT,
   PARTITION_SPLIT,
-  PARTITION_HORZ_A,  // HORZ split and the top partition is split again
-  PARTITION_HORZ_B,  // HORZ split and the bottom partition is split again
-  PARTITION_VERT_A,  // VERT split and the left partition is split again
-  PARTITION_VERT_B,  // VERT split and the right partition is split again
-  PARTITION_HORZ_4,  // 4:1 horizontal partition
-  PARTITION_VERT_4,  // 4:1 vertical partition
+  PARTITION_HORZ_A, // HORZ split and the top partition is split again
+  PARTITION_HORZ_B, // HORZ split and the bottom partition is split again
+  PARTITION_VERT_A, // VERT split and the left partition is split again
+  PARTITION_VERT_B, // VERT split and the right partition is split again
+  PARTITION_HORZ_4, // 4:1 horizontal partition
+  PARTITION_VERT_4, // 4:1 vertical partition
   PARTITION_INVALID
 }
 
@@ -105,11 +106,15 @@ impl BlockSize {
   const BLOCK_SIZE_HEIGHT_LOG2: [usize; BlockSize::BLOCK_SIZES_ALL] =
     [2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 4, 2, 5, 3, 6, 4, 7, 5];
 
-  pub const MI_SIZE_WIDE: [usize; BlockSize::BLOCK_SIZES_ALL] =
-    [1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 1, 4, 2, 8, 4, 16, 8, 32];
+  pub const MI_SIZE_WIDE: [usize; BlockSize::BLOCK_SIZES_ALL] = [
+    1, 1, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 1, 4, 2, 8, 4, 16, 8,
+    32,
+  ];
 
-  pub const MI_SIZE_HIGH: [usize; BlockSize::BLOCK_SIZES_ALL] =
-    [1, 2, 1, 2, 4, 2, 4, 8, 4, 8, 16, 8, 16, 32, 16, 32, 4, 1, 8, 2, 16, 4, 32, 8];
+  pub const MI_SIZE_HIGH: [usize; BlockSize::BLOCK_SIZES_ALL] = [
+    1, 2, 1, 2, 4, 2, 4, 8, 4, 8, 16, 8, 16, 32, 16, 32, 4, 1, 8, 2, 16, 4,
+    32, 8,
+  ];
 
   pub fn cfl_allowed(self) -> bool {
     // TODO: fix me when enabling EXT_PARTITION_TYPES
@@ -356,7 +361,7 @@ pub enum PredictionMode {
 #[derive(Copy, Clone)]
 pub struct MotionVector {
   pub row: i16,
-  pub col: i16,
+  pub col: i16
 }
 
 pub const NEWMV_MODE_CONTEXTS: usize = 7;
@@ -366,7 +371,8 @@ pub const REFMV_MODE_CONTEXTS: usize = 9;
 pub const REFMV_OFFSET: usize = 4;
 pub const GLOBALMV_OFFSET: usize = 3;
 pub const NEWMV_CTX_MASK: usize = ((1 << GLOBALMV_OFFSET) - 1);
-pub const GLOBALMV_CTX_MASK: usize = ((1 << (REFMV_OFFSET - GLOBALMV_OFFSET)) - 1);
+pub const GLOBALMV_CTX_MASK: usize =
+  ((1 << (REFMV_OFFSET - GLOBALMV_OFFSET)) - 1);
 pub const REFMV_CTX_MASK: usize = ((1 << (8 - REFMV_OFFSET)) - 1);
 
 pub static RAV1E_PARTITION_TYPES: &'static [PartitionType] =
@@ -394,81 +400,129 @@ pub enum GlobalMVMode {
 pub enum MvSubpelPrecision {
   MV_SUBPEL_NONE = -1,
   MV_SUBPEL_LOW_PRECISION = 0,
-  MV_SUBPEL_HIGH_PRECISION,
+  MV_SUBPEL_HIGH_PRECISION
 }
 
 const SUBPEL_FILTERS: [[[i32; 8]; 16]; 6] = [
   [
-    [ 0, 0, 0, 128, 0, 0, 0, 0 ],      [ 0, 2, -6, 126, 8, -2, 0, 0 ],
-    [ 0, 2, -10, 122, 18, -4, 0, 0 ],  [ 0, 2, -12, 116, 28, -8, 2, 0 ],
-    [ 0, 2, -14, 110, 38, -10, 2, 0 ], [ 0, 2, -14, 102, 48, -12, 2, 0 ],
-    [ 0, 2, -16, 94, 58, -12, 2, 0 ],  [ 0, 2, -14, 84, 66, -12, 2, 0 ],
-    [ 0, 2, -14, 76, 76, -14, 2, 0 ],  [ 0, 2, -12, 66, 84, -14, 2, 0 ],
-    [ 0, 2, -12, 58, 94, -16, 2, 0 ],  [ 0, 2, -12, 48, 102, -14, 2, 0 ],
-    [ 0, 2, -10, 38, 110, -14, 2, 0 ], [ 0, 2, -8, 28, 116, -12, 2, 0 ],
-    [ 0, 0, -4, 18, 122, -10, 2, 0 ],  [ 0, 0, -2, 8, 126, -6, 2, 0 ]
+    [0, 0, 0, 128, 0, 0, 0, 0],
+    [0, 2, -6, 126, 8, -2, 0, 0],
+    [0, 2, -10, 122, 18, -4, 0, 0],
+    [0, 2, -12, 116, 28, -8, 2, 0],
+    [0, 2, -14, 110, 38, -10, 2, 0],
+    [0, 2, -14, 102, 48, -12, 2, 0],
+    [0, 2, -16, 94, 58, -12, 2, 0],
+    [0, 2, -14, 84, 66, -12, 2, 0],
+    [0, 2, -14, 76, 76, -14, 2, 0],
+    [0, 2, -12, 66, 84, -14, 2, 0],
+    [0, 2, -12, 58, 94, -16, 2, 0],
+    [0, 2, -12, 48, 102, -14, 2, 0],
+    [0, 2, -10, 38, 110, -14, 2, 0],
+    [0, 2, -8, 28, 116, -12, 2, 0],
+    [0, 0, -4, 18, 122, -10, 2, 0],
+    [0, 0, -2, 8, 126, -6, 2, 0]
   ],
   [
-    [ 0, 0, 0, 128, 0, 0, 0, 0 ],     [ 0, 2, 28, 62, 34, 2, 0, 0 ],
-    [ 0, 0, 26, 62, 36, 4, 0, 0 ],    [ 0, 0, 22, 62, 40, 4, 0, 0 ],
-    [ 0, 0, 20, 60, 42, 6, 0, 0 ],    [ 0, 0, 18, 58, 44, 8, 0, 0 ],
-    [ 0, 0, 16, 56, 46, 10, 0, 0 ],   [ 0, -2, 16, 54, 48, 12, 0, 0 ],
-    [ 0, -2, 14, 52, 52, 14, -2, 0 ], [ 0, 0, 12, 48, 54, 16, -2, 0 ],
-    [ 0, 0, 10, 46, 56, 16, 0, 0 ],   [ 0, 0, 8, 44, 58, 18, 0, 0 ],
-    [ 0, 0, 6, 42, 60, 20, 0, 0 ],    [ 0, 0, 4, 40, 62, 22, 0, 0 ],
-    [ 0, 0, 4, 36, 62, 26, 0, 0 ],    [ 0, 0, 2, 34, 62, 28, 2, 0 ]
+    [0, 0, 0, 128, 0, 0, 0, 0],
+    [0, 2, 28, 62, 34, 2, 0, 0],
+    [0, 0, 26, 62, 36, 4, 0, 0],
+    [0, 0, 22, 62, 40, 4, 0, 0],
+    [0, 0, 20, 60, 42, 6, 0, 0],
+    [0, 0, 18, 58, 44, 8, 0, 0],
+    [0, 0, 16, 56, 46, 10, 0, 0],
+    [0, -2, 16, 54, 48, 12, 0, 0],
+    [0, -2, 14, 52, 52, 14, -2, 0],
+    [0, 0, 12, 48, 54, 16, -2, 0],
+    [0, 0, 10, 46, 56, 16, 0, 0],
+    [0, 0, 8, 44, 58, 18, 0, 0],
+    [0, 0, 6, 42, 60, 20, 0, 0],
+    [0, 0, 4, 40, 62, 22, 0, 0],
+    [0, 0, 4, 36, 62, 26, 0, 0],
+    [0, 0, 2, 34, 62, 28, 2, 0]
   ],
   [
-    [ 0, 0, 0, 128, 0, 0, 0, 0 ],         [ -2, 2, -6, 126, 8, -2, 2, 0 ],
-    [ -2, 6, -12, 124, 16, -6, 4, -2 ],   [ -2, 8, -18, 120, 26, -10, 6, -2 ],
-    [ -4, 10, -22, 116, 38, -14, 6, -2 ], [ -4, 10, -22, 108, 48, -18, 8, -2 ],
-    [ -4, 10, -24, 100, 60, -20, 8, -2 ], [ -4, 10, -24, 90, 70, -22, 10, -2 ],
-    [ -4, 12, -24, 80, 80, -24, 12, -4 ], [ -2, 10, -22, 70, 90, -24, 10, -4 ],
-    [ -2, 8, -20, 60, 100, -24, 10, -4 ], [ -2, 8, -18, 48, 108, -22, 10, -4 ],
-    [ -2, 6, -14, 38, 116, -22, 10, -4 ], [ -2, 6, -10, 26, 120, -18, 8, -2 ],
-    [ -2, 4, -6, 16, 124, -12, 6, -2 ],   [ 0, 2, -2, 8, 126, -6, 2, -2 ]
+    [0, 0, 0, 128, 0, 0, 0, 0],
+    [-2, 2, -6, 126, 8, -2, 2, 0],
+    [-2, 6, -12, 124, 16, -6, 4, -2],
+    [-2, 8, -18, 120, 26, -10, 6, -2],
+    [-4, 10, -22, 116, 38, -14, 6, -2],
+    [-4, 10, -22, 108, 48, -18, 8, -2],
+    [-4, 10, -24, 100, 60, -20, 8, -2],
+    [-4, 10, -24, 90, 70, -22, 10, -2],
+    [-4, 12, -24, 80, 80, -24, 12, -4],
+    [-2, 10, -22, 70, 90, -24, 10, -4],
+    [-2, 8, -20, 60, 100, -24, 10, -4],
+    [-2, 8, -18, 48, 108, -22, 10, -4],
+    [-2, 6, -14, 38, 116, -22, 10, -4],
+    [-2, 6, -10, 26, 120, -18, 8, -2],
+    [-2, 4, -6, 16, 124, -12, 6, -2],
+    [0, 2, -2, 8, 126, -6, 2, -2]
   ],
   [
-    [ 0, 0, 0, 128, 0, 0, 0, 0 ],  [ 0, 0, 0, 120, 8, 0, 0, 0 ],
-    [ 0, 0, 0, 112, 16, 0, 0, 0 ], [ 0, 0, 0, 104, 24, 0, 0, 0 ],
-    [ 0, 0, 0, 96, 32, 0, 0, 0 ],  [ 0, 0, 0, 88, 40, 0, 0, 0 ],
-    [ 0, 0, 0, 80, 48, 0, 0, 0 ],  [ 0, 0, 0, 72, 56, 0, 0, 0 ],
-    [ 0, 0, 0, 64, 64, 0, 0, 0 ],  [ 0, 0, 0, 56, 72, 0, 0, 0 ],
-    [ 0, 0, 0, 48, 80, 0, 0, 0 ],  [ 0, 0, 0, 40, 88, 0, 0, 0 ],
-    [ 0, 0, 0, 32, 96, 0, 0, 0 ],  [ 0, 0, 0, 24, 104, 0, 0, 0 ],
-    [ 0, 0, 0, 16, 112, 0, 0, 0 ], [ 0, 0, 0, 8, 120, 0, 0, 0 ]
+    [0, 0, 0, 128, 0, 0, 0, 0],
+    [0, 0, 0, 120, 8, 0, 0, 0],
+    [0, 0, 0, 112, 16, 0, 0, 0],
+    [0, 0, 0, 104, 24, 0, 0, 0],
+    [0, 0, 0, 96, 32, 0, 0, 0],
+    [0, 0, 0, 88, 40, 0, 0, 0],
+    [0, 0, 0, 80, 48, 0, 0, 0],
+    [0, 0, 0, 72, 56, 0, 0, 0],
+    [0, 0, 0, 64, 64, 0, 0, 0],
+    [0, 0, 0, 56, 72, 0, 0, 0],
+    [0, 0, 0, 48, 80, 0, 0, 0],
+    [0, 0, 0, 40, 88, 0, 0, 0],
+    [0, 0, 0, 32, 96, 0, 0, 0],
+    [0, 0, 0, 24, 104, 0, 0, 0],
+    [0, 0, 0, 16, 112, 0, 0, 0],
+    [0, 0, 0, 8, 120, 0, 0, 0]
   ],
   [
-    [ 0, 0, 0, 128, 0, 0, 0, 0 ],     [ 0, 0, -4, 126, 8, -2, 0, 0 ],
-    [ 0, 0, -8, 122, 18, -4, 0, 0 ],  [ 0, 0, -10, 116, 28, -6, 0, 0 ],
-    [ 0, 0, -12, 110, 38, -8, 0, 0 ], [ 0, 0, -12, 102, 48, -10, 0, 0 ],
-    [ 0, 0, -14, 94, 58, -10, 0, 0 ], [ 0, 0, -12, 84, 66, -10, 0, 0 ],
-    [ 0, 0, -12, 76, 76, -12, 0, 0 ], [ 0, 0, -10, 66, 84, -12, 0, 0 ],
-    [ 0, 0, -10, 58, 94, -14, 0, 0 ], [ 0, 0, -10, 48, 102, -12, 0, 0 ],
-    [ 0, 0, -8, 38, 110, -12, 0, 0 ], [ 0, 0, -6, 28, 116, -10, 0, 0 ],
-    [ 0, 0, -4, 18, 122, -8, 0, 0 ],  [ 0, 0, -2, 8, 126, -4, 0, 0 ]
+    [0, 0, 0, 128, 0, 0, 0, 0],
+    [0, 0, -4, 126, 8, -2, 0, 0],
+    [0, 0, -8, 122, 18, -4, 0, 0],
+    [0, 0, -10, 116, 28, -6, 0, 0],
+    [0, 0, -12, 110, 38, -8, 0, 0],
+    [0, 0, -12, 102, 48, -10, 0, 0],
+    [0, 0, -14, 94, 58, -10, 0, 0],
+    [0, 0, -12, 84, 66, -10, 0, 0],
+    [0, 0, -12, 76, 76, -12, 0, 0],
+    [0, 0, -10, 66, 84, -12, 0, 0],
+    [0, 0, -10, 58, 94, -14, 0, 0],
+    [0, 0, -10, 48, 102, -12, 0, 0],
+    [0, 0, -8, 38, 110, -12, 0, 0],
+    [0, 0, -6, 28, 116, -10, 0, 0],
+    [0, 0, -4, 18, 122, -8, 0, 0],
+    [0, 0, -2, 8, 126, -4, 0, 0]
   ],
   [
-    [ 0, 0, 0, 128, 0, 0, 0, 0 ],   [ 0, 0, 30, 62, 34, 2, 0, 0 ],
-    [ 0, 0, 26, 62, 36, 4, 0, 0 ],  [ 0, 0, 22, 62, 40, 4, 0, 0 ],
-    [ 0, 0, 20, 60, 42, 6, 0, 0 ],  [ 0, 0, 18, 58, 44, 8, 0, 0 ],
-    [ 0, 0, 16, 56, 46, 10, 0, 0 ], [ 0, 0, 14, 54, 48, 12, 0, 0 ],
-    [ 0, 0, 12, 52, 52, 12, 0, 0 ], [ 0, 0, 12, 48, 54, 14, 0, 0 ],
-    [ 0, 0, 10, 46, 56, 16, 0, 0 ], [ 0, 0, 8, 44, 58, 18, 0, 0 ],
-    [ 0, 0, 6, 42, 60, 20, 0, 0 ],  [ 0, 0, 4, 40, 62, 22, 0, 0 ],
-    [ 0, 0, 4, 36, 62, 26, 0, 0 ],  [ 0, 0, 2, 34, 62, 30, 0, 0 ]
+    [0, 0, 0, 128, 0, 0, 0, 0],
+    [0, 0, 30, 62, 34, 2, 0, 0],
+    [0, 0, 26, 62, 36, 4, 0, 0],
+    [0, 0, 22, 62, 40, 4, 0, 0],
+    [0, 0, 20, 60, 42, 6, 0, 0],
+    [0, 0, 18, 58, 44, 8, 0, 0],
+    [0, 0, 16, 56, 46, 10, 0, 0],
+    [0, 0, 14, 54, 48, 12, 0, 0],
+    [0, 0, 12, 52, 52, 12, 0, 0],
+    [0, 0, 12, 48, 54, 14, 0, 0],
+    [0, 0, 10, 46, 56, 16, 0, 0],
+    [0, 0, 8, 44, 58, 18, 0, 0],
+    [0, 0, 6, 42, 60, 20, 0, 0],
+    [0, 0, 4, 40, 62, 22, 0, 0],
+    [0, 0, 4, 36, 62, 26, 0, 0],
+    [0, 0, 2, 34, 62, 30, 0, 0]
   ]
 ];
 
 /* Symbols for coding which components are zero jointly */
-pub const MV_JOINTS:usize = 4;
+pub const MV_JOINTS: usize = 4;
 
 #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
 pub enum MvJointType {
   MV_JOINT_ZERO = 0,   /* Zero vector */
   MV_JOINT_HNZVZ = 1,  /* Vert zero, hor nonzero */
   MV_JOINT_HZVNZ = 2,  /* Hor zero, vert nonzero */
-  MV_JOINT_HNZVNZ = 3, /* Both components nonzero */
+  MV_JOINT_HNZVNZ = 3  /* Both components nonzero */
 }
 
 use context::*;
@@ -497,8 +551,8 @@ impl PredictionMode {
 
   #[inline(always)]
   fn predict_intra_inner<'a, B: Intra>(
-    self, dst: &'a mut PlaneMutSlice<'a>, bit_depth: usize,
-    ac: &[i16], alpha: i16
+    self, dst: &'a mut PlaneMutSlice<'a>, bit_depth: usize, ac: &[i16],
+    alpha: i16
   ) {
     // above and left arrays include above-left sample
     // above array includes above-right samples
@@ -506,8 +560,10 @@ impl PredictionMode {
     let bd = bit_depth;
     let base = 128 << (bd - 8);
 
-    let above = &mut [(base - 1) as u16; 2 * MAX_TX_SIZE + 1][..B::W + B::H + 1];
-    let left = &mut [(base + 1) as u16; 2 * MAX_TX_SIZE + 1][..B::H + B::W + 1];
+    let above =
+      &mut [(base - 1) as u16; 2 * MAX_TX_SIZE + 1][..B::W + B::H + 1];
+    let left =
+      &mut [(base + 1) as u16; 2 * MAX_TX_SIZE + 1][..B::H + B::W + 1];
 
     let stride = dst.plane.cfg.stride;
     let x = dst.x;
@@ -540,10 +596,11 @@ impl PredictionMode {
       above[0] = dst.go_up(1).go_left(1).p(0, 0);
     }
 
-    if self == PredictionMode::SMOOTH_H_PRED ||
-      self == PredictionMode::SMOOTH_V_PRED ||
-      self == PredictionMode::SMOOTH_PRED ||
-      self == PredictionMode::PAETH_PRED {
+    if self == PredictionMode::SMOOTH_H_PRED
+      || self == PredictionMode::SMOOTH_V_PRED
+      || self == PredictionMode::SMOOTH_PRED
+      || self == PredictionMode::PAETH_PRED
+    {
       if x == 0 && y != 0 {
         for i in 0..B::H {
           left[i + 1] = dst.go_up(1).p(0, 0);
@@ -576,8 +633,10 @@ impl PredictionMode {
     match self {
       PredictionMode::DC_PRED | PredictionMode::UV_CFL_PRED => match (x, y) {
         (0, 0) => B::pred_dc_128(slice, stride, bit_depth),
-        (_, 0) => B::pred_dc_left(slice, stride, above_slice, left_slice, bit_depth),
-        (0, _) => B::pred_dc_top(slice, stride, above_slice, left_slice, bit_depth),
+        (_, 0) =>
+          B::pred_dc_left(slice, stride, above_slice, left_slice, bit_depth),
+        (0, _) =>
+          B::pred_dc_top(slice, stride, above_slice, left_slice, bit_depth),
         _ => B::pred_dc(slice, stride, above_slice, left_slice)
       },
       PredictionMode::H_PRED => match (x, y) {
@@ -617,9 +676,11 @@ impl PredictionMode {
     self >= PredictionMode::V_PRED && self <= PredictionMode::D63_PRED
   }
 
-  pub fn predict_inter<'a>(self, fi: &FrameInvariants, p: usize, po: &PlaneOffset,
-                           dst: &'a mut PlaneMutSlice<'a>, width: usize, height: usize,
-                           ref_frame: usize, mv: &MotionVector, bit_depth: usize) {
+  pub fn predict_inter<'a>(
+    self, fi: &FrameInvariants, p: usize, po: &PlaneOffset,
+    dst: &'a mut PlaneMutSlice<'a>, width: usize, height: usize,
+    ref_frame: usize, mv: &MotionVector, bit_depth: usize
+  ) {
     assert!(!self.is_intra());
     assert!(ref_frame == LAST_FRAME);
 
@@ -630,8 +691,10 @@ impl PredictionMode {
         let shift_col = 3 + rec_cfg.xdec;
         let row_offset = mv.row as i32 >> shift_row;
         let col_offset = mv.col as i32 >> shift_col;
-        let row_frac = (mv.row as i32 - (row_offset << shift_row)) << (4 - shift_row);
-        let col_frac = (mv.col as i32 - (col_offset << shift_col)) << (4 - shift_col);
+        let row_frac =
+          (mv.row as i32 - (row_offset << shift_row)) << (4 - shift_row);
+        let col_frac =
+          (mv.col as i32 - (col_offset << shift_col)) << (4 - shift_col);
         let ref_stride = rec_cfg.stride;
 
         let stride = dst.plane.cfg.stride;
@@ -642,85 +705,101 @@ impl PredictionMode {
         let x_filter_idx = if width <= 4 { 4 } else { 0 };
 
         match (col_frac, row_frac) {
-        (0,0) => {
-          let qo = PlaneOffset { x: po.x + col_offset as isize, y: po.y + row_offset as isize };
-          let ps = rec.frame.planes[p].slice(&qo);
-          let s = ps.as_slice_clamped();
-          for r in 0..height {
-            for c in 0..width {
-              let output_index = r * stride + c;
-              slice[output_index] = s[r * ref_stride + c];
-            }
-          }
-        }
-        (0,_) => {
-          let qo = PlaneOffset { x: po.x + col_offset as isize, y: po.y + row_offset as isize - 3 };
-          let ps = rec.frame.planes[p].slice(&qo);
-          let s = ps.as_slice_clamped();
-          for r in 0..height {
-            for c in 0..width {
-              let mut sum: i32 = 0;
-              for k in 0..8 {
-                sum += s[(r + k) * ref_stride + c] as i32 * SUBPEL_FILTERS[y_filter_idx][row_frac as usize][k];
+          (0, 0) => {
+            let qo = PlaneOffset {
+              x: po.x + col_offset as isize,
+              y: po.y + row_offset as isize
+            };
+            let ps = rec.frame.planes[p].slice(&qo);
+            let s = ps.as_slice_clamped();
+            for r in 0..height {
+              for c in 0..width {
+                let output_index = r * stride + c;
+                slice[output_index] = s[r * ref_stride + c];
               }
-              let output_index = r * stride + c;
-              let val = ((sum + 64) >> 7).max(0).min(max_sample_val);
-              slice[output_index] = val as u16;
             }
           }
-        }
-        (_,0) => {
-          let qo = PlaneOffset { x: po.x + col_offset as isize - 3, y: po.y + row_offset as isize };
-          let ps = rec.frame.planes[p].slice(&qo);
-          let s = ps.as_slice_clamped();
-          for r in 0..height {
-            for c in 0..width {
-            let mut sum: i32 = 0;
-            for k in 0..8 {
-              sum += s[r * ref_stride + (c + k)] as i32 * SUBPEL_FILTERS[x_filter_idx][col_frac as usize][k];
-            }
-            let output_index = r * stride + c;
-            let val = ((((sum + 4) >> 3) + 8) >> 4).max(0).min(max_sample_val);
-            slice[output_index] = val as u16;
-            }
-          }
-        }
-        (_,_) => {
-          let mut intermediate = [0 as i16; 8 * (128 + 7)];
-
-          let qo = PlaneOffset { x: po.x + col_offset as isize - 3, y: po.y + row_offset as isize - 3 };
-          let ps = rec.frame.planes[p].slice(&qo);
-          let s = ps.as_slice_clamped();
-          for cg in (0..width).step_by(8) {
-            for r in 0..height+7 {
-              for c in cg..(cg+8).min(width) {
+          (0, _) => {
+            let qo = PlaneOffset {
+              x: po.x + col_offset as isize,
+              y: po.y + row_offset as isize - 3
+            };
+            let ps = rec.frame.planes[p].slice(&qo);
+            let s = ps.as_slice_clamped();
+            for r in 0..height {
+              for c in 0..width {
                 let mut sum: i32 = 0;
                 for k in 0..8 {
-                  sum += s[r * ref_stride + (c + k)] as i32 * SUBPEL_FILTERS[x_filter_idx][col_frac as usize][k];
+                  sum += s[(r + k) * ref_stride + c] as i32
+                    * SUBPEL_FILTERS[y_filter_idx][row_frac as usize][k];
                 }
-                let val = (sum + 4) >> 3;
-                intermediate[8 * r + (c - cg)] = val as i16;
+                let output_index = r * stride + c;
+                let val = ((sum + 64) >> 7).max(0).min(max_sample_val);
+                slice[output_index] = val as u16;
               }
             }
-
+          }
+          (_, 0) => {
+            let qo = PlaneOffset {
+              x: po.x + col_offset as isize - 3,
+              y: po.y + row_offset as isize
+            };
+            let ps = rec.frame.planes[p].slice(&qo);
+            let s = ps.as_slice_clamped();
             for r in 0..height {
-              for c in cg..(cg+8).min(width) {
+              for c in 0..width {
                 let mut sum: i32 = 0;
                 for k in 0..8 {
-                  sum += intermediate[8 * (r + k) + c - cg] as i32 * SUBPEL_FILTERS[y_filter_idx][row_frac as usize][k];
+                  sum += s[r * ref_stride + (c + k)] as i32
+                    * SUBPEL_FILTERS[x_filter_idx][col_frac as usize][k];
                 }
                 let output_index = r * stride + c;
-                let val = ((sum + 1024) >> 11).max(0).min(max_sample_val);
+                let val =
+                  ((((sum + 4) >> 3) + 8) >> 4).max(0).min(max_sample_val);
                 slice[output_index] = val as u16;
               }
             }
           }
+          (_, _) => {
+            let mut intermediate = [0 as i16; 8 * (128 + 7)];
+
+            let qo = PlaneOffset {
+              x: po.x + col_offset as isize - 3,
+              y: po.y + row_offset as isize - 3
+            };
+            let ps = rec.frame.planes[p].slice(&qo);
+            let s = ps.as_slice_clamped();
+            for cg in (0..width).step_by(8) {
+              for r in 0..height + 7 {
+                for c in cg..(cg + 8).min(width) {
+                  let mut sum: i32 = 0;
+                  for k in 0..8 {
+                    sum += s[r * ref_stride + (c + k)] as i32 * SUBPEL_FILTERS
+                      [x_filter_idx][col_frac as usize][k];
+                  }
+                  let val = (sum + 4) >> 3;
+                  intermediate[8 * r + (c - cg)] = val as i16;
+                }
+              }
+
+              for r in 0..height {
+                for c in cg..(cg + 8).min(width) {
+                  let mut sum: i32 = 0;
+                  for k in 0..8 {
+                    sum += intermediate[8 * (r + k) + c - cg] as i32
+                      * SUBPEL_FILTERS[y_filter_idx][row_frac as usize][k];
+                  }
+                  let output_index = r * stride + c;
+                  let val = ((sum + 1024) >> 11).max(0).min(max_sample_val);
+                  slice[output_index] = val as u16;
+                }
+              }
+            }
+          }
         }
       }
-      },
-      None => (),
+      None => ()
     }
-
   }
 }
 
diff --git a/src/plane.rs b/src/plane.rs
index 5d4e6e53..f6e26e12 100644
--- a/src/plane.rs
+++ b/src/plane.rs
@@ -44,14 +44,30 @@ impl Plane {
   /// Data alignment in bytes.
   const DATA_ALIGNMENT_LOG2: usize = 4;
 
-  pub fn new(width: usize, height: usize, xdec: usize, ydec: usize, xpad: usize, ypad: usize) -> Plane {
+  pub fn new(
+    width: usize, height: usize, xdec: usize, ydec: usize, xpad: usize,
+    ypad: usize
+  ) -> Plane {
     let xorigin = xpad.align_power_of_two(Plane::STRIDE_ALIGNMENT_LOG2 - 1);
     let yorigin = ypad;
-    let stride = (xorigin + width + xpad).align_power_of_two(Plane::STRIDE_ALIGNMENT_LOG2 - 1);
+    let stride = (xorigin + width + xpad)
+      .align_power_of_two(Plane::STRIDE_ALIGNMENT_LOG2 - 1);
     let alloc_height = yorigin + height + ypad;
     let data = vec![128u16; stride * alloc_height];
     assert!(is_aligned(data.as_ptr(), Plane::DATA_ALIGNMENT_LOG2));
-    Plane { data, cfg: PlaneConfig { stride, alloc_height, width, height, xdec, ydec, xorigin, yorigin } }
+    Plane {
+      data,
+      cfg: PlaneConfig {
+        stride,
+        alloc_height,
+        width,
+        height,
+        xdec,
+        ydec,
+        xorigin,
+        yorigin
+      }
+    }
   }
 
   pub fn pad(&mut self) {
@@ -61,38 +77,49 @@ impl Plane {
     let width = self.cfg.width;
     let height = self.cfg.height;
 
-
     if xorigin > 0 {
       for y in 0..height {
-        let mut ps = self.mut_slice(&PlaneOffset { x: -(xorigin as isize), y: y as isize });
+        let mut ps = self
+          .mut_slice(&PlaneOffset { x: -(xorigin as isize), y: y as isize });
         let s = ps.as_mut_slice_w_width(xorigin + 1);
         let fill_val = s[xorigin];
-        for val in s[..xorigin].iter_mut() { *val = fill_val; }
+        for val in s[..xorigin].iter_mut() {
+          *val = fill_val;
+        }
       }
     }
 
     if xorigin + width < stride {
       for y in 0..height {
-        let mut ps = self.mut_slice(&PlaneOffset { x: width as isize - 1, y: y as isize });
+        let mut ps = self
+          .mut_slice(&PlaneOffset { x: width as isize - 1, y: y as isize });
         let s = ps.as_mut_slice_w_width(stride - xorigin - width + 1);
         let fill_val = s[0];
-        for val in s[1..].iter_mut() { *val = fill_val; }
+        for val in s[1..].iter_mut() {
+          *val = fill_val;
+        }
       }
     }
 
     if yorigin > 0 {
-      let mut ps = self.mut_slice(&PlaneOffset { x: -(xorigin as isize), y: -(yorigin as isize) });
-      let (s1, s2) = ps.as_mut_slice().split_at_mut(yorigin*stride);
-      for y in 0 .. yorigin {
-        s1[y*stride..y*stride+stride].copy_from_slice(&s2[..stride]);
+      let mut ps = self.mut_slice(&PlaneOffset {
+        x: -(xorigin as isize),
+        y: -(yorigin as isize)
+      });
+      let (s1, s2) = ps.as_mut_slice().split_at_mut(yorigin * stride);
+      for y in 0..yorigin {
+        s1[y * stride..y * stride + stride].copy_from_slice(&s2[..stride]);
       }
     }
 
     if yorigin + height < self.cfg.alloc_height {
-      let mut ps = self.mut_slice(&PlaneOffset { x: -(xorigin as isize), y: height as isize - 1 });
+      let mut ps = self.mut_slice(&PlaneOffset {
+        x: -(xorigin as isize),
+        y: height as isize - 1
+      });
       let (s2, s1) = ps.as_mut_slice().split_at_mut(stride);
-      for y in 0 .. yorigin {
-        s1[y*stride..y*stride+stride].copy_from_slice(&s2[..stride]);
+      for y in 0..yorigin {
+        s1[y * stride..y * stride + stride].copy_from_slice(&s2[..stride]);
       }
     }
   }
@@ -106,7 +133,8 @@ impl Plane {
   }
 
   pub fn p(&self, x: usize, y: usize) -> u16 {
-    self.data[(y + self.cfg.yorigin) * self.cfg.stride + (x + self.cfg.xorigin)]
+    self.data
+      [(y + self.cfg.yorigin) * self.cfg.stride + (x + self.cfg.xorigin)]
   }
 
   pub fn data_origin(&self) -> &[u16] {
@@ -121,8 +149,10 @@ impl Plane {
     &mut self, source: &[u8], source_stride: usize, source_bytewidth: usize
   ) {
     let stride = self.cfg.stride;
-    for (self_row, source_row) in
-      self.data_origin_mut().chunks_mut(stride).zip(source.chunks(source_stride))
+    for (self_row, source_row) in self
+      .data_origin_mut()
+      .chunks_mut(stride)
+      .zip(source.chunks(source_stride))
     {
       match source_bytewidth {
         1 => for (self_pixel, source_pixel) in
@@ -151,25 +181,35 @@ pub struct PlaneSlice<'a> {
 impl<'a> PlaneSlice<'a> {
   pub fn as_slice(&'a self) -> &'a [u16] {
     let stride = self.plane.cfg.stride;
-    let base = (self.y + self.plane.cfg.yorigin as isize) as usize * stride + (self.x + self.plane.cfg.xorigin as isize) as usize;
+    let base = (self.y + self.plane.cfg.yorigin as isize) as usize * stride
+      + (self.x + self.plane.cfg.xorigin as isize) as usize;
     &self.plane.data[base..]
   }
 
   pub fn as_slice_clamped(&'a self) -> &'a [u16] {
     let stride = self.plane.cfg.stride;
-    let y = (self.y.min(self.plane.cfg.height as isize) + self.plane.cfg.yorigin as isize).max(0) as usize;
-    let x = (self.x.min(self.plane.cfg.width as isize) + self.plane.cfg.xorigin as isize).max(0) as usize;
+    let y = (self.y.min(self.plane.cfg.height as isize)
+      + self.plane.cfg.yorigin as isize)
+      .max(0) as usize;
+    let x = (self.x.min(self.plane.cfg.width as isize)
+      + self.plane.cfg.xorigin as isize)
+      .max(0) as usize;
     &self.plane.data[y * stride + x..]
   }
 
   pub fn as_slice_w_width(&'a self, width: usize) -> &'a [u16] {
     let stride = self.plane.cfg.stride;
-    let base = (self.y + self.plane.cfg.yorigin as isize) as usize * stride + (self.x + self.plane.cfg.xorigin as isize) as usize;
-    &self.plane.data[base .. base + width]
+    let base = (self.y + self.plane.cfg.yorigin as isize) as usize * stride
+      + (self.x + self.plane.cfg.xorigin as isize) as usize;
+    &self.plane.data[base..base + width]
   }
 
   pub fn subslice(&'a self, xo: usize, yo: usize) -> PlaneSlice<'a> {
-    PlaneSlice { plane: self.plane, x: self.x + xo as isize, y: self.y + yo as isize }
+    PlaneSlice {
+      plane: self.plane,
+      x: self.x + xo as isize,
+      y: self.y + yo as isize
+    }
   }
 
   /// A slice starting i pixels above the current one.
@@ -183,8 +223,10 @@ impl<'a> PlaneSlice<'a> {
   }
 
   pub fn p(&self, add_x: usize, add_y: usize) -> u16 {
-    let new_y = (self.y + add_y as isize + self.plane.cfg.yorigin as isize) as usize;
-    let new_x = (self.x + add_x as isize + self.plane.cfg.xorigin as isize) as usize;
+    let new_y =
+      (self.y + add_y as isize + self.plane.cfg.yorigin as isize) as usize;
+    let new_x =
+      (self.x + add_x as isize + self.plane.cfg.xorigin as isize) as usize;
     self.plane.data[new_y * self.plane.cfg.stride + new_x]
   }
 }
@@ -198,7 +240,8 @@ pub struct PlaneMutSlice<'a> {
 impl<'a> PlaneMutSlice<'a> {
   pub fn as_mut_slice(&'a mut self) -> &'a mut [u16] {
     let stride = self.plane.cfg.stride;
-    let base = (self.y + self.plane.cfg.yorigin as isize) as usize * stride + (self.x + self.plane.cfg.xorigin as isize) as usize;
+    let base = (self.y + self.plane.cfg.yorigin as isize) as usize * stride
+      + (self.x + self.plane.cfg.xorigin as isize) as usize;
     &mut self.plane.data[base..]
   }
 
@@ -209,21 +252,24 @@ impl<'a> PlaneMutSlice<'a> {
     assert!(y >= 0);
     assert!(x >= 0);
     let base = y as usize * stride + x as usize;
-    &mut self.plane.data[base .. base + width]
+    &mut self.plane.data[base..base + width]
   }
 
-
   pub fn offset(&self, add_x: usize, add_y: usize) -> &[u16] {
-    let new_y = (self.y + add_y as isize + self.plane.cfg.yorigin as isize) as usize;
-    let new_x = (self.x + add_x as isize + self.plane.cfg.xorigin as isize) as usize;
+    let new_y =
+      (self.y + add_y as isize + self.plane.cfg.yorigin as isize) as usize;
+    let new_x =
+      (self.x + add_x as isize + self.plane.cfg.xorigin as isize) as usize;
     &self.plane.data[new_y * self.plane.cfg.stride + new_x..]
   }
 
   pub fn offset_as_mutable(
     &'a mut self, add_x: usize, add_y: usize
   ) -> &'a mut [u16] {
-    let new_y = (self.y + add_y as isize + self.plane.cfg.yorigin as isize) as usize;
-    let new_x = (self.x + add_x as isize + self.plane.cfg.xorigin as isize) as usize;
+    let new_y =
+      (self.y + add_y as isize + self.plane.cfg.yorigin as isize) as usize;
+    let new_x =
+      (self.x + add_x as isize + self.plane.cfg.xorigin as isize) as usize;
     &mut self.plane.data[new_y * self.plane.cfg.stride + new_x..]
   }
 
@@ -240,8 +286,10 @@ impl<'a> PlaneMutSlice<'a> {
   }
 
   pub fn p(&self, add_x: usize, add_y: usize) -> u16 {
-    let new_y = (self.y + add_y as isize + self.plane.cfg.yorigin as isize) as usize;
-    let new_x = (self.x + add_x as isize + self.plane.cfg.xorigin as isize) as usize;
+    let new_y =
+      (self.y + add_y as isize + self.plane.cfg.yorigin as isize) as usize;
+    let new_x =
+      (self.x + add_x as isize + self.plane.cfg.xorigin as isize) as usize;
     self.plane.data[new_y * self.plane.cfg.stride + new_x]
   }
 }
diff --git a/src/predict.rs b/src/predict.rs
index 27d6710f..22158208 100755
--- a/src/predict.rs
+++ b/src/predict.rs
@@ -13,10 +13,10 @@
 
 use libc;
 
+use context::INTRA_MODES;
 use context::MAX_TX_SIZE;
 use partition::*;
 use std::mem::*;
-use context::INTRA_MODES;
 
 #[cfg(target_arch = "x86")]
 use std::arch::x86::*;
@@ -44,7 +44,7 @@ pub static RAV1E_INTRA_MODES_MINIMAL: &'static [PredictionMode] = &[
 pub static RAV1E_INTER_MODES: &'static [PredictionMode] = &[
   PredictionMode::GLOBALMV,
   PredictionMode::NEARESTMV,
-  PredictionMode::NEWMV,
+  PredictionMode::NEWMV
 ];
 
 // Weights are quadratic from '1' to '1 / block_size', scaled by 2^sm_weight_log2_scale.
@@ -74,7 +74,6 @@ static sm_weight_arrays: [u8; 2 * MAX_TX_SIZE] = [
     13, 12, 10, 9, 8, 7, 6, 6, 5, 5, 4, 4, 4,*/
 ];
 
-
 const NEED_LEFT: u8 = 1 << 1;
 const NEED_ABOVE: u8 = 1 << 2;
 const NEED_ABOVERIGHT: u8 = 1 << 3;
@@ -86,19 +85,19 @@ const INTRA_EDGE_TAPS: usize = 5;
 const MAX_UPSAMPLE_SZ: usize = 16;*/
 
 pub static extend_modes: [u8; INTRA_MODES] = [
-  NEED_ABOVE | NEED_LEFT,                   // DC
-  NEED_ABOVE,                               // V
-  NEED_LEFT,                                // H
-  NEED_ABOVE | NEED_ABOVERIGHT,             // D45
-  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT,  // D135
-  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT,  // D113
-  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT,  // D157
-  NEED_LEFT | NEED_BOTTOMLEFT,              // D203
-  NEED_ABOVE | NEED_ABOVERIGHT,             // D67
-  NEED_LEFT | NEED_ABOVE,                   // SMOOTH
-  NEED_LEFT | NEED_ABOVE,                   // SMOOTH_V
-  NEED_LEFT | NEED_ABOVE,                   // SMOOTH_H
-  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT,  // PAETH
+  NEED_ABOVE | NEED_LEFT,                  // DC
+  NEED_ABOVE,                              // V
+  NEED_LEFT,                               // H
+  NEED_ABOVE | NEED_ABOVERIGHT,            // D45
+  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT, // D135
+  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT, // D113
+  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT, // D157
+  NEED_LEFT | NEED_BOTTOMLEFT,             // D203
+  NEED_ABOVE | NEED_ABOVERIGHT,            // D67
+  NEED_LEFT | NEED_ABOVE,                  // SMOOTH
+  NEED_LEFT | NEED_ABOVE,                  // SMOOTH_V
+  NEED_LEFT | NEED_ABOVE,                  // SMOOTH_H
+  NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT  // PAETH
 ];
 
 extern {
@@ -231,7 +230,8 @@ pub trait Intra: Dim {
 
   #[cfg_attr(feature = "comparative_bench", inline(never))]
   fn pred_dc_left(
-    output: &mut [u16], stride: usize, above: &[u16], left: &[u16], bit_depth: usize
+    output: &mut [u16], stride: usize, above: &[u16], left: &[u16],
+    bit_depth: usize
   ) {
     unsafe {
       highbd_dc_left_predictor(
@@ -248,7 +248,8 @@ pub trait Intra: Dim {
 
   #[cfg_attr(feature = "comparative_bench", inline(never))]
   fn pred_dc_top(
-    output: &mut [u16], stride: usize, above: &[u16], left: &[u16], bit_depth: usize
+    output: &mut [u16], stride: usize, above: &[u16], left: &[u16],
+    bit_depth: usize
   ) {
     unsafe {
       highbd_dc_top_predictor(
@@ -501,9 +502,7 @@ pub trait Intra: Dim {
   }
 }
 
-pub trait Inter: Dim {
-
-}
+pub trait Inter: Dim {}
 
 impl Intra for Block4x4 {}
 impl Intra for Block8x8 {}
diff --git a/src/quantize.rs b/src/quantize.rs
index 961835ec..0645e409 100755
--- a/src/quantize.rs
+++ b/src/quantize.rs
@@ -17,7 +17,7 @@ extern {
   static dc_qlookup_10_Q3: [i16; 256];
   static dc_qlookup_12_Q3: [i16; 256];
 
-  static ac_qlookup_Q3: [i16; 256];  
+  static ac_qlookup_Q3: [i16; 256];
   static ac_qlookup_10_Q3: [i16; 256];
   static ac_qlookup_12_Q3: [i16; 256];
 }
@@ -119,7 +119,9 @@ mod test {
 }
 
 impl QuantizationContext {
-  pub fn update(&mut self, qindex: u8, tx_size: TxSize, is_intra: bool, bit_depth: usize) {
+  pub fn update(
+    &mut self, qindex: u8, tx_size: TxSize, is_intra: bool, bit_depth: usize
+  ) {
     self.log_tx_scale = get_log_tx_scale(tx_size);
 
     self.dc_quant = dc_q(qindex, bit_depth) as u32;
@@ -128,8 +130,10 @@ impl QuantizationContext {
     self.ac_quant = ac_q(qindex, bit_depth) as u32;
     self.ac_mul_add = divu_gen(self.ac_quant);
 
-    self.dc_offset = self.dc_quant as i32 * (if is_intra {21} else {15}) / 64;
-    self.ac_offset = self.ac_quant as i32 * (if is_intra {21} else {15}) / 64;
+    self.dc_offset =
+      self.dc_quant as i32 * (if is_intra { 21 } else { 15 }) / 64;
+    self.ac_offset =
+      self.ac_quant as i32 * (if is_intra { 21 } else { 15 }) / 64;
   }
 
   #[inline]
@@ -146,7 +150,9 @@ impl QuantizationContext {
   }
 }
 
-pub fn quantize_in_place(qindex: u8, coeffs: &mut [i32], tx_size: TxSize, bit_depth: usize) {
+pub fn quantize_in_place(
+  qindex: u8, coeffs: &mut [i32], tx_size: TxSize, bit_depth: usize
+) {
   let log_tx_scale = get_log_tx_scale(tx_size);
 
   let dc_quant = dc_q(qindex, bit_depth) as i32;
@@ -168,7 +174,8 @@ pub fn quantize_in_place(qindex: u8, coeffs: &mut [i32], tx_size: TxSize, bit_de
 }
 
 pub fn dequantize(
-  qindex: u8, coeffs: &[i32], rcoeffs: &mut [i32], tx_size: TxSize, bit_depth: usize
+  qindex: u8, coeffs: &[i32], rcoeffs: &mut [i32], tx_size: TxSize,
+  bit_depth: usize
 ) {
   let log_tx_scale = get_log_tx_scale(tx_size) as i32;
   let offset = (1 << log_tx_scale) - 1;
diff --git a/src/rdo.rs b/src/rdo.rs
index 4a75473d..d890a7d9 100755
--- a/src/rdo.rs
+++ b/src/rdo.rs
@@ -58,7 +58,9 @@ pub struct RDOPartitionOutput {
 }
 
 #[allow(unused)]
-fn cdef_dist_wxh_8x8(src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, bit_depth: usize) -> u64 {
+fn cdef_dist_wxh_8x8(
+  src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, bit_depth: usize
+) -> u64 {
   let coeff_shift = bit_depth - 8;
 
   let mut sum_s: i32 = 0;
@@ -88,7 +90,8 @@ fn cdef_dist_wxh_8x8(src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, bit_depth: us
 
 #[allow(unused)]
 fn cdef_dist_wxh(
-  src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, w: usize, h: usize, bit_depth: usize
+  src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, w: usize, h: usize,
+  bit_depth: usize
 ) -> u64 {
   assert!(w & 0x7 == 0);
   assert!(h & 0x7 == 0);
@@ -107,7 +110,9 @@ fn cdef_dist_wxh(
 }
 
 // Sum of Squared Error for a wxh block
-fn sse_wxh(src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, w: usize, h: usize) -> u64 {
+fn sse_wxh(
+  src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, w: usize, h: usize
+) -> u64 {
   assert!(w & (MI_SIZE - 1) == 0);
   assert!(h & (MI_SIZE - 1) == 0);
 
@@ -118,9 +123,13 @@ fn sse_wxh(src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, w: usize, h: usize) ->
     let s1 = src1j.as_slice_w_width(w);
     let s2 = src2j.as_slice_w_width(w);
 
-    let row_sse = s1.iter().zip(s2)
-      .map(|(&a, &b)| { let c = (a as i16 - b as i16) as i32; (c * c) as u32 })
-      .sum::<u32>();
+    let row_sse = s1
+      .iter()
+      .zip(s2)
+      .map(|(&a, &b)| {
+        let c = (a as i16 - b as i16) as i32;
+        (c * c) as u32
+      }).sum::<u32>();
     sse += row_sse as u64;
   }
   sse
@@ -140,7 +149,8 @@ pub fn get_lambda(fi: &FrameInvariants, bit_depth: usize) -> f64 {
 // Compute the rate-distortion cost for an encode
 fn compute_rd_cost(
   fi: &FrameInvariants, fs: &FrameState, w_y: usize, h_y: usize,
-  is_chroma_block: bool, bo: &BlockOffset, bit_cost: u32, bit_depth: usize, luma_only: bool
+  is_chroma_block: bool, bo: &BlockOffset, bit_cost: u32, bit_depth: usize,
+  luma_only: bool
 ) -> f64 {
   let lambda = get_lambda(fi, bit_depth);
 
@@ -197,16 +207,17 @@ fn compute_rd_cost(
   (distortion as f64) + lambda * rate
 }
 
-pub fn rdo_tx_size_type(seq: &Sequence, fi: &FrameInvariants,
-  fs: &mut FrameState, cw: &mut ContextWriter, bsize: BlockSize,
-  bo: &BlockOffset, luma_mode: PredictionMode, ref_frame: usize, mv: MotionVector, skip: bool)
-  -> (TxSize, TxType) {
+pub fn rdo_tx_size_type(
+  seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
+  cw: &mut ContextWriter, bsize: BlockSize, bo: &BlockOffset,
+  luma_mode: PredictionMode, ref_frame: usize, mv: MotionVector, skip: bool
+) -> (TxSize, TxType) {
   // these rules follow TX_MODE_LARGEST
   let tx_size = match bsize {
-      BlockSize::BLOCK_4X4 => TxSize::TX_4X4,
-      BlockSize::BLOCK_8X8 => TxSize::TX_8X8,
-      BlockSize::BLOCK_16X16 => TxSize::TX_16X16,
-      _ => TxSize::TX_32X32
+    BlockSize::BLOCK_4X4 => TxSize::TX_4X4,
+    BlockSize::BLOCK_8X8 => TxSize::TX_8X8,
+    BlockSize::BLOCK_16X16 => TxSize::TX_16X16,
+    _ => TxSize::TX_32X32
   };
   cw.bc.set_tx_size(bo, tx_size);
   // Were we not hardcoded to TX_MODE_LARGEST, block tx size would be written here
@@ -215,19 +226,33 @@ pub fn rdo_tx_size_type(seq: &Sequence, fi: &FrameInvariants,
   let is_inter = !luma_mode.is_intra();
   let tx_set = get_tx_set(tx_size, is_inter, fi.use_reduced_tx_set);
 
-  let tx_type = if tx_set > TxSet::TX_SET_DCTONLY && fi.config.speed <= 3 && !skip {
-      rdo_tx_type_decision(fi, fs, cw, luma_mode, ref_frame, mv, bsize, bo, tx_size, tx_set, seq.bit_depth)
-  } else {
+  let tx_type =
+    if tx_set > TxSet::TX_SET_DCTONLY && fi.config.speed <= 3 && !skip {
+      rdo_tx_type_decision(
+        fi,
+        fs,
+        cw,
+        luma_mode,
+        ref_frame,
+        mv,
+        bsize,
+        bo,
+        tx_size,
+        tx_set,
+        seq.bit_depth
+      )
+    } else {
       TxType::DCT_DCT
-  };
+    };
 
   (tx_size, tx_type)
 }
 
 // RDO-based mode decision
 pub fn rdo_mode_decision(
-  seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter,
-  bsize: BlockSize, bo: &BlockOffset) -> RDOOutput {
+  seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
+  cw: &mut ContextWriter, bsize: BlockSize, bo: &BlockOffset
+) -> RDOOutput {
   let mut best_mode_luma = PredictionMode::DC_PRED;
   let mut best_mode_chroma = PredictionMode::DC_PRED;
   let mut best_cfl_params = CFLParams::new();
@@ -246,8 +271,10 @@ pub fn rdo_mode_decision(
   let cw_checkpoint = cw.checkpoint();
 
   // Exclude complex prediction modes at higher speed levels
-  let intra_mode_set = if (fi.frame_type == FrameType::KEY && fi.config.speed <= 3) ||
-                          (fi.frame_type == FrameType::INTER && fi.config.speed <= 1) {
+  let intra_mode_set = if (fi.frame_type == FrameType::KEY
+    && fi.config.speed <= 3)
+    || (fi.frame_type == FrameType::INTER && fi.config.speed <= 1)
+  {
     RAV1E_INTRA_MODES
   } else {
     RAV1E_INTRA_MODES_MINIMAL
@@ -261,14 +288,18 @@ pub fn rdo_mode_decision(
   mode_set.extend_from_slice(intra_mode_set);
 
   let mut mv_stack = Vec::new();
-  let mode_context = cw.find_mvrefs(bo, LAST_FRAME, &mut mv_stack, bsize, false);
+  let mode_context =
+    cw.find_mvrefs(bo, LAST_FRAME, &mut mv_stack, bsize, false);
 
   for &luma_mode in &mode_set {
     assert!(fi.frame_type == FrameType::INTER || luma_mode.is_intra());
 
-    let mut mode_set_chroma = vec![ luma_mode ];
+    let mut mode_set_chroma = vec![luma_mode];
 
-    if is_chroma_block && luma_mode.is_intra() && luma_mode != PredictionMode::DC_PRED {
+    if is_chroma_block
+      && luma_mode.is_intra()
+      && luma_mode != PredictionMode::DC_PRED
+    {
       mode_set_chroma.push(PredictionMode::DC_PRED);
     }
 
@@ -276,15 +307,21 @@ pub fn rdo_mode_decision(
       mode_set_chroma.push(PredictionMode::UV_CFL_PRED);
     }
 
-    let ref_frame = if luma_mode.is_intra() { INTRA_FRAME } else { LAST_FRAME };
+    let ref_frame =
+      if luma_mode.is_intra() { INTRA_FRAME } else { LAST_FRAME };
     let mv = match luma_mode {
       PredictionMode::NEWMV => motion_estimation(fi, fs, bsize, bo, ref_frame),
-      PredictionMode::NEARESTMV => if mv_stack.len() > 0 { mv_stack[0].this_mv } else { MotionVector { row: 0, col: 0 } },
+      PredictionMode::NEARESTMV => if mv_stack.len() > 0 {
+        mv_stack[0].this_mv
+      } else {
+        MotionVector { row: 0, col: 0 }
+      },
       _ => MotionVector { row: 0, col: 0 }
     };
 
-    let (tx_size, tx_type) =
-      rdo_tx_size_type(seq, fi, fs, cw, bsize, bo, luma_mode, ref_frame, mv, false);
+    let (tx_size, tx_type) = rdo_tx_size_type(
+      seq, fi, fs, cw, bsize, bo, luma_mode, ref_frame, mv, false,
+    );
 
     // Find the best chroma prediction mode for the current luma prediction mode
     for &chroma_mode in &mode_set_chroma {
@@ -296,7 +333,20 @@ pub fn rdo_mode_decision(
         let cw_checkpoint = cw.checkpoint();
         let mut wr: &mut dyn Writer = &mut WriterCounter::new();
         write_tx_blocks(
-          fi, fs, cw, wr, luma_mode, luma_mode, bo, bsize, tx_size, tx_type, false, seq.bit_depth, cfl, true
+          fi,
+          fs,
+          cw,
+          wr,
+          luma_mode,
+          luma_mode,
+          bo,
+          bsize,
+          tx_size,
+          tx_type,
+          false,
+          seq.bit_depth,
+          cfl,
+          true
         );
         cw.rollback(&cw_checkpoint);
         match rdo_cfl_alpha(fs, bo, bsize, seq.bit_depth) {
@@ -309,14 +359,34 @@ pub fn rdo_mode_decision(
 
       for &skip in &[false, true] {
         // Don't skip when using intra modes
-        if skip && luma_mode.is_intra() { continue; }
+        if skip && luma_mode.is_intra() {
+          continue;
+        }
 
         let mut wr: &mut dyn Writer = &mut WriterCounter::new();
         let tell = wr.tell_frac();
 
         encode_block_a(seq, cw, wr, bsize, bo, skip);
-        encode_block_b(seq, fi, fs, cw, wr, luma_mode, chroma_mode,
-          ref_frame, mv, bsize, bo, skip, seq.bit_depth, cfl, tx_size, tx_type, mode_context, &mv_stack);
+        encode_block_b(
+          seq,
+          fi,
+          fs,
+          cw,
+          wr,
+          luma_mode,
+          chroma_mode,
+          ref_frame,
+          mv,
+          bsize,
+          bo,
+          skip,
+          seq.bit_depth,
+          cfl,
+          tx_size,
+          tx_type,
+          mode_context,
+          &mv_stack
+        );
 
         let cost = wr.tell_frac() - tell;
         let rd = compute_rd_cost(
@@ -479,8 +549,10 @@ pub fn rdo_tx_type_decision(
 
 // RDO-based single level partitioning decision
 pub fn rdo_partition_decision(
-  seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter,
-  bsize: BlockSize, bo: &BlockOffset, cached_block: &RDOOutput) -> RDOOutput {
+  seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
+  cw: &mut ContextWriter, bsize: BlockSize, bo: &BlockOffset,
+  cached_block: &RDOOutput
+) -> RDOOutput {
   let max_rd = std::f64::MAX;
 
   let mut best_partition = cached_block.part_type;
@@ -507,8 +579,9 @@ pub fn rdo_partition_decision(
         let mode_decision = cached_block
           .part_modes
           .get(0)
-          .unwrap_or(&rdo_mode_decision(seq, fi, fs, cw, bsize, bo).part_modes[0])
-          .clone();
+          .unwrap_or(
+            &rdo_mode_decision(seq, fi, fs, cw, bsize, bo).part_modes[0]
+          ).clone();
         child_modes.push(mode_decision);
       }
       PartitionType::PARTITION_SPLIT => {
@@ -522,28 +595,28 @@ pub fn rdo_partition_decision(
         let hbs = bs >> 1; // Half the block size in blocks
 
         let offset = BlockOffset { x: bo.x, y: bo.y };
-        let mode_decision = rdo_mode_decision(seq, fi, fs, cw, subsize, &offset)
-          .part_modes[0]
-          .clone();
+        let mode_decision =
+          rdo_mode_decision(seq, fi, fs, cw, subsize, &offset).part_modes[0]
+            .clone();
         child_modes.push(mode_decision);
 
         let offset = BlockOffset { x: bo.x + hbs as usize, y: bo.y };
-        let mode_decision = rdo_mode_decision(seq, fi, fs, cw, subsize, &offset)
-          .part_modes[0]
-          .clone();
+        let mode_decision =
+          rdo_mode_decision(seq, fi, fs, cw, subsize, &offset).part_modes[0]
+            .clone();
         child_modes.push(mode_decision);
 
         let offset = BlockOffset { x: bo.x, y: bo.y + hbs as usize };
-        let mode_decision = rdo_mode_decision(seq, fi, fs, cw, subsize, &offset)
-          .part_modes[0]
-          .clone();
+        let mode_decision =
+          rdo_mode_decision(seq, fi, fs, cw, subsize, &offset).part_modes[0]
+            .clone();
         child_modes.push(mode_decision);
 
         let offset =
           BlockOffset { x: bo.x + hbs as usize, y: bo.y + hbs as usize };
-        let mode_decision = rdo_mode_decision(seq, fi, fs, cw, subsize, &offset)
-          .part_modes[0]
-          .clone();
+        let mode_decision =
+          rdo_mode_decision(seq, fi, fs, cw, subsize, &offset).part_modes[0]
+            .clone();
         child_modes.push(mode_decision);
       }
       _ => {
diff --git a/src/test_encode_decode.rs b/src/test_encode_decode.rs
index ea4fcd73..209d2d07 100644
--- a/src/test_encode_decode.rs
+++ b/src/test_encode_decode.rs
@@ -8,8 +8,8 @@ include!(concat!(env!("OUT_DIR"), "/aom.rs"));
 use super::*;
 
 use rand::{ChaChaRng, Rng, SeedableRng};
-use std::mem;
 use std::collections::VecDeque;
+use std::mem;
 
     fn fill_frame(ra: &mut ChaChaRng, frame: &mut Frame) {
         for plane in frame.planes.iter_mut() {
diff --git a/src/transform.rs b/src/transform.rs
index 8a75275c..861cdd61 100755
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -694,7 +694,7 @@ extern {
   );
 }
 
-extern "C" {
+extern {
   static av1_inv_txfm2d_add_4x4: extern fn(
     input: *const i32,
     output: *mut u16,
@@ -703,11 +703,8 @@ extern "C" {
     bd: libc::c_int
   );
   fn av1_inv_txfm2d_add_4x4_c(
-    input: *const i32,
-    output: *mut u16,
-    stride: libc::c_int,
-    tx_type: libc::c_int,
-    bd: libc::c_int
+    input: *const i32, output: *mut u16, stride: libc::c_int,
+    tx_type: libc::c_int, bd: libc::c_int
   );
   static av1_inv_txfm2d_add_8x8: extern fn(
     input: *const i32,
@@ -717,11 +714,8 @@ extern "C" {
     bd: libc::c_int
   ) -> ();
   fn av1_inv_txfm2d_add_8x8_c(
-    input: *const i32,
-    output: *mut u16,
-    stride: libc::c_int,
-    tx_type: libc::c_int,
-    bd: libc::c_int
+    input: *const i32, output: *mut u16, stride: libc::c_int,
+    tx_type: libc::c_int, bd: libc::c_int
   ) -> ();
   static av1_inv_txfm2d_add_16x16: extern fn(
     input: *const i32,
@@ -742,11 +736,8 @@ extern "C" {
     bd: libc::c_int
   );
   fn av1_inv_txfm2d_add_32x32_c(
-    input: *const i32,
-    output: *mut u16,
-    stride: libc::c_int,
-    tx_type: libc::c_int,
-    bd: libc::c_int
+    input: *const i32, output: *mut u16, stride: libc::c_int,
+    tx_type: libc::c_int, bd: libc::c_int
   );
 }
 
@@ -770,13 +761,18 @@ pub fn inverse_transform_add(
   match tx_size {
     TxSize::TX_4X4 => iht4x4_add(input, output, stride, tx_type, bit_depth),
     TxSize::TX_8X8 => iht8x8_add(input, output, stride, tx_type, bit_depth),
-    TxSize::TX_16X16 => iht16x16_add(input, output, stride, tx_type, bit_depth),
-    TxSize::TX_32X32 => iht32x32_add(input, output, stride, tx_type, bit_depth),
+    TxSize::TX_16X16 =>
+      iht16x16_add(input, output, stride, tx_type, bit_depth),
+    TxSize::TX_32X32 =>
+      iht32x32_add(input, output, stride, tx_type, bit_depth),
     _ => panic!("unimplemented tx size")
   }
 }
 
-fn fht4x4(input: &[i16], output: &mut [i32], stride: usize, tx_type: TxType, bit_depth: usize) {
+fn fht4x4(
+  input: &[i16], output: &mut [i32], stride: usize, tx_type: TxType,
+  bit_depth: usize
+) {
   unsafe {
     av1_fwd_txfm2d_4x4_c(
       input.as_ptr(),
@@ -789,7 +785,8 @@ fn fht4x4(input: &[i16], output: &mut [i32], stride: usize, tx_type: TxType, bit
 }
 
 fn iht4x4_add(
-  input: &[i32], output: &mut [u16], stride: usize, tx_type: TxType, bit_depth: usize
+  input: &[i32], output: &mut [u16], stride: usize, tx_type: TxType,
+  bit_depth: usize
 ) {
   // SIMD code may assert for transform types beyond TxType::IDTX.
   if tx_type <= TxType::ADST_ADST
@@ -819,7 +816,10 @@ fn iht4x4_add(
   }
 }
 
-fn fht8x8(input: &[i16], output: &mut [i32], stride: usize, tx_type: TxType, bit_depth: usize) {
+fn fht8x8(
+  input: &[i16], output: &mut [i32], stride: usize, tx_type: TxType,
+  bit_depth: usize
+) {
   unsafe {
     av1_fwd_txfm2d_8x8_c(
       input.as_ptr(),
@@ -832,7 +832,8 @@ fn fht8x8(input: &[i16], output: &mut [i32], stride: usize, tx_type: TxType, bit
 }
 
 fn iht8x8_add(
-  input: &[i32], output: &mut [u16], stride: usize, tx_type: TxType, bit_depth: usize
+  input: &[i32], output: &mut [u16], stride: usize, tx_type: TxType,
+  bit_depth: usize
 ) {
   // SIMD code may assert for transform types beyond TxType::IDTX.
   if tx_type <= TxType::ADST_ADST
@@ -863,7 +864,8 @@ fn iht8x8_add(
 }
 
 fn fht16x16(
-  input: &[i16], output: &mut [i32], stride: usize, tx_type: TxType, bit_depth: usize
+  input: &[i16], output: &mut [i32], stride: usize, tx_type: TxType,
+  bit_depth: usize
 ) {
   unsafe {
     av1_fwd_txfm2d_16x16_c(
@@ -877,7 +879,8 @@ fn fht16x16(
 }
 
 fn iht16x16_add(
-  input: &[i32], output: &mut [u16], stride: usize, tx_type: TxType, bit_depth: usize
+  input: &[i32], output: &mut [u16], stride: usize, tx_type: TxType,
+  bit_depth: usize
 ) {
   unsafe {
     if tx_type <= TxType::ADST_ADST
@@ -906,7 +909,8 @@ fn iht16x16_add(
 }
 
 fn fht32x32(
-  input: &[i16], output: &mut [i32], stride: usize, tx_type: TxType, bit_depth: usize
+  input: &[i16], output: &mut [i32], stride: usize, tx_type: TxType,
+  bit_depth: usize
 ) {
   unsafe {
     av1_fwd_txfm2d_32x32_c(
@@ -920,7 +924,8 @@ fn fht32x32(
 }
 
 fn iht32x32_add(
-  input: &[i32], output: &mut [u16], stride: usize, tx_type: TxType, bit_depth: usize
+  input: &[i32], output: &mut [u16], stride: usize, tx_type: TxType,
+  bit_depth: usize
 ) {
   unsafe {
     if tx_type < TxType::IDTX {
diff --git a/src/util.rs b/src/util.rs
index 610fc7aa..b9db082f 100755
--- a/src/util.rs
+++ b/src/util.rs
@@ -189,29 +189,26 @@ pub fn is_aligned<T>(ptr: *const T, n: usize) -> bool {
 
 pub fn clamp<T: PartialOrd>(input: T, min: T, max: T) -> T {
   if input < min {
-      return min;
-  }
-  else if input > max {
-      return max;
-  }
-  else {
-      return input;
+    return min;
+  } else if input > max {
+    return max;
+  } else {
+    return input;
   }
 }
 
 use num_traits::PrimInt;
 use std::mem::size_of;
 
-pub trait ILog : PrimInt {
-    fn ilog(self) -> Self {
-        Self::from(size_of::<Self>() * 8 - self.leading_zeros() as usize).unwrap()
-    }
+pub trait ILog: PrimInt {
+  fn ilog(self) -> Self {
+    Self::from(size_of::<Self>() * 8 - self.leading_zeros() as usize).unwrap()
+  }
 }
 
 impl<T> ILog for T where T: PrimInt {}
 
 pub fn msb(x: i32) -> i32 {
-    debug_assert!(x>0);
-    31 ^ (x.leading_zeros() as i32)
+  debug_assert!(x > 0);
+  31 ^ (x.leading_zeros() as i32)
 }
-
-- 
GitLab