h264: add SIMD optimisations for x86_64 (not enabled by default)
[nihav.git] / nihav-itu / src / codecs / h264 / mb_recon.rs
index 97637a2d30ef04fb8595e413be7959783e758512..e17095b6c39d4c877eb55fe775b0ffaa9868a168 100644 (file)
@@ -219,7 +219,13 @@ fn do_p_mc(frm: &mut NASimpleVideoFrame<u8>, xpos: usize, ypos: usize, w: usize,
                 } else {
                     [1, 0, 0]
                 };
-            mc_dsp.put_block_weighted(&mut frm.data[yoff..], frm.stride[0], &ytmp, w, h, yw);
+            let wmode = match w {
+                    2 => 0,
+                    4 => 1,
+                    8 => 2,
+                    _ => 3,
+                };
+            (mc_dsp.put_block_weighted[wmode])(&mut frm.data[yoff..], frm.stride[0], &ytmp, h, yw);
 
             for chroma in 0..2 {
                 let cstride = frm.stride[chroma + 1];
@@ -230,7 +236,7 @@ fn do_p_mc(frm: &mut NASimpleVideoFrame<u8>, xpos: usize, ypos: usize, w: usize,
                         [1, 0, 0]
                     };
                 let csrc = if chroma == 0 { &utmp } else { &vtmp };
-                mc_dsp.put_block_weighted(&mut frm.data[coff..], cstride, csrc, w / 2, h / 2, cw);
+                (mc_dsp.put_block_weighted[wmode - 1])(&mut frm.data[coff..], cstride, csrc, h / 2, cw);
             }
         }
     } else {
@@ -238,6 +244,7 @@ fn do_p_mc(frm: &mut NASimpleVideoFrame<u8>, xpos: usize, ypos: usize, w: usize,
     }
 }
 
+#[allow(clippy::match_like_matches_macro)]
 fn do_b_mc(frm: &mut NASimpleVideoFrame<u8>, mode: BMode, xpos: usize, ypos: usize, w: usize, h: usize, mv0: MV, ref_pic0: Option<NAVideoBufferRef<u8>>, weight0: &WeightInfo, mv1: MV, ref_pic1: Option<NAVideoBufferRef<u8>>, weight1: &WeightInfo, mc_dsp: &mut H264MC) {
     let do_weight = match (mode, weight0.is_weighted(), weight1.is_weighted()) {
             (BMode::L0, true, _) => true,
@@ -297,7 +304,13 @@ fn do_b_mc(frm: &mut NASimpleVideoFrame<u8>, mode: BMode, xpos: usize, ypos: usi
                     } else {
                         [1, 0, 0]
                     };
-                mc_dsp.put_block_weighted(&mut frm.data[yoff..], frm.stride[0], &ytmp0, w, h, yw);
+                let wmode = match w {
+                        2 => 0,
+                        4 => 1,
+                        8 => 2,
+                        _ => 3,
+                    };
+                (mc_dsp.put_block_weighted[wmode])(&mut frm.data[yoff..], frm.stride[0], &ytmp0, h, yw);
 
                 for chroma in 0..2 {
                     let cstride = frm.stride[chroma + 1];
@@ -308,7 +321,7 @@ fn do_b_mc(frm: &mut NASimpleVideoFrame<u8>, mode: BMode, xpos: usize, ypos: usi
                             [1, 0, 0]
                         };
                     let csrc = if chroma == 0 { &utmp0 } else { &vtmp0 };
-                    mc_dsp.put_block_weighted(&mut frm.data[coff..], cstride, csrc, w / 2, h / 2, cw);
+                    (mc_dsp.put_block_weighted[wmode - 1])(&mut frm.data[coff..], cstride, csrc, h / 2, cw);
                 }
             },
             (BMode::Bi, Some(buf0), Some(buf1)) => { // do both and avg
@@ -322,7 +335,13 @@ fn do_b_mc(frm: &mut NASimpleVideoFrame<u8>, mode: BMode, xpos: usize, ypos: usi
                         (false, true) => [1 << weight1.luma_shift, 0, weight1.luma_weight, weight1.luma_offset, weight1.luma_shift as i8],
                         (false, false) => [1, 0, 1, 0, 0],
                     };
-                mc_dsp.put_block_weighted2(&mut frm.data[yoff..], frm.stride[0], &ytmp0, &ytmp1, w, h, yw);
+                let wmode = match w {
+                        2 => 0,
+                        4 => 1,
+                        8 => 2,
+                        _ => 3,
+                    };
+                (mc_dsp.put_block_weighted2[wmode])(&mut frm.data[yoff..], frm.stride[0], &ytmp0, &ytmp1, h, yw);
 
                 for chroma in 0..2 {
                     let cstride = frm.stride[chroma + 1];
@@ -339,7 +358,7 @@ fn do_b_mc(frm: &mut NASimpleVideoFrame<u8>, mode: BMode, xpos: usize, ypos: usi
                         };
                     let csrc0 = if chroma == 0 { &utmp0 } else { &vtmp0 };
                     let csrc1 = if chroma == 0 { &utmp1 } else { &vtmp1 };
-                    mc_dsp.put_block_weighted2(&mut frm.data[coff..], cstride, csrc0, csrc1, w / 2, h / 2, cw);
+                    (mc_dsp.put_block_weighted2[wmode - 1])(&mut frm.data[coff..], cstride, csrc0, csrc1, h / 2, cw);
                 }
             },
             _ => {
@@ -405,10 +424,10 @@ pub fn recon_mb(frm: &mut NASimpleVideoFrame<u8>, slice_hdr: &SliceHeader, mb_in
 
     match mb_info.mb_type {
         MBType::Intra16x16(_, _, _) => {
-            pred_intra(frm, &sstate, &mb_info);
+            pred_intra(frm, sstate, mb_info);
         },
         MBType::Intra4x4 | MBType::Intra8x8 => {
-            pred_intra(frm, &sstate, &mb_info);
+            pred_intra(frm, sstate, mb_info);
         },
         MBType::PCM => {},
         MBType::PSkip => {
@@ -582,8 +601,8 @@ pub fn recon_mb(frm: &mut NASimpleVideoFrame<u8>, slice_hdr: &SliceHeader, mb_in
     };
     if !mb_info.mb_type.is_skip() {
         if mb_info.mb_type != MBType::Intra4x4 && mb_info.mb_type != MBType::Intra8x8 {
-            add_luma(frm, &sstate, &mb_info);
+            add_luma(frm, sstate, mb_info);
         }
-        add_chroma(frm, &sstate, &mb_info);
+        add_chroma(frm, sstate, mb_info);
     }
 }