LCOV - code coverage report
Current view: top level - third_party/aom/aom_dsp/x86 - fwd_txfm_impl_sse2.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 573 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
       3             :  *
       4             :  * This source code is subject to the terms of the BSD 2 Clause License and
       5             :  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
       6             :  * was not distributed with this source code in the LICENSE file, you can
       7             :  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
       8             :  * Media Patent License 1.0 was not distributed with this source code in the
       9             :  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
      10             :  */
      11             : 
      12             : #include <emmintrin.h>  // SSE2
      13             : 
      14             : #include "./aom_dsp_rtcd.h"
      15             : #include "aom_dsp/txfm_common.h"
      16             : #include "aom_dsp/x86/fwd_txfm_sse2.h"
      17             : #include "aom_dsp/x86/txfm_common_sse2.h"
      18             : #include "aom_ports/mem.h"
      19             : 
      20             : // TODO(jingning) The high bit-depth functions need rework for performance.
      21             : // After we properly fix the high bit-depth function implementations, this
      22             : // file's dependency should be substantially simplified.
      23             : #if DCT_HIGH_BIT_DEPTH
      24             : #define ADD_EPI16 _mm_adds_epi16
      25             : #define SUB_EPI16 _mm_subs_epi16
      26             : 
      27             : #else
      28             : #define ADD_EPI16 _mm_add_epi16
      29             : #define SUB_EPI16 _mm_sub_epi16
      30             : #endif
      31             : 
      32           0 : void FDCT4x4_2D(const int16_t *input, tran_low_t *output, int stride) {
      33             :   // This 2D transform implements 4 vertical 1D transforms followed
      34             :   // by 4 horizontal 1D transforms.  The multiplies and adds are as given
      35             :   // by Chen, Smith and Fralick ('77).  The commands for moving the data
      36             :   // around have been minimized by hand.
      37             :   // For the purposes of the comments, the 16 inputs are referred to at i0
      38             :   // through iF (in raster order), intermediate variables are a0, b0, c0
      39             :   // through f, and correspond to the in-place computations mapped to input
      40             :   // locations.  The outputs, o0 through oF are labeled according to the
      41             :   // output locations.
      42             : 
      43             :   // Constants
      44             :   // These are the coefficients used for the multiplies.
      45             :   // In the comments, pN means cos(N pi /64) and mN is -cos(N pi /64),
      46             :   // where cospi_N_64 = cos(N pi /64)
      47           0 :   const __m128i k__cospi_A =
      48           0 :       octa_set_epi16(cospi_16_64, cospi_16_64, cospi_16_64, cospi_16_64,
      49             :                      cospi_16_64, -cospi_16_64, cospi_16_64, -cospi_16_64);
      50           0 :   const __m128i k__cospi_B =
      51           0 :       octa_set_epi16(cospi_16_64, -cospi_16_64, cospi_16_64, -cospi_16_64,
      52             :                      cospi_16_64, cospi_16_64, cospi_16_64, cospi_16_64);
      53           0 :   const __m128i k__cospi_C =
      54           0 :       octa_set_epi16(cospi_8_64, cospi_24_64, cospi_8_64, cospi_24_64,
      55             :                      cospi_24_64, -cospi_8_64, cospi_24_64, -cospi_8_64);
      56           0 :   const __m128i k__cospi_D =
      57           0 :       octa_set_epi16(cospi_24_64, -cospi_8_64, cospi_24_64, -cospi_8_64,
      58             :                      cospi_8_64, cospi_24_64, cospi_8_64, cospi_24_64);
      59           0 :   const __m128i k__cospi_E =
      60           0 :       octa_set_epi16(cospi_16_64, cospi_16_64, cospi_16_64, cospi_16_64,
      61             :                      cospi_16_64, cospi_16_64, cospi_16_64, cospi_16_64);
      62           0 :   const __m128i k__cospi_F =
      63           0 :       octa_set_epi16(cospi_16_64, -cospi_16_64, cospi_16_64, -cospi_16_64,
      64             :                      cospi_16_64, -cospi_16_64, cospi_16_64, -cospi_16_64);
      65           0 :   const __m128i k__cospi_G =
      66           0 :       octa_set_epi16(cospi_8_64, cospi_24_64, cospi_8_64, cospi_24_64,
      67             :                      -cospi_8_64, -cospi_24_64, -cospi_8_64, -cospi_24_64);
      68           0 :   const __m128i k__cospi_H =
      69           0 :       octa_set_epi16(cospi_24_64, -cospi_8_64, cospi_24_64, -cospi_8_64,
      70             :                      -cospi_24_64, cospi_8_64, -cospi_24_64, cospi_8_64);
      71             : 
      72           0 :   const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
      73             :   // This second rounding constant saves doing some extra adds at the end
      74           0 :   const __m128i k__DCT_CONST_ROUNDING2 =
      75             :       _mm_set1_epi32(DCT_CONST_ROUNDING + (DCT_CONST_ROUNDING << 1));
      76           0 :   const int DCT_CONST_BITS2 = DCT_CONST_BITS + 2;
      77           0 :   const __m128i k__nonzero_bias_a = _mm_setr_epi16(0, 1, 1, 1, 1, 1, 1, 1);
      78           0 :   const __m128i k__nonzero_bias_b = _mm_setr_epi16(1, 0, 0, 0, 0, 0, 0, 0);
      79             :   __m128i in0, in1;
      80             : #if DCT_HIGH_BIT_DEPTH
      81             :   __m128i cmp0, cmp1;
      82             :   int test, overflow;
      83             : #endif
      84             : 
      85             :   // Load inputs.
      86           0 :   in0 = _mm_loadl_epi64((const __m128i *)(input + 0 * stride));
      87           0 :   in1 = _mm_loadl_epi64((const __m128i *)(input + 1 * stride));
      88             :   // in0 = [i0 i1 i2 i3 iC iD iE iF]
      89             :   // in1 = [i4 i5 i6 i7 i8 i9 iA iB]
      90           0 :   in1 = _mm_unpacklo_epi64(
      91           0 :       in1, _mm_loadl_epi64((const __m128i *)(input + 2 * stride)));
      92           0 :   in0 = _mm_unpacklo_epi64(
      93           0 :       in0, _mm_loadl_epi64((const __m128i *)(input + 3 * stride)));
      94             : #if DCT_HIGH_BIT_DEPTH
      95             :   // Check inputs small enough to use optimised code
      96           0 :   cmp0 = _mm_xor_si128(_mm_cmpgt_epi16(in0, _mm_set1_epi16(0x3ff)),
      97             :                        _mm_cmplt_epi16(in0, _mm_set1_epi16(0xfc00)));
      98           0 :   cmp1 = _mm_xor_si128(_mm_cmpgt_epi16(in1, _mm_set1_epi16(0x3ff)),
      99             :                        _mm_cmplt_epi16(in1, _mm_set1_epi16(0xfc00)));
     100           0 :   test = _mm_movemask_epi8(_mm_or_si128(cmp0, cmp1));
     101           0 :   if (test) {
     102           0 :     aom_highbd_fdct4x4_c(input, output, stride);
     103           0 :     return;
     104             :   }
     105             : #endif  // DCT_HIGH_BIT_DEPTH
     106             : 
     107             :   // multiply by 16 to give some extra precision
     108           0 :   in0 = _mm_slli_epi16(in0, 4);
     109           0 :   in1 = _mm_slli_epi16(in1, 4);
     110             :   // if (i == 0 && input[0]) input[0] += 1;
     111             :   // add 1 to the upper left pixel if it is non-zero, which helps reduce
     112             :   // the round-trip error
     113             :   {
     114             :     // The mask will only contain whether the first value is zero, all
     115             :     // other comparison will fail as something shifted by 4 (above << 4)
     116             :     // can never be equal to one. To increment in the non-zero case, we
     117             :     // add the mask and one for the first element:
     118             :     //   - if zero, mask = -1, v = v - 1 + 1 = v
     119             :     //   - if non-zero, mask = 0, v = v + 0 + 1 = v + 1
     120           0 :     __m128i mask = _mm_cmpeq_epi16(in0, k__nonzero_bias_a);
     121           0 :     in0 = _mm_add_epi16(in0, mask);
     122           0 :     in0 = _mm_add_epi16(in0, k__nonzero_bias_b);
     123             :   }
     124             :   // There are 4 total stages, alternating between an add/subtract stage
     125             :   // followed by an multiply-and-add stage.
     126             :   {
     127             :     // Stage 1: Add/subtract
     128             : 
     129             :     // in0 = [i0 i1 i2 i3 iC iD iE iF]
     130             :     // in1 = [i4 i5 i6 i7 i8 i9 iA iB]
     131           0 :     const __m128i r0 = _mm_unpacklo_epi16(in0, in1);
     132           0 :     const __m128i r1 = _mm_unpackhi_epi16(in0, in1);
     133             :     // r0 = [i0 i4 i1 i5 i2 i6 i3 i7]
     134             :     // r1 = [iC i8 iD i9 iE iA iF iB]
     135           0 :     const __m128i r2 = _mm_shuffle_epi32(r0, 0xB4);
     136           0 :     const __m128i r3 = _mm_shuffle_epi32(r1, 0xB4);
     137             :     // r2 = [i0 i4 i1 i5 i3 i7 i2 i6]
     138             :     // r3 = [iC i8 iD i9 iF iB iE iA]
     139             : 
     140           0 :     const __m128i t0 = _mm_add_epi16(r2, r3);
     141           0 :     const __m128i t1 = _mm_sub_epi16(r2, r3);
     142             :     // t0 = [a0 a4 a1 a5 a3 a7 a2 a6]
     143             :     // t1 = [aC a8 aD a9 aF aB aE aA]
     144             : 
     145             :     // Stage 2: multiply by constants (which gets us into 32 bits).
     146             :     // The constants needed here are:
     147             :     // k__cospi_A = [p16 p16 p16 p16 p16 m16 p16 m16]
     148             :     // k__cospi_B = [p16 m16 p16 m16 p16 p16 p16 p16]
     149             :     // k__cospi_C = [p08 p24 p08 p24 p24 m08 p24 m08]
     150             :     // k__cospi_D = [p24 m08 p24 m08 p08 p24 p08 p24]
     151           0 :     const __m128i u0 = _mm_madd_epi16(t0, k__cospi_A);
     152           0 :     const __m128i u2 = _mm_madd_epi16(t0, k__cospi_B);
     153           0 :     const __m128i u1 = _mm_madd_epi16(t1, k__cospi_C);
     154           0 :     const __m128i u3 = _mm_madd_epi16(t1, k__cospi_D);
     155             :     // Then add and right-shift to get back to 16-bit range
     156           0 :     const __m128i v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
     157           0 :     const __m128i v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
     158           0 :     const __m128i v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
     159           0 :     const __m128i v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
     160           0 :     const __m128i w0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
     161           0 :     const __m128i w1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
     162           0 :     const __m128i w2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
     163           0 :     const __m128i w3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
     164             :     // w0 = [b0 b1 b7 b6]
     165             :     // w1 = [b8 b9 bF bE]
     166             :     // w2 = [b4 b5 b3 b2]
     167             :     // w3 = [bC bD bB bA]
     168           0 :     const __m128i x0 = _mm_packs_epi32(w0, w1);
     169           0 :     const __m128i x1 = _mm_packs_epi32(w2, w3);
     170             : #if DCT_HIGH_BIT_DEPTH
     171           0 :     overflow = check_epi16_overflow_x2(&x0, &x1);
     172           0 :     if (overflow) {
     173           0 :       aom_highbd_fdct4x4_c(input, output, stride);
     174           0 :       return;
     175             :     }
     176             : #endif  // DCT_HIGH_BIT_DEPTH
     177             :     // x0 = [b0 b1 b7 b6 b8 b9 bF bE]
     178             :     // x1 = [b4 b5 b3 b2 bC bD bB bA]
     179           0 :     in0 = _mm_shuffle_epi32(x0, 0xD8);
     180           0 :     in1 = _mm_shuffle_epi32(x1, 0x8D);
     181             :     // in0 = [b0 b1 b8 b9 b7 b6 bF bE]
     182             :     // in1 = [b3 b2 bB bA b4 b5 bC bD]
     183             :   }
     184             :   {
     185             :     // vertical DCTs finished. Now we do the horizontal DCTs.
     186             :     // Stage 3: Add/subtract
     187             : 
     188             :     // t0 = [c0 c1 c8 c9  c4  c5  cC  cD]
     189             :     // t1 = [c3 c2 cB cA -c7 -c6 -cF -cE]
     190           0 :     const __m128i t0 = ADD_EPI16(in0, in1);
     191           0 :     const __m128i t1 = SUB_EPI16(in0, in1);
     192             : #if DCT_HIGH_BIT_DEPTH
     193           0 :     overflow = check_epi16_overflow_x2(&t0, &t1);
     194           0 :     if (overflow) {
     195           0 :       aom_highbd_fdct4x4_c(input, output, stride);
     196           0 :       return;
     197             :     }
     198             : #endif  // DCT_HIGH_BIT_DEPTH
     199             : 
     200             :     // Stage 4: multiply by constants (which gets us into 32 bits).
     201             :     {
     202             :       // The constants needed here are:
     203             :       // k__cospi_E = [p16 p16 p16 p16 p16 p16 p16 p16]
     204             :       // k__cospi_F = [p16 m16 p16 m16 p16 m16 p16 m16]
     205             :       // k__cospi_G = [p08 p24 p08 p24 m08 m24 m08 m24]
     206             :       // k__cospi_H = [p24 m08 p24 m08 m24 p08 m24 p08]
     207           0 :       const __m128i u0 = _mm_madd_epi16(t0, k__cospi_E);
     208           0 :       const __m128i u1 = _mm_madd_epi16(t0, k__cospi_F);
     209           0 :       const __m128i u2 = _mm_madd_epi16(t1, k__cospi_G);
     210           0 :       const __m128i u3 = _mm_madd_epi16(t1, k__cospi_H);
     211             :       // Then add and right-shift to get back to 16-bit range
     212             :       // but this combines the final right-shift as well to save operations
     213             :       // This unusual rounding operations is to maintain bit-accurate
     214             :       // compatibility with the c version of this function which has two
     215             :       // rounding steps in a row.
     216           0 :       const __m128i v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING2);
     217           0 :       const __m128i v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING2);
     218           0 :       const __m128i v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING2);
     219           0 :       const __m128i v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING2);
     220           0 :       const __m128i w0 = _mm_srai_epi32(v0, DCT_CONST_BITS2);
     221           0 :       const __m128i w1 = _mm_srai_epi32(v1, DCT_CONST_BITS2);
     222           0 :       const __m128i w2 = _mm_srai_epi32(v2, DCT_CONST_BITS2);
     223           0 :       const __m128i w3 = _mm_srai_epi32(v3, DCT_CONST_BITS2);
     224             :       // w0 = [o0 o4 o8 oC]
     225             :       // w1 = [o2 o6 oA oE]
     226             :       // w2 = [o1 o5 o9 oD]
     227             :       // w3 = [o3 o7 oB oF]
     228             :       // remember the o's are numbered according to the correct output location
     229           0 :       const __m128i x0 = _mm_packs_epi32(w0, w1);
     230           0 :       const __m128i x1 = _mm_packs_epi32(w2, w3);
     231             : #if DCT_HIGH_BIT_DEPTH
     232           0 :       overflow = check_epi16_overflow_x2(&x0, &x1);
     233           0 :       if (overflow) {
     234           0 :         aom_highbd_fdct4x4_c(input, output, stride);
     235           0 :         return;
     236             :       }
     237             : #endif  // DCT_HIGH_BIT_DEPTH
     238             :       {
     239             :         // x0 = [o0 o4 o8 oC o2 o6 oA oE]
     240             :         // x1 = [o1 o5 o9 oD o3 o7 oB oF]
     241           0 :         const __m128i y0 = _mm_unpacklo_epi16(x0, x1);
     242           0 :         const __m128i y1 = _mm_unpackhi_epi16(x0, x1);
     243             :         // y0 = [o0 o1 o4 o5 o8 o9 oC oD]
     244             :         // y1 = [o2 o3 o6 o7 oA oB oE oF]
     245           0 :         in0 = _mm_unpacklo_epi32(y0, y1);
     246             :         // in0 = [o0 o1 o2 o3 o4 o5 o6 o7]
     247           0 :         in1 = _mm_unpackhi_epi32(y0, y1);
     248             :         // in1 = [o8 o9 oA oB oC oD oE oF]
     249             :       }
     250             :     }
     251             :   }
     252             :   // Post-condition (v + 1) >> 2 is now incorporated into previous
     253             :   // add and right-shift commands.  Only 2 store instructions needed
     254             :   // because we are using the fact that 1/3 are stored just after 0/2.
     255           0 :   storeu_output(&in0, output + 0 * 4);
     256           0 :   storeu_output(&in1, output + 2 * 4);
     257           0 : }
     258             : 
     259           0 : void FDCT8x8_2D(const int16_t *input, tran_low_t *output, int stride) {
     260             :   int pass;
     261             :   // Constants
     262             :   //    When we use them, in one case, they are all the same. In all others
     263             :   //    it's a pair of them that we need to repeat four times. This is done
     264             :   //    by constructing the 32 bit constant corresponding to that pair.
     265           0 :   const __m128i k__cospi_p16_p16 = _mm_set1_epi16((int16_t)cospi_16_64);
     266           0 :   const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
     267           0 :   const __m128i k__cospi_p24_p08 = pair_set_epi16(cospi_24_64, cospi_8_64);
     268           0 :   const __m128i k__cospi_m08_p24 = pair_set_epi16(-cospi_8_64, cospi_24_64);
     269           0 :   const __m128i k__cospi_p28_p04 = pair_set_epi16(cospi_28_64, cospi_4_64);
     270           0 :   const __m128i k__cospi_m04_p28 = pair_set_epi16(-cospi_4_64, cospi_28_64);
     271           0 :   const __m128i k__cospi_p12_p20 = pair_set_epi16(cospi_12_64, cospi_20_64);
     272           0 :   const __m128i k__cospi_m20_p12 = pair_set_epi16(-cospi_20_64, cospi_12_64);
     273           0 :   const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
     274             : #if DCT_HIGH_BIT_DEPTH
     275             :   int overflow;
     276             : #endif
     277             :   // Load input
     278           0 :   __m128i in0 = _mm_load_si128((const __m128i *)(input + 0 * stride));
     279           0 :   __m128i in1 = _mm_load_si128((const __m128i *)(input + 1 * stride));
     280           0 :   __m128i in2 = _mm_load_si128((const __m128i *)(input + 2 * stride));
     281           0 :   __m128i in3 = _mm_load_si128((const __m128i *)(input + 3 * stride));
     282           0 :   __m128i in4 = _mm_load_si128((const __m128i *)(input + 4 * stride));
     283           0 :   __m128i in5 = _mm_load_si128((const __m128i *)(input + 5 * stride));
     284           0 :   __m128i in6 = _mm_load_si128((const __m128i *)(input + 6 * stride));
     285           0 :   __m128i in7 = _mm_load_si128((const __m128i *)(input + 7 * stride));
     286             :   // Pre-condition input (shift by two)
     287           0 :   in0 = _mm_slli_epi16(in0, 2);
     288           0 :   in1 = _mm_slli_epi16(in1, 2);
     289           0 :   in2 = _mm_slli_epi16(in2, 2);
     290           0 :   in3 = _mm_slli_epi16(in3, 2);
     291           0 :   in4 = _mm_slli_epi16(in4, 2);
     292           0 :   in5 = _mm_slli_epi16(in5, 2);
     293           0 :   in6 = _mm_slli_epi16(in6, 2);
     294           0 :   in7 = _mm_slli_epi16(in7, 2);
     295             : 
     296             :   // We do two passes, first the columns, then the rows. The results of the
     297             :   // first pass are transposed so that the same column code can be reused. The
     298             :   // results of the second pass are also transposed so that the rows (processed
     299             :   // as columns) are put back in row positions.
     300           0 :   for (pass = 0; pass < 2; pass++) {
     301             :     // To store results of each pass before the transpose.
     302             :     __m128i res0, res1, res2, res3, res4, res5, res6, res7;
     303             :     // Add/subtract
     304           0 :     const __m128i q0 = ADD_EPI16(in0, in7);
     305           0 :     const __m128i q1 = ADD_EPI16(in1, in6);
     306           0 :     const __m128i q2 = ADD_EPI16(in2, in5);
     307           0 :     const __m128i q3 = ADD_EPI16(in3, in4);
     308           0 :     const __m128i q4 = SUB_EPI16(in3, in4);
     309           0 :     const __m128i q5 = SUB_EPI16(in2, in5);
     310           0 :     const __m128i q6 = SUB_EPI16(in1, in6);
     311           0 :     const __m128i q7 = SUB_EPI16(in0, in7);
     312             : #if DCT_HIGH_BIT_DEPTH
     313           0 :     if (pass == 1) {
     314           0 :       overflow =
     315             :           check_epi16_overflow_x8(&q0, &q1, &q2, &q3, &q4, &q5, &q6, &q7);
     316           0 :       if (overflow) {
     317           0 :         aom_highbd_fdct8x8_c(input, output, stride);
     318           0 :         return;
     319             :       }
     320             :     }
     321             : #endif  // DCT_HIGH_BIT_DEPTH
     322             :     // Work on first four results
     323             :     {
     324             :       // Add/subtract
     325           0 :       const __m128i r0 = ADD_EPI16(q0, q3);
     326           0 :       const __m128i r1 = ADD_EPI16(q1, q2);
     327           0 :       const __m128i r2 = SUB_EPI16(q1, q2);
     328           0 :       const __m128i r3 = SUB_EPI16(q0, q3);
     329             : #if DCT_HIGH_BIT_DEPTH
     330           0 :       overflow = check_epi16_overflow_x4(&r0, &r1, &r2, &r3);
     331           0 :       if (overflow) {
     332           0 :         aom_highbd_fdct8x8_c(input, output, stride);
     333           0 :         return;
     334             :       }
     335             : #endif  // DCT_HIGH_BIT_DEPTH
     336             :       // Interleave to do the multiply by constants which gets us into 32bits
     337             :       {
     338           0 :         const __m128i t0 = _mm_unpacklo_epi16(r0, r1);
     339           0 :         const __m128i t1 = _mm_unpackhi_epi16(r0, r1);
     340           0 :         const __m128i t2 = _mm_unpacklo_epi16(r2, r3);
     341           0 :         const __m128i t3 = _mm_unpackhi_epi16(r2, r3);
     342           0 :         const __m128i u0 = _mm_madd_epi16(t0, k__cospi_p16_p16);
     343           0 :         const __m128i u1 = _mm_madd_epi16(t1, k__cospi_p16_p16);
     344           0 :         const __m128i u2 = _mm_madd_epi16(t0, k__cospi_p16_m16);
     345           0 :         const __m128i u3 = _mm_madd_epi16(t1, k__cospi_p16_m16);
     346           0 :         const __m128i u4 = _mm_madd_epi16(t2, k__cospi_p24_p08);
     347           0 :         const __m128i u5 = _mm_madd_epi16(t3, k__cospi_p24_p08);
     348           0 :         const __m128i u6 = _mm_madd_epi16(t2, k__cospi_m08_p24);
     349           0 :         const __m128i u7 = _mm_madd_epi16(t3, k__cospi_m08_p24);
     350             :         // dct_const_round_shift
     351           0 :         const __m128i v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
     352           0 :         const __m128i v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
     353           0 :         const __m128i v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
     354           0 :         const __m128i v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
     355           0 :         const __m128i v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
     356           0 :         const __m128i v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
     357           0 :         const __m128i v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
     358           0 :         const __m128i v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
     359           0 :         const __m128i w0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
     360           0 :         const __m128i w1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
     361           0 :         const __m128i w2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
     362           0 :         const __m128i w3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
     363           0 :         const __m128i w4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
     364           0 :         const __m128i w5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
     365           0 :         const __m128i w6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
     366           0 :         const __m128i w7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
     367             :         // Combine
     368           0 :         res0 = _mm_packs_epi32(w0, w1);
     369           0 :         res4 = _mm_packs_epi32(w2, w3);
     370           0 :         res2 = _mm_packs_epi32(w4, w5);
     371           0 :         res6 = _mm_packs_epi32(w6, w7);
     372             : #if DCT_HIGH_BIT_DEPTH
     373           0 :         overflow = check_epi16_overflow_x4(&res0, &res4, &res2, &res6);
     374           0 :         if (overflow) {
     375           0 :           aom_highbd_fdct8x8_c(input, output, stride);
     376           0 :           return;
     377             :         }
     378             : #endif  // DCT_HIGH_BIT_DEPTH
     379             :       }
     380             :     }
     381             :     // Work on next four results
     382             :     {
     383             :       // Interleave to do the multiply by constants which gets us into 32bits
     384           0 :       const __m128i d0 = _mm_unpacklo_epi16(q6, q5);
     385           0 :       const __m128i d1 = _mm_unpackhi_epi16(q6, q5);
     386           0 :       const __m128i e0 = _mm_madd_epi16(d0, k__cospi_p16_m16);
     387           0 :       const __m128i e1 = _mm_madd_epi16(d1, k__cospi_p16_m16);
     388           0 :       const __m128i e2 = _mm_madd_epi16(d0, k__cospi_p16_p16);
     389           0 :       const __m128i e3 = _mm_madd_epi16(d1, k__cospi_p16_p16);
     390             :       // dct_const_round_shift
     391           0 :       const __m128i f0 = _mm_add_epi32(e0, k__DCT_CONST_ROUNDING);
     392           0 :       const __m128i f1 = _mm_add_epi32(e1, k__DCT_CONST_ROUNDING);
     393           0 :       const __m128i f2 = _mm_add_epi32(e2, k__DCT_CONST_ROUNDING);
     394           0 :       const __m128i f3 = _mm_add_epi32(e3, k__DCT_CONST_ROUNDING);
     395           0 :       const __m128i s0 = _mm_srai_epi32(f0, DCT_CONST_BITS);
     396           0 :       const __m128i s1 = _mm_srai_epi32(f1, DCT_CONST_BITS);
     397           0 :       const __m128i s2 = _mm_srai_epi32(f2, DCT_CONST_BITS);
     398           0 :       const __m128i s3 = _mm_srai_epi32(f3, DCT_CONST_BITS);
     399             :       // Combine
     400           0 :       const __m128i r0 = _mm_packs_epi32(s0, s1);
     401           0 :       const __m128i r1 = _mm_packs_epi32(s2, s3);
     402             : #if DCT_HIGH_BIT_DEPTH
     403           0 :       overflow = check_epi16_overflow_x2(&r0, &r1);
     404           0 :       if (overflow) {
     405           0 :         aom_highbd_fdct8x8_c(input, output, stride);
     406           0 :         return;
     407             :       }
     408             : #endif  // DCT_HIGH_BIT_DEPTH
     409             :       {
     410             :         // Add/subtract
     411           0 :         const __m128i x0 = ADD_EPI16(q4, r0);
     412           0 :         const __m128i x1 = SUB_EPI16(q4, r0);
     413           0 :         const __m128i x2 = SUB_EPI16(q7, r1);
     414           0 :         const __m128i x3 = ADD_EPI16(q7, r1);
     415             : #if DCT_HIGH_BIT_DEPTH
     416           0 :         overflow = check_epi16_overflow_x4(&x0, &x1, &x2, &x3);
     417           0 :         if (overflow) {
     418           0 :           aom_highbd_fdct8x8_c(input, output, stride);
     419           0 :           return;
     420             :         }
     421             : #endif  // DCT_HIGH_BIT_DEPTH
     422             :         // Interleave to do the multiply by constants which gets us into 32bits
     423             :         {
     424           0 :           const __m128i t0 = _mm_unpacklo_epi16(x0, x3);
     425           0 :           const __m128i t1 = _mm_unpackhi_epi16(x0, x3);
     426           0 :           const __m128i t2 = _mm_unpacklo_epi16(x1, x2);
     427           0 :           const __m128i t3 = _mm_unpackhi_epi16(x1, x2);
     428           0 :           const __m128i u0 = _mm_madd_epi16(t0, k__cospi_p28_p04);
     429           0 :           const __m128i u1 = _mm_madd_epi16(t1, k__cospi_p28_p04);
     430           0 :           const __m128i u2 = _mm_madd_epi16(t0, k__cospi_m04_p28);
     431           0 :           const __m128i u3 = _mm_madd_epi16(t1, k__cospi_m04_p28);
     432           0 :           const __m128i u4 = _mm_madd_epi16(t2, k__cospi_p12_p20);
     433           0 :           const __m128i u5 = _mm_madd_epi16(t3, k__cospi_p12_p20);
     434           0 :           const __m128i u6 = _mm_madd_epi16(t2, k__cospi_m20_p12);
     435           0 :           const __m128i u7 = _mm_madd_epi16(t3, k__cospi_m20_p12);
     436             :           // dct_const_round_shift
     437           0 :           const __m128i v0 = _mm_add_epi32(u0, k__DCT_CONST_ROUNDING);
     438           0 :           const __m128i v1 = _mm_add_epi32(u1, k__DCT_CONST_ROUNDING);
     439           0 :           const __m128i v2 = _mm_add_epi32(u2, k__DCT_CONST_ROUNDING);
     440           0 :           const __m128i v3 = _mm_add_epi32(u3, k__DCT_CONST_ROUNDING);
     441           0 :           const __m128i v4 = _mm_add_epi32(u4, k__DCT_CONST_ROUNDING);
     442           0 :           const __m128i v5 = _mm_add_epi32(u5, k__DCT_CONST_ROUNDING);
     443           0 :           const __m128i v6 = _mm_add_epi32(u6, k__DCT_CONST_ROUNDING);
     444           0 :           const __m128i v7 = _mm_add_epi32(u7, k__DCT_CONST_ROUNDING);
     445           0 :           const __m128i w0 = _mm_srai_epi32(v0, DCT_CONST_BITS);
     446           0 :           const __m128i w1 = _mm_srai_epi32(v1, DCT_CONST_BITS);
     447           0 :           const __m128i w2 = _mm_srai_epi32(v2, DCT_CONST_BITS);
     448           0 :           const __m128i w3 = _mm_srai_epi32(v3, DCT_CONST_BITS);
     449           0 :           const __m128i w4 = _mm_srai_epi32(v4, DCT_CONST_BITS);
     450           0 :           const __m128i w5 = _mm_srai_epi32(v5, DCT_CONST_BITS);
     451           0 :           const __m128i w6 = _mm_srai_epi32(v6, DCT_CONST_BITS);
     452           0 :           const __m128i w7 = _mm_srai_epi32(v7, DCT_CONST_BITS);
     453             :           // Combine
     454           0 :           res1 = _mm_packs_epi32(w0, w1);
     455           0 :           res7 = _mm_packs_epi32(w2, w3);
     456           0 :           res5 = _mm_packs_epi32(w4, w5);
     457           0 :           res3 = _mm_packs_epi32(w6, w7);
     458             : #if DCT_HIGH_BIT_DEPTH
     459           0 :           overflow = check_epi16_overflow_x4(&res1, &res7, &res5, &res3);
     460           0 :           if (overflow) {
     461           0 :             aom_highbd_fdct8x8_c(input, output, stride);
     462           0 :             return;
     463             :           }
     464             : #endif  // DCT_HIGH_BIT_DEPTH
     465             :         }
     466             :       }
     467             :     }
     468             :     // Transpose the 8x8.
     469             :     {
     470             :       // 00 01 02 03 04 05 06 07
     471             :       // 10 11 12 13 14 15 16 17
     472             :       // 20 21 22 23 24 25 26 27
     473             :       // 30 31 32 33 34 35 36 37
     474             :       // 40 41 42 43 44 45 46 47
     475             :       // 50 51 52 53 54 55 56 57
     476             :       // 60 61 62 63 64 65 66 67
     477             :       // 70 71 72 73 74 75 76 77
     478           0 :       const __m128i tr0_0 = _mm_unpacklo_epi16(res0, res1);
     479           0 :       const __m128i tr0_1 = _mm_unpacklo_epi16(res2, res3);
     480           0 :       const __m128i tr0_2 = _mm_unpackhi_epi16(res0, res1);
     481           0 :       const __m128i tr0_3 = _mm_unpackhi_epi16(res2, res3);
     482           0 :       const __m128i tr0_4 = _mm_unpacklo_epi16(res4, res5);
     483           0 :       const __m128i tr0_5 = _mm_unpacklo_epi16(res6, res7);
     484           0 :       const __m128i tr0_6 = _mm_unpackhi_epi16(res4, res5);
     485           0 :       const __m128i tr0_7 = _mm_unpackhi_epi16(res6, res7);
     486             :       // 00 10 01 11 02 12 03 13
     487             :       // 20 30 21 31 22 32 23 33
     488             :       // 04 14 05 15 06 16 07 17
     489             :       // 24 34 25 35 26 36 27 37
     490             :       // 40 50 41 51 42 52 43 53
     491             :       // 60 70 61 71 62 72 63 73
     492             :       // 54 54 55 55 56 56 57 57
     493             :       // 64 74 65 75 66 76 67 77
     494           0 :       const __m128i tr1_0 = _mm_unpacklo_epi32(tr0_0, tr0_1);
     495           0 :       const __m128i tr1_1 = _mm_unpacklo_epi32(tr0_2, tr0_3);
     496           0 :       const __m128i tr1_2 = _mm_unpackhi_epi32(tr0_0, tr0_1);
     497           0 :       const __m128i tr1_3 = _mm_unpackhi_epi32(tr0_2, tr0_3);
     498           0 :       const __m128i tr1_4 = _mm_unpacklo_epi32(tr0_4, tr0_5);
     499           0 :       const __m128i tr1_5 = _mm_unpacklo_epi32(tr0_6, tr0_7);
     500           0 :       const __m128i tr1_6 = _mm_unpackhi_epi32(tr0_4, tr0_5);
     501           0 :       const __m128i tr1_7 = _mm_unpackhi_epi32(tr0_6, tr0_7);
     502             :       // 00 10 20 30 01 11 21 31
     503             :       // 40 50 60 70 41 51 61 71
     504             :       // 02 12 22 32 03 13 23 33
     505             :       // 42 52 62 72 43 53 63 73
     506             :       // 04 14 24 34 05 15 21 36
     507             :       // 44 54 64 74 45 55 61 76
     508             :       // 06 16 26 36 07 17 27 37
     509             :       // 46 56 66 76 47 57 67 77
     510           0 :       in0 = _mm_unpacklo_epi64(tr1_0, tr1_4);
     511           0 :       in1 = _mm_unpackhi_epi64(tr1_0, tr1_4);
     512           0 :       in2 = _mm_unpacklo_epi64(tr1_2, tr1_6);
     513           0 :       in3 = _mm_unpackhi_epi64(tr1_2, tr1_6);
     514           0 :       in4 = _mm_unpacklo_epi64(tr1_1, tr1_5);
     515           0 :       in5 = _mm_unpackhi_epi64(tr1_1, tr1_5);
     516           0 :       in6 = _mm_unpacklo_epi64(tr1_3, tr1_7);
     517           0 :       in7 = _mm_unpackhi_epi64(tr1_3, tr1_7);
     518             :       // 00 10 20 30 40 50 60 70
     519             :       // 01 11 21 31 41 51 61 71
     520             :       // 02 12 22 32 42 52 62 72
     521             :       // 03 13 23 33 43 53 63 73
     522             :       // 04 14 24 34 44 54 64 74
     523             :       // 05 15 25 35 45 55 65 75
     524             :       // 06 16 26 36 46 56 66 76
     525             :       // 07 17 27 37 47 57 67 77
     526             :     }
     527             :   }
     528             :   // Post-condition output and store it
     529             :   {
     530             :     // Post-condition (division by two)
     531             :     //    division of two 16 bits signed numbers using shifts
     532             :     //    n / 2 = (n - (n >> 15)) >> 1
     533           0 :     const __m128i sign_in0 = _mm_srai_epi16(in0, 15);
     534           0 :     const __m128i sign_in1 = _mm_srai_epi16(in1, 15);
     535           0 :     const __m128i sign_in2 = _mm_srai_epi16(in2, 15);
     536           0 :     const __m128i sign_in3 = _mm_srai_epi16(in3, 15);
     537           0 :     const __m128i sign_in4 = _mm_srai_epi16(in4, 15);
     538           0 :     const __m128i sign_in5 = _mm_srai_epi16(in5, 15);
     539           0 :     const __m128i sign_in6 = _mm_srai_epi16(in6, 15);
     540           0 :     const __m128i sign_in7 = _mm_srai_epi16(in7, 15);
     541           0 :     in0 = _mm_sub_epi16(in0, sign_in0);
     542           0 :     in1 = _mm_sub_epi16(in1, sign_in1);
     543           0 :     in2 = _mm_sub_epi16(in2, sign_in2);
     544           0 :     in3 = _mm_sub_epi16(in3, sign_in3);
     545           0 :     in4 = _mm_sub_epi16(in4, sign_in4);
     546           0 :     in5 = _mm_sub_epi16(in5, sign_in5);
     547           0 :     in6 = _mm_sub_epi16(in6, sign_in6);
     548           0 :     in7 = _mm_sub_epi16(in7, sign_in7);
     549           0 :     in0 = _mm_srai_epi16(in0, 1);
     550           0 :     in1 = _mm_srai_epi16(in1, 1);
     551           0 :     in2 = _mm_srai_epi16(in2, 1);
     552           0 :     in3 = _mm_srai_epi16(in3, 1);
     553           0 :     in4 = _mm_srai_epi16(in4, 1);
     554           0 :     in5 = _mm_srai_epi16(in5, 1);
     555           0 :     in6 = _mm_srai_epi16(in6, 1);
     556           0 :     in7 = _mm_srai_epi16(in7, 1);
     557             :     // store results
     558           0 :     store_output(&in0, (output + 0 * 8));
     559           0 :     store_output(&in1, (output + 1 * 8));
     560           0 :     store_output(&in2, (output + 2 * 8));
     561           0 :     store_output(&in3, (output + 3 * 8));
     562           0 :     store_output(&in4, (output + 4 * 8));
     563           0 :     store_output(&in5, (output + 5 * 8));
     564           0 :     store_output(&in6, (output + 6 * 8));
     565           0 :     store_output(&in7, (output + 7 * 8));
     566             :   }
     567           0 : }
     568             : 
     569           0 : void FDCT16x16_2D(const int16_t *input, tran_low_t *output, int stride) {
     570             :   // The 2D transform is done with two passes which are actually pretty
     571             :   // similar. In the first one, we transform the columns and transpose
     572             :   // the results. In the second one, we transform the rows. To achieve that,
     573             :   // as the first pass results are transposed, we transpose the columns (that
     574             :   // is the transposed rows) and transpose the results (so that it goes back
     575             :   // in normal/row positions).
     576             :   int pass;
     577             :   // We need an intermediate buffer between passes.
     578             :   DECLARE_ALIGNED(16, int16_t, intermediate[256]);
     579           0 :   const int16_t *in = input;
     580           0 :   int16_t *out0 = intermediate;
     581           0 :   tran_low_t *out1 = output;
     582             :   // Constants
     583             :   //    When we use them, in one case, they are all the same. In all others
     584             :   //    it's a pair of them that we need to repeat four times. This is done
     585             :   //    by constructing the 32 bit constant corresponding to that pair.
     586           0 :   const __m128i k__cospi_p16_p16 = _mm_set1_epi16((int16_t)cospi_16_64);
     587           0 :   const __m128i k__cospi_p16_m16 = pair_set_epi16(cospi_16_64, -cospi_16_64);
     588           0 :   const __m128i k__cospi_p24_p08 = pair_set_epi16(cospi_24_64, cospi_8_64);
     589           0 :   const __m128i k__cospi_p08_m24 = pair_set_epi16(cospi_8_64, -cospi_24_64);
     590           0 :   const __m128i k__cospi_m08_p24 = pair_set_epi16(-cospi_8_64, cospi_24_64);
     591           0 :   const __m128i k__cospi_p28_p04 = pair_set_epi16(cospi_28_64, cospi_4_64);
     592           0 :   const __m128i k__cospi_m04_p28 = pair_set_epi16(-cospi_4_64, cospi_28_64);
     593           0 :   const __m128i k__cospi_p12_p20 = pair_set_epi16(cospi_12_64, cospi_20_64);
     594           0 :   const __m128i k__cospi_m20_p12 = pair_set_epi16(-cospi_20_64, cospi_12_64);
     595           0 :   const __m128i k__cospi_p30_p02 = pair_set_epi16(cospi_30_64, cospi_2_64);
     596           0 :   const __m128i k__cospi_p14_p18 = pair_set_epi16(cospi_14_64, cospi_18_64);
     597           0 :   const __m128i k__cospi_m02_p30 = pair_set_epi16(-cospi_2_64, cospi_30_64);
     598           0 :   const __m128i k__cospi_m18_p14 = pair_set_epi16(-cospi_18_64, cospi_14_64);
     599           0 :   const __m128i k__cospi_p22_p10 = pair_set_epi16(cospi_22_64, cospi_10_64);
     600           0 :   const __m128i k__cospi_p06_p26 = pair_set_epi16(cospi_6_64, cospi_26_64);
     601           0 :   const __m128i k__cospi_m10_p22 = pair_set_epi16(-cospi_10_64, cospi_22_64);
     602           0 :   const __m128i k__cospi_m26_p06 = pair_set_epi16(-cospi_26_64, cospi_6_64);
     603           0 :   const __m128i k__DCT_CONST_ROUNDING = _mm_set1_epi32(DCT_CONST_ROUNDING);
     604           0 :   const __m128i kOne = _mm_set1_epi16(1);
     605             :   // Do the two transform/transpose passes
     606           0 :   for (pass = 0; pass < 2; ++pass) {
     607             :     // We process eight columns (transposed rows in second pass) at a time.
     608             :     int column_start;
     609             : #if DCT_HIGH_BIT_DEPTH
     610             :     int overflow;
     611             : #endif
     612           0 :     for (column_start = 0; column_start < 16; column_start += 8) {
     613             :       __m128i in00, in01, in02, in03, in04, in05, in06, in07;
     614             :       __m128i in08, in09, in10, in11, in12, in13, in14, in15;
     615             :       __m128i input0, input1, input2, input3, input4, input5, input6, input7;
     616             :       __m128i step1_0, step1_1, step1_2, step1_3;
     617             :       __m128i step1_4, step1_5, step1_6, step1_7;
     618             :       __m128i step2_1, step2_2, step2_3, step2_4, step2_5, step2_6;
     619             :       __m128i step3_0, step3_1, step3_2, step3_3;
     620             :       __m128i step3_4, step3_5, step3_6, step3_7;
     621             :       __m128i res00, res01, res02, res03, res04, res05, res06, res07;
     622             :       __m128i res08, res09, res10, res11, res12, res13, res14, res15;
     623             :       // Load and pre-condition input.
     624           0 :       if (0 == pass) {
     625           0 :         in00 = _mm_load_si128((const __m128i *)(in + 0 * stride));
     626           0 :         in01 = _mm_load_si128((const __m128i *)(in + 1 * stride));
     627           0 :         in02 = _mm_load_si128((const __m128i *)(in + 2 * stride));
     628           0 :         in03 = _mm_load_si128((const __m128i *)(in + 3 * stride));
     629           0 :         in04 = _mm_load_si128((const __m128i *)(in + 4 * stride));
     630           0 :         in05 = _mm_load_si128((const __m128i *)(in + 5 * stride));
     631           0 :         in06 = _mm_load_si128((const __m128i *)(in + 6 * stride));
     632           0 :         in07 = _mm_load_si128((const __m128i *)(in + 7 * stride));
     633           0 :         in08 = _mm_load_si128((const __m128i *)(in + 8 * stride));
     634           0 :         in09 = _mm_load_si128((const __m128i *)(in + 9 * stride));
     635           0 :         in10 = _mm_load_si128((const __m128i *)(in + 10 * stride));
     636           0 :         in11 = _mm_load_si128((const __m128i *)(in + 11 * stride));
     637           0 :         in12 = _mm_load_si128((const __m128i *)(in + 12 * stride));
     638           0 :         in13 = _mm_load_si128((const __m128i *)(in + 13 * stride));
     639           0 :         in14 = _mm_load_si128((const __m128i *)(in + 14 * stride));
     640           0 :         in15 = _mm_load_si128((const __m128i *)(in + 15 * stride));
     641             :         // x = x << 2
     642           0 :         in00 = _mm_slli_epi16(in00, 2);
     643           0 :         in01 = _mm_slli_epi16(in01, 2);
     644           0 :         in02 = _mm_slli_epi16(in02, 2);
     645           0 :         in03 = _mm_slli_epi16(in03, 2);
     646           0 :         in04 = _mm_slli_epi16(in04, 2);
     647           0 :         in05 = _mm_slli_epi16(in05, 2);
     648           0 :         in06 = _mm_slli_epi16(in06, 2);
     649           0 :         in07 = _mm_slli_epi16(in07, 2);
     650           0 :         in08 = _mm_slli_epi16(in08, 2);
     651           0 :         in09 = _mm_slli_epi16(in09, 2);
     652           0 :         in10 = _mm_slli_epi16(in10, 2);
     653           0 :         in11 = _mm_slli_epi16(in11, 2);
     654           0 :         in12 = _mm_slli_epi16(in12, 2);
     655           0 :         in13 = _mm_slli_epi16(in13, 2);
     656           0 :         in14 = _mm_slli_epi16(in14, 2);
     657           0 :         in15 = _mm_slli_epi16(in15, 2);
     658             :       } else {
     659           0 :         in00 = _mm_load_si128((const __m128i *)(in + 0 * 16));
     660           0 :         in01 = _mm_load_si128((const __m128i *)(in + 1 * 16));
     661           0 :         in02 = _mm_load_si128((const __m128i *)(in + 2 * 16));
     662           0 :         in03 = _mm_load_si128((const __m128i *)(in + 3 * 16));
     663           0 :         in04 = _mm_load_si128((const __m128i *)(in + 4 * 16));
     664           0 :         in05 = _mm_load_si128((const __m128i *)(in + 5 * 16));
     665           0 :         in06 = _mm_load_si128((const __m128i *)(in + 6 * 16));
     666           0 :         in07 = _mm_load_si128((const __m128i *)(in + 7 * 16));
     667           0 :         in08 = _mm_load_si128((const __m128i *)(in + 8 * 16));
     668           0 :         in09 = _mm_load_si128((const __m128i *)(in + 9 * 16));
     669           0 :         in10 = _mm_load_si128((const __m128i *)(in + 10 * 16));
     670           0 :         in11 = _mm_load_si128((const __m128i *)(in + 11 * 16));
     671           0 :         in12 = _mm_load_si128((const __m128i *)(in + 12 * 16));
     672           0 :         in13 = _mm_load_si128((const __m128i *)(in + 13 * 16));
     673           0 :         in14 = _mm_load_si128((const __m128i *)(in + 14 * 16));
     674           0 :         in15 = _mm_load_si128((const __m128i *)(in + 15 * 16));
     675             :         // x = (x + 1) >> 2
     676           0 :         in00 = _mm_add_epi16(in00, kOne);
     677           0 :         in01 = _mm_add_epi16(in01, kOne);
     678           0 :         in02 = _mm_add_epi16(in02, kOne);
     679           0 :         in03 = _mm_add_epi16(in03, kOne);
     680           0 :         in04 = _mm_add_epi16(in04, kOne);
     681           0 :         in05 = _mm_add_epi16(in05, kOne);
     682           0 :         in06 = _mm_add_epi16(in06, kOne);
     683           0 :         in07 = _mm_add_epi16(in07, kOne);
     684           0 :         in08 = _mm_add_epi16(in08, kOne);
     685           0 :         in09 = _mm_add_epi16(in09, kOne);
     686           0 :         in10 = _mm_add_epi16(in10, kOne);
     687           0 :         in11 = _mm_add_epi16(in11, kOne);
     688           0 :         in12 = _mm_add_epi16(in12, kOne);
     689           0 :         in13 = _mm_add_epi16(in13, kOne);
     690           0 :         in14 = _mm_add_epi16(in14, kOne);
     691           0 :         in15 = _mm_add_epi16(in15, kOne);
     692           0 :         in00 = _mm_srai_epi16(in00, 2);
     693           0 :         in01 = _mm_srai_epi16(in01, 2);
     694           0 :         in02 = _mm_srai_epi16(in02, 2);
     695           0 :         in03 = _mm_srai_epi16(in03, 2);
     696           0 :         in04 = _mm_srai_epi16(in04, 2);
     697           0 :         in05 = _mm_srai_epi16(in05, 2);
     698           0 :         in06 = _mm_srai_epi16(in06, 2);
     699           0 :         in07 = _mm_srai_epi16(in07, 2);
     700           0 :         in08 = _mm_srai_epi16(in08, 2);
     701           0 :         in09 = _mm_srai_epi16(in09, 2);
     702           0 :         in10 = _mm_srai_epi16(in10, 2);
     703           0 :         in11 = _mm_srai_epi16(in11, 2);
     704           0 :         in12 = _mm_srai_epi16(in12, 2);
     705           0 :         in13 = _mm_srai_epi16(in13, 2);
     706           0 :         in14 = _mm_srai_epi16(in14, 2);
     707           0 :         in15 = _mm_srai_epi16(in15, 2);
     708             :       }
     709           0 :       in += 8;
     710             :       // Calculate input for the first 8 results.
     711             :       {
     712           0 :         input0 = ADD_EPI16(in00, in15);
     713           0 :         input1 = ADD_EPI16(in01, in14);
     714           0 :         input2 = ADD_EPI16(in02, in13);
     715           0 :         input3 = ADD_EPI16(in03, in12);
     716           0 :         input4 = ADD_EPI16(in04, in11);
     717           0 :         input5 = ADD_EPI16(in05, in10);
     718           0 :         input6 = ADD_EPI16(in06, in09);
     719           0 :         input7 = ADD_EPI16(in07, in08);
     720             : #if DCT_HIGH_BIT_DEPTH
     721           0 :         overflow = check_epi16_overflow_x8(&input0, &input1, &input2, &input3,
     722             :                                            &input4, &input5, &input6, &input7);
     723           0 :         if (overflow) {
     724           0 :           aom_highbd_fdct16x16_c(input, output, stride);
     725           0 :           return;
     726             :         }
     727             : #endif  // DCT_HIGH_BIT_DEPTH
     728             :       }
     729             :       // Calculate input for the next 8 results.
     730             :       {
     731           0 :         step1_0 = SUB_EPI16(in07, in08);
     732           0 :         step1_1 = SUB_EPI16(in06, in09);
     733           0 :         step1_2 = SUB_EPI16(in05, in10);
     734           0 :         step1_3 = SUB_EPI16(in04, in11);
     735           0 :         step1_4 = SUB_EPI16(in03, in12);
     736           0 :         step1_5 = SUB_EPI16(in02, in13);
     737           0 :         step1_6 = SUB_EPI16(in01, in14);
     738           0 :         step1_7 = SUB_EPI16(in00, in15);
     739             : #if DCT_HIGH_BIT_DEPTH
     740           0 :         overflow =
     741             :             check_epi16_overflow_x8(&step1_0, &step1_1, &step1_2, &step1_3,
     742             :                                     &step1_4, &step1_5, &step1_6, &step1_7);
     743           0 :         if (overflow) {
     744           0 :           aom_highbd_fdct16x16_c(input, output, stride);
     745           0 :           return;
     746             :         }
     747             : #endif  // DCT_HIGH_BIT_DEPTH
     748             :       }
     749             :       // Work on the first eight values; fdct8(input, even_results);
     750             :       {
     751             :         // Add/subtract
     752           0 :         const __m128i q0 = ADD_EPI16(input0, input7);
     753           0 :         const __m128i q1 = ADD_EPI16(input1, input6);
     754           0 :         const __m128i q2 = ADD_EPI16(input2, input5);
     755           0 :         const __m128i q3 = ADD_EPI16(input3, input4);
     756           0 :         const __m128i q4 = SUB_EPI16(input3, input4);
     757           0 :         const __m128i q5 = SUB_EPI16(input2, input5);
     758           0 :         const __m128i q6 = SUB_EPI16(input1, input6);
     759           0 :         const __m128i q7 = SUB_EPI16(input0, input7);
     760             : #if DCT_HIGH_BIT_DEPTH
     761           0 :         overflow =
     762             :             check_epi16_overflow_x8(&q0, &q1, &q2, &q3, &q4, &q5, &q6, &q7);
     763           0 :         if (overflow) {
     764           0 :           aom_highbd_fdct16x16_c(input, output, stride);
     765           0 :           return;
     766             :         }
     767             : #endif  // DCT_HIGH_BIT_DEPTH
     768             :         // Work on first four results
     769             :         {
     770             :           // Add/subtract
     771           0 :           const __m128i r0 = ADD_EPI16(q0, q3);
     772           0 :           const __m128i r1 = ADD_EPI16(q1, q2);
     773           0 :           const __m128i r2 = SUB_EPI16(q1, q2);
     774           0 :           const __m128i r3 = SUB_EPI16(q0, q3);
     775             : #if DCT_HIGH_BIT_DEPTH
     776           0 :           overflow = check_epi16_overflow_x4(&r0, &r1, &r2, &r3);
     777           0 :           if (overflow) {
     778           0 :             aom_highbd_fdct16x16_c(input, output, stride);
     779           0 :             return;
     780             :           }
     781             : #endif  // DCT_HIGH_BIT_DEPTH
     782             :           // Interleave to do the multiply by constants which gets us
     783             :           // into 32 bits.
     784             :           {
     785           0 :             const __m128i t0 = _mm_unpacklo_epi16(r0, r1);
     786           0 :             const __m128i t1 = _mm_unpackhi_epi16(r0, r1);
     787           0 :             const __m128i t2 = _mm_unpacklo_epi16(r2, r3);
     788           0 :             const __m128i t3 = _mm_unpackhi_epi16(r2, r3);
     789           0 :             res00 = mult_round_shift(&t0, &t1, &k__cospi_p16_p16,
     790             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     791           0 :             res08 = mult_round_shift(&t0, &t1, &k__cospi_p16_m16,
     792             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     793           0 :             res04 = mult_round_shift(&t2, &t3, &k__cospi_p24_p08,
     794             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     795           0 :             res12 = mult_round_shift(&t2, &t3, &k__cospi_m08_p24,
     796             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     797             : #if DCT_HIGH_BIT_DEPTH
     798           0 :             overflow = check_epi16_overflow_x4(&res00, &res08, &res04, &res12);
     799           0 :             if (overflow) {
     800           0 :               aom_highbd_fdct16x16_c(input, output, stride);
     801           0 :               return;
     802             :             }
     803             : #endif  // DCT_HIGH_BIT_DEPTH
     804             :           }
     805             :         }
     806             :         // Work on next four results
     807             :         {
     808             :           // Interleave to do the multiply by constants which gets us
     809             :           // into 32 bits.
     810           0 :           const __m128i d0 = _mm_unpacklo_epi16(q6, q5);
     811           0 :           const __m128i d1 = _mm_unpackhi_epi16(q6, q5);
     812           0 :           const __m128i r0 =
     813           0 :               mult_round_shift(&d0, &d1, &k__cospi_p16_m16,
     814             :                                &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     815           0 :           const __m128i r1 =
     816           0 :               mult_round_shift(&d0, &d1, &k__cospi_p16_p16,
     817             :                                &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     818             : #if DCT_HIGH_BIT_DEPTH
     819           0 :           overflow = check_epi16_overflow_x2(&r0, &r1);
     820           0 :           if (overflow) {
     821           0 :             aom_highbd_fdct16x16_c(input, output, stride);
     822           0 :             return;
     823             :           }
     824             : #endif  // DCT_HIGH_BIT_DEPTH
     825             :           {
     826             :             // Add/subtract
     827           0 :             const __m128i x0 = ADD_EPI16(q4, r0);
     828           0 :             const __m128i x1 = SUB_EPI16(q4, r0);
     829           0 :             const __m128i x2 = SUB_EPI16(q7, r1);
     830           0 :             const __m128i x3 = ADD_EPI16(q7, r1);
     831             : #if DCT_HIGH_BIT_DEPTH
     832           0 :             overflow = check_epi16_overflow_x4(&x0, &x1, &x2, &x3);
     833           0 :             if (overflow) {
     834           0 :               aom_highbd_fdct16x16_c(input, output, stride);
     835           0 :               return;
     836             :             }
     837             : #endif  // DCT_HIGH_BIT_DEPTH
     838             :             // Interleave to do the multiply by constants which gets us
     839             :             // into 32 bits.
     840             :             {
     841           0 :               const __m128i t0 = _mm_unpacklo_epi16(x0, x3);
     842           0 :               const __m128i t1 = _mm_unpackhi_epi16(x0, x3);
     843           0 :               const __m128i t2 = _mm_unpacklo_epi16(x1, x2);
     844           0 :               const __m128i t3 = _mm_unpackhi_epi16(x1, x2);
     845           0 :               res02 = mult_round_shift(&t0, &t1, &k__cospi_p28_p04,
     846             :                                        &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     847           0 :               res14 = mult_round_shift(&t0, &t1, &k__cospi_m04_p28,
     848             :                                        &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     849           0 :               res10 = mult_round_shift(&t2, &t3, &k__cospi_p12_p20,
     850             :                                        &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     851           0 :               res06 = mult_round_shift(&t2, &t3, &k__cospi_m20_p12,
     852             :                                        &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     853             : #if DCT_HIGH_BIT_DEPTH
     854           0 :               overflow =
     855             :                   check_epi16_overflow_x4(&res02, &res14, &res10, &res06);
     856           0 :               if (overflow) {
     857           0 :                 aom_highbd_fdct16x16_c(input, output, stride);
     858           0 :                 return;
     859             :               }
     860             : #endif  // DCT_HIGH_BIT_DEPTH
     861             :             }
     862             :           }
     863             :         }
     864             :       }
     865             :       // Work on the next eight values; step1 -> odd_results
     866             :       {
     867             :         // step 2
     868             :         {
     869           0 :           const __m128i t0 = _mm_unpacklo_epi16(step1_5, step1_2);
     870           0 :           const __m128i t1 = _mm_unpackhi_epi16(step1_5, step1_2);
     871           0 :           const __m128i t2 = _mm_unpacklo_epi16(step1_4, step1_3);
     872           0 :           const __m128i t3 = _mm_unpackhi_epi16(step1_4, step1_3);
     873           0 :           step2_2 = mult_round_shift(&t0, &t1, &k__cospi_p16_m16,
     874             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     875           0 :           step2_3 = mult_round_shift(&t2, &t3, &k__cospi_p16_m16,
     876             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     877           0 :           step2_5 = mult_round_shift(&t0, &t1, &k__cospi_p16_p16,
     878             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     879           0 :           step2_4 = mult_round_shift(&t2, &t3, &k__cospi_p16_p16,
     880             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     881             : #if DCT_HIGH_BIT_DEPTH
     882           0 :           overflow =
     883             :               check_epi16_overflow_x4(&step2_2, &step2_3, &step2_5, &step2_4);
     884           0 :           if (overflow) {
     885           0 :             aom_highbd_fdct16x16_c(input, output, stride);
     886           0 :             return;
     887             :           }
     888             : #endif  // DCT_HIGH_BIT_DEPTH
     889             :         }
     890             :         // step 3
     891             :         {
     892           0 :           step3_0 = ADD_EPI16(step1_0, step2_3);
     893           0 :           step3_1 = ADD_EPI16(step1_1, step2_2);
     894           0 :           step3_2 = SUB_EPI16(step1_1, step2_2);
     895           0 :           step3_3 = SUB_EPI16(step1_0, step2_3);
     896           0 :           step3_4 = SUB_EPI16(step1_7, step2_4);
     897           0 :           step3_5 = SUB_EPI16(step1_6, step2_5);
     898           0 :           step3_6 = ADD_EPI16(step1_6, step2_5);
     899           0 :           step3_7 = ADD_EPI16(step1_7, step2_4);
     900             : #if DCT_HIGH_BIT_DEPTH
     901           0 :           overflow =
     902             :               check_epi16_overflow_x8(&step3_0, &step3_1, &step3_2, &step3_3,
     903             :                                       &step3_4, &step3_5, &step3_6, &step3_7);
     904           0 :           if (overflow) {
     905           0 :             aom_highbd_fdct16x16_c(input, output, stride);
     906           0 :             return;
     907             :           }
     908             : #endif  // DCT_HIGH_BIT_DEPTH
     909             :         }
     910             :         // step 4
     911             :         {
     912           0 :           const __m128i t0 = _mm_unpacklo_epi16(step3_1, step3_6);
     913           0 :           const __m128i t1 = _mm_unpackhi_epi16(step3_1, step3_6);
     914           0 :           const __m128i t2 = _mm_unpacklo_epi16(step3_2, step3_5);
     915           0 :           const __m128i t3 = _mm_unpackhi_epi16(step3_2, step3_5);
     916           0 :           step2_1 = mult_round_shift(&t0, &t1, &k__cospi_m08_p24,
     917             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     918           0 :           step2_2 = mult_round_shift(&t2, &t3, &k__cospi_p24_p08,
     919             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     920           0 :           step2_6 = mult_round_shift(&t0, &t1, &k__cospi_p24_p08,
     921             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     922           0 :           step2_5 = mult_round_shift(&t2, &t3, &k__cospi_p08_m24,
     923             :                                      &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     924             : #if DCT_HIGH_BIT_DEPTH
     925           0 :           overflow =
     926             :               check_epi16_overflow_x4(&step2_1, &step2_2, &step2_6, &step2_5);
     927           0 :           if (overflow) {
     928           0 :             aom_highbd_fdct16x16_c(input, output, stride);
     929           0 :             return;
     930             :           }
     931             : #endif  // DCT_HIGH_BIT_DEPTH
     932             :         }
     933             :         // step 5
     934             :         {
     935           0 :           step1_0 = ADD_EPI16(step3_0, step2_1);
     936           0 :           step1_1 = SUB_EPI16(step3_0, step2_1);
     937           0 :           step1_2 = ADD_EPI16(step3_3, step2_2);
     938           0 :           step1_3 = SUB_EPI16(step3_3, step2_2);
     939           0 :           step1_4 = SUB_EPI16(step3_4, step2_5);
     940           0 :           step1_5 = ADD_EPI16(step3_4, step2_5);
     941           0 :           step1_6 = SUB_EPI16(step3_7, step2_6);
     942           0 :           step1_7 = ADD_EPI16(step3_7, step2_6);
     943             : #if DCT_HIGH_BIT_DEPTH
     944           0 :           overflow =
     945             :               check_epi16_overflow_x8(&step1_0, &step1_1, &step1_2, &step1_3,
     946             :                                       &step1_4, &step1_5, &step1_6, &step1_7);
     947           0 :           if (overflow) {
     948           0 :             aom_highbd_fdct16x16_c(input, output, stride);
     949           0 :             return;
     950             :           }
     951             : #endif  // DCT_HIGH_BIT_DEPTH
     952             :         }
     953             :         // step 6
     954             :         {
     955           0 :           const __m128i t0 = _mm_unpacklo_epi16(step1_0, step1_7);
     956           0 :           const __m128i t1 = _mm_unpackhi_epi16(step1_0, step1_7);
     957           0 :           const __m128i t2 = _mm_unpacklo_epi16(step1_1, step1_6);
     958           0 :           const __m128i t3 = _mm_unpackhi_epi16(step1_1, step1_6);
     959           0 :           res01 = mult_round_shift(&t0, &t1, &k__cospi_p30_p02,
     960             :                                    &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     961           0 :           res09 = mult_round_shift(&t2, &t3, &k__cospi_p14_p18,
     962             :                                    &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     963           0 :           res15 = mult_round_shift(&t0, &t1, &k__cospi_m02_p30,
     964             :                                    &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     965           0 :           res07 = mult_round_shift(&t2, &t3, &k__cospi_m18_p14,
     966             :                                    &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     967             : #if DCT_HIGH_BIT_DEPTH
     968           0 :           overflow = check_epi16_overflow_x4(&res01, &res09, &res15, &res07);
     969           0 :           if (overflow) {
     970           0 :             aom_highbd_fdct16x16_c(input, output, stride);
     971           0 :             return;
     972             :           }
     973             : #endif  // DCT_HIGH_BIT_DEPTH
     974             :         }
     975             :         {
     976           0 :           const __m128i t0 = _mm_unpacklo_epi16(step1_2, step1_5);
     977           0 :           const __m128i t1 = _mm_unpackhi_epi16(step1_2, step1_5);
     978           0 :           const __m128i t2 = _mm_unpacklo_epi16(step1_3, step1_4);
     979           0 :           const __m128i t3 = _mm_unpackhi_epi16(step1_3, step1_4);
     980           0 :           res05 = mult_round_shift(&t0, &t1, &k__cospi_p22_p10,
     981             :                                    &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     982           0 :           res13 = mult_round_shift(&t2, &t3, &k__cospi_p06_p26,
     983             :                                    &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     984           0 :           res11 = mult_round_shift(&t0, &t1, &k__cospi_m10_p22,
     985             :                                    &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     986           0 :           res03 = mult_round_shift(&t2, &t3, &k__cospi_m26_p06,
     987             :                                    &k__DCT_CONST_ROUNDING, DCT_CONST_BITS);
     988             : #if DCT_HIGH_BIT_DEPTH
     989           0 :           overflow = check_epi16_overflow_x4(&res05, &res13, &res11, &res03);
     990           0 :           if (overflow) {
     991           0 :             aom_highbd_fdct16x16_c(input, output, stride);
     992           0 :             return;
     993             :           }
     994             : #endif  // DCT_HIGH_BIT_DEPTH
     995             :         }
     996             :       }
     997             :       // Transpose the results, do it as two 8x8 transposes.
     998           0 :       transpose_and_output8x8(&res00, &res01, &res02, &res03, &res04, &res05,
     999             :                               &res06, &res07, pass, out0, out1);
    1000           0 :       transpose_and_output8x8(&res08, &res09, &res10, &res11, &res12, &res13,
    1001             :                               &res14, &res15, pass, out0 + 8, out1 + 8);
    1002           0 :       if (pass == 0) {
    1003           0 :         out0 += 8 * 16;
    1004             :       } else {
    1005           0 :         out1 += 8 * 16;
    1006             :       }
    1007             :     }
    1008             :     // Setup in/out for next pass.
    1009           0 :     in = intermediate;
    1010             :   }
    1011           0 : }
    1012             : 
    1013             : #undef ADD_EPI16
    1014             : #undef SUB_EPI16

Generated by: LCOV version 1.13