loopfilter_filters_mmi.c 74.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
/*
 *  Copyright (c) 2017 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "./vpx_dsp_rtcd.h"
#include "vp8/common/loopfilter.h"
#include "vp8/common/onyxc_int.h"
#include "vpx_ports/asmdefs_mmi.h"

DECLARE_ALIGNED(8, static const uint64_t, ff_ph_01) = { 0x0001000100010001ULL };
DECLARE_ALIGNED(8, static const uint64_t,
                ff_ph_003f) = { 0x003f003f003f003fULL };
DECLARE_ALIGNED(8, static const uint64_t,
                ff_ph_0900) = { 0x0900090009000900ULL };
DECLARE_ALIGNED(8, static const uint64_t,
                ff_ph_1200) = { 0x1200120012001200ULL };
DECLARE_ALIGNED(8, static const uint64_t,
                ff_ph_1b00) = { 0x1b001b001b001b00ULL };
DECLARE_ALIGNED(8, static const uint64_t, ff_pb_fe) = { 0xfefefefefefefefeULL };
DECLARE_ALIGNED(8, static const uint64_t, ff_pb_80) = { 0x8080808080808080ULL };
DECLARE_ALIGNED(8, static const uint64_t, ff_pb_04) = { 0x0404040404040404ULL };
DECLARE_ALIGNED(8, static const uint64_t, ff_pb_03) = { 0x0303030303030303ULL };
DECLARE_ALIGNED(8, static const uint64_t, ff_pb_01) = { 0x0101010101010101ULL };

void vp8_loop_filter_horizontal_edge_mmi(
    unsigned char *src_ptr, int src_pixel_step, const unsigned char *blimit,
    const unsigned char *limit, const unsigned char *thresh, int count) {
  uint32_t tmp[1];
  mips_reg addr[2];
  double ftmp[12];
  __asm__ volatile (
    "1:                                                             \n\t"
    "gsldlc1    %[ftmp10],  0x07(%[limit])                          \n\t"
    "gsldrc1    %[ftmp10],  0x00(%[limit])                          \n\t"

    MMI_ADDU(%[addr0], %[src_ptr], %[src_pixel_step])

    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step_x4])
    "gsldlc1    %[ftmp1],   0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp1],   0x00(%[addr1])                          \n\t"

    MMI_SUBU(%[addr1], %[addr0], %[src_pixel_step_x4])
    "gsldlc1    %[ftmp3],   0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp3],   0x00(%[addr1])                          \n\t"
    "pasubub    %[ftmp0],   %[ftmp1],           %[ftmp3]            \n\t"
    "psubusb    %[ftmp0],   %[ftmp0],           %[ftmp10]           \n\t"

    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step_x2])
    "gsldlc1    %[ftmp4],   0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp4],   0x00(%[addr1])                          \n\t"
    "pasubub    %[ftmp1],   %[ftmp3],           %[ftmp4]            \n\t"
    "psubusb    %[ftmp1],   %[ftmp1],           %[ftmp10]           \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"

    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp5],   0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp5],   0x00(%[addr1])                          \n\t"
    "pasubub    %[ftmp9],   %[ftmp4],           %[ftmp5]            \n\t"
    "psubusb    %[ftmp1],   %[ftmp9],           %[ftmp10]           \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"

    "gsldlc1    %[ftmp6],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp6],   0x00(%[src_ptr])                        \n\t"

    "gsldlc1    %[ftmp7],   0x07(%[addr0])                          \n\t"
    "gsldrc1    %[ftmp7],   0x00(%[addr0])                          \n\t"
    "pasubub    %[ftmp11],  %[ftmp7],           %[ftmp6]            \n\t"
    "psubusb    %[ftmp1],   %[ftmp11],          %[ftmp10]           \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"

    MMI_ADDU(%[addr1], %[src_ptr], %[src_pixel_step_x2])
    "gsldlc1    %[ftmp8],   0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp8],   0x00(%[addr1])                          \n\t"
    "pasubub    %[ftmp1],   %[ftmp8],           %[ftmp7]            \n\t"
    "psubusb    %[ftmp1],   %[ftmp1],           %[ftmp10]           \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"

    MMI_ADDU(%[addr1], %[addr0], %[src_pixel_step_x2])
    "gsldlc1    %[ftmp2],   0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp2],   0x00(%[addr1])                          \n\t"
    "pasubub    %[ftmp1],   %[ftmp2],           %[ftmp8]            \n\t"
    "psubusb    %[ftmp1],   %[ftmp1],           %[ftmp10]           \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"

    "pasubub    %[ftmp1],   %[ftmp5],           %[ftmp6]            \n\t"
    "paddusb    %[ftmp1],   %[ftmp1],           %[ftmp1]            \n\t"
    "pasubub    %[ftmp2],   %[ftmp4],           %[ftmp7]            \n\t"
    "and        %[ftmp2],   %[ftmp2],           %[ff_pb_fe]         \n\t"
    "li         %[tmp0],    0x01                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp10]                               \n\t"
    "psrlh      %[ftmp2],   %[ftmp2],           %[ftmp10]           \n\t"
    "paddusb    %[ftmp1],   %[ftmp1],           %[ftmp2]            \n\t"
    "gsldlc1    %[ftmp10],  0x07(%[blimit])                         \n\t"
    "gsldrc1    %[ftmp10],  0x00(%[blimit])                         \n\t"
    "psubusb    %[ftmp1],   %[ftmp1],           %[ftmp10]           \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"
    "xor        %[ftmp10],  %[ftmp10],          %[ftmp10]           \n\t"
    "pcmpeqb    %[ftmp0],   %[ftmp0],           %[ftmp10]           \n\t"

    "gsldlc1    %[ftmp10],  0x07(%[thresh])                         \n\t"
    "gsldrc1    %[ftmp10],  0x00(%[thresh])                         \n\t"
    "psubusb    %[ftmp1],   %[ftmp9],           %[ftmp10]           \n\t"
    "psubusb    %[ftmp2],   %[ftmp11],          %[ftmp10]           \n\t"
    "paddb      %[ftmp1],   %[ftmp1],           %[ftmp2]            \n\t"
    "xor        %[ftmp2],   %[ftmp2],           %[ftmp2]            \n\t"
    "pcmpeqb    %[ftmp1],   %[ftmp1],           %[ftmp2]            \n\t"
    "pcmpeqb    %[ftmp2],   %[ftmp2],           %[ftmp2]            \n\t"
    "xor        %[ftmp1],   %[ftmp1],           %[ftmp2]            \n\t"

    "xor        %[ftmp4],   %[ftmp4],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp5],   %[ftmp5],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp6],   %[ftmp6],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp7],   %[ftmp7],           %[ff_pb_80]         \n\t"

    "psubsb     %[ftmp2],   %[ftmp4],           %[ftmp7]            \n\t"
    "and        %[ftmp2],   %[ftmp2],           %[ftmp1]            \n\t"
    "psubsb     %[ftmp3],   %[ftmp6],           %[ftmp5]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp3]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp3]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp3]            \n\t"
    "and        %[ftmp2],   %[ftmp2],           %[ftmp0]            \n\t"

    "paddsb     %[ftmp8],   %[ftmp2],           %[ff_pb_03]         \n\t"
    "paddsb     %[ftmp9],   %[ftmp2],           %[ff_pb_04]         \n\t"

    "xor        %[ftmp0],   %[ftmp0],           %[ftmp0]            \n\t"
    "xor        %[ftmp11],  %[ftmp11],          %[ftmp11]           \n\t"
    "punpcklbh  %[ftmp0],   %[ftmp0],           %[ftmp8]            \n\t"
    "punpckhbh  %[ftmp11],  %[ftmp11],          %[ftmp8]            \n\t"

    "li         %[tmp0],    0x0b                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp10]                               \n\t"
    "psrah      %[ftmp0],   %[ftmp0],           %[ftmp10]           \n\t"
    "psrah      %[ftmp11],  %[ftmp11],          %[ftmp10]           \n\t"
    "packsshb   %[ftmp8],   %[ftmp0],           %[ftmp11]           \n\t"
    "xor        %[ftmp0],   %[ftmp0],           %[ftmp0]            \n\t"
    "punpcklbh  %[ftmp0],   %[ftmp0],           %[ftmp9]            \n\t"
    "psrah      %[ftmp0],   %[ftmp0],           %[ftmp10]           \n\t"
    "xor        %[ftmp11],  %[ftmp11],          %[ftmp11]           \n\t"
    "punpckhbh  %[ftmp9],   %[ftmp11],          %[ftmp9]            \n\t"
    "psrah      %[ftmp9],   %[ftmp9],           %[ftmp10]           \n\t"
    "paddsh     %[ftmp11],  %[ftmp0],           %[ff_ph_01]         \n\t"
    "packsshb   %[ftmp0],   %[ftmp0],           %[ftmp9]            \n\t"
    "paddsh     %[ftmp9],   %[ftmp9],           %[ff_ph_01]         \n\t"

    "li         %[tmp0],    0x01                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp10]                               \n\t"
    "psrah      %[ftmp11],  %[ftmp11],          %[ftmp10]           \n\t"
    "psrah      %[ftmp9],   %[ftmp9],           %[ftmp10]           \n\t"
    "packsshb   %[ftmp11],  %[ftmp11],          %[ftmp9]            \n\t"
    "pandn      %[ftmp1],   %[ftmp1],           %[ftmp11]           \n\t"
    "paddsb     %[ftmp5],   %[ftmp5],           %[ftmp8]            \n\t"
    "xor        %[ftmp5],   %[ftmp5],           %[ff_pb_80]         \n\t"

    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step])
    "gssdlc1    %[ftmp5],   0x07(%[addr1])                          \n\t"
    "gssdrc1    %[ftmp5],   0x00(%[addr1])                          \n\t"
    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step_x2])
    "paddsb     %[ftmp4],   %[ftmp4],           %[ftmp1]            \n\t"
    "xor        %[ftmp4],   %[ftmp4],           %[ff_pb_80]         \n\t"
    "gssdlc1    %[ftmp4],   0x07(%[addr1])                          \n\t"
    "gssdrc1    %[ftmp4],   0x00(%[addr1])                          \n\t"

    "psubsb     %[ftmp6],   %[ftmp6],           %[ftmp0]            \n\t"
    "xor        %[ftmp6],   %[ftmp6],           %[ff_pb_80]         \n\t"
    "gssdlc1    %[ftmp6],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp6],   0x00(%[src_ptr])                        \n\t"

    "psubsb     %[ftmp7],   %[ftmp7],           %[ftmp1]            \n\t"
    "xor        %[ftmp7],   %[ftmp7],           %[ff_pb_80]         \n\t"
    "gssdlc1    %[ftmp7],   0x07(%[addr0])                          \n\t"
    "gssdrc1    %[ftmp7],   0x00(%[addr0])                          \n\t"

    "addiu      %[count],   %[count],           -0x01               \n\t"
    MMI_ADDIU(%[src_ptr], %[src_ptr], 0x08)
    "bnez       %[count],   1b                                      \n\t"
    : [ftmp0]"=&f"(ftmp[0]),              [ftmp1]"=&f"(ftmp[1]),
      [ftmp2]"=&f"(ftmp[2]),              [ftmp3]"=&f"(ftmp[3]),
      [ftmp4]"=&f"(ftmp[4]),              [ftmp5]"=&f"(ftmp[5]),
      [ftmp6]"=&f"(ftmp[6]),              [ftmp7]"=&f"(ftmp[7]),
      [ftmp8]"=&f"(ftmp[8]),              [ftmp9]"=&f"(ftmp[9]),
      [ftmp10]"=&f"(ftmp[10]),            [ftmp11]"=&f"(ftmp[11]),
      [tmp0]"=&r"(tmp[0]),
      [addr0]"=&r"(addr[0]),            [addr1]"=&r"(addr[1]),
      [src_ptr]"+&r"(src_ptr),          [count]"+&r"(count)
    : [limit]"r"(limit),                [blimit]"r"(blimit),
      [thresh]"r"(thresh),
      [src_pixel_step]"r"((mips_reg)src_pixel_step),
      [src_pixel_step_x2]"r"((mips_reg)(src_pixel_step<<1)),
      [src_pixel_step_x4]"r"((mips_reg)(src_pixel_step<<2)),
      [ff_ph_01]"f"(ff_ph_01),          [ff_pb_fe]"f"(ff_pb_fe),
      [ff_pb_80]"f"(ff_pb_80),          [ff_pb_04]"f"(ff_pb_04),
      [ff_pb_03]"f"(ff_pb_03)
    : "memory"
  );
}

void vp8_loop_filter_vertical_edge_mmi(unsigned char *src_ptr,
                                       int src_pixel_step,
                                       const unsigned char *blimit,
                                       const unsigned char *limit,
                                       const unsigned char *thresh, int count) {
  uint32_t tmp[1];
  mips_reg addr[2];
  double ftmp[13];

  __asm__ volatile (
    MMI_SLL(%[tmp0], %[src_pixel_step], 0x02)
    MMI_ADDU(%[src_ptr], %[src_ptr], %[tmp0])
    MMI_SUBU(%[src_ptr], %[src_ptr], 0x04)

    "1:                                                             \n\t"
    MMI_ADDU(%[addr0], %[src_ptr], %[src_pixel_step])

    MMI_SLL (%[tmp0], %[src_pixel_step], 0x01)
    MMI_ADDU(%[addr1], %[src_ptr], %[tmp0])
    "gsldlc1    %[ftmp11],  0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp11],  0x00(%[addr1])                          \n\t"
    MMI_ADDU(%[addr1], %[addr0], %[tmp0])
    "gsldlc1    %[ftmp12],  0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp12],  0x00(%[addr1])                          \n\t"
    "punpcklbh  %[ftmp1],   %[ftmp11],          %[ftmp12]           \n\t"
    "punpckhbh  %[ftmp2],   %[ftmp11],          %[ftmp12]           \n\t"

    "gsldlc1    %[ftmp11],  0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp11],  0x00(%[src_ptr])                        \n\t"
    "gsldlc1    %[ftmp12],  0x07(%[addr0])                          \n\t"
    "gsldrc1    %[ftmp12],  0x00(%[addr0])                          \n\t"
    "punpcklbh  %[ftmp3],   %[ftmp11],          %[ftmp12]           \n\t"
    "punpckhbh  %[ftmp4],   %[ftmp11],          %[ftmp12]           \n\t"

    "punpcklhw  %[ftmp5],   %[ftmp4],           %[ftmp2]            \n\t"
    "punpckhhw  %[ftmp6],   %[ftmp4],           %[ftmp2]            \n\t"
    "punpcklhw  %[ftmp7],   %[ftmp3],           %[ftmp1]            \n\t"
    "punpckhhw  %[ftmp8],   %[ftmp3],           %[ftmp1]            \n\t"

    MMI_SLL(%[tmp0], %[src_pixel_step], 0x01)
    MMI_SUBU(%[addr1], %[src_ptr], %[tmp0])
    "gsldlc1    %[ftmp11],  0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp11],  0x00(%[addr1])                          \n\t"
    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp12],  0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp12],  0x00(%[addr1])                          \n\t"
    "punpcklbh  %[ftmp9],   %[ftmp11],          %[ftmp12]           \n\t"
    "punpckhbh  %[ftmp10],  %[ftmp11],          %[ftmp12]           \n\t"

    MMI_SLL(%[tmp0], %[src_pixel_step], 0x02)
    MMI_SUBU(%[addr1], %[src_ptr], %[tmp0])
    "gsldlc1    %[ftmp11],  0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp11],  0x00(%[addr1])                          \n\t"
    MMI_SLL(%[tmp0], %[src_pixel_step], 0x02)
    MMI_SUBU(%[addr1], %[addr0], %[tmp0])
    "gsldlc1    %[ftmp12],  0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp12],  0x00(%[addr1])                          \n\t"
    "punpcklbh  %[ftmp0],   %[ftmp11],          %[ftmp12]           \n\t"
    "punpckhbh  %[ftmp11],  %[ftmp11],          %[ftmp12]           \n\t"

    "punpcklhw  %[ftmp1],   %[ftmp11],          %[ftmp10]           \n\t"
    "punpckhhw  %[ftmp2],   %[ftmp11],          %[ftmp10]           \n\t"
    "punpcklhw  %[ftmp3],   %[ftmp0],           %[ftmp9]            \n\t"
    "punpckhhw  %[ftmp4],   %[ftmp0],           %[ftmp9]            \n\t"

    /* ftmp9:q0  ftmp10:q1 */
    "punpcklwd  %[ftmp9],   %[ftmp1],           %[ftmp5]            \n\t"
    "punpckhwd  %[ftmp10],  %[ftmp1],           %[ftmp5]            \n\t"
    /* ftmp11:q2  ftmp12:q3 */
    "punpcklwd  %[ftmp11],  %[ftmp2],           %[ftmp6]            \n\t"
    "punpckhwd  %[ftmp12],  %[ftmp2],           %[ftmp6]            \n\t"
    /* ftmp1:p3  ftmp2:p2 */
    "punpcklwd  %[ftmp1],   %[ftmp3],           %[ftmp7]            \n\t"
    "punpckhwd  %[ftmp2],   %[ftmp3],           %[ftmp7]            \n\t"
    /* ftmp5:p1  ftmp6:p0 */
    "punpcklwd  %[ftmp5],   %[ftmp4],           %[ftmp8]            \n\t"
    "punpckhwd  %[ftmp6],   %[ftmp4],           %[ftmp8]            \n\t"

    "gsldlc1    %[ftmp8],   0x07(%[limit])                          \n\t"
    "gsldrc1    %[ftmp8],   0x00(%[limit])                          \n\t"

    /* abs (q3-q2) */
    "pasubub    %[ftmp7],   %[ftmp12],          %[ftmp11]           \n\t"
    "psubusb    %[ftmp0],   %[ftmp7],           %[ftmp8]            \n\t"
    /* abs (q2-q1) */
    "pasubub    %[ftmp7],   %[ftmp11],          %[ftmp10]           \n\t"
    "psubusb    %[ftmp7],   %[ftmp7],           %[ftmp8]            \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    /* ftmp3: abs(q1-q0) */
    "pasubub    %[ftmp3],   %[ftmp10],          %[ftmp9]            \n\t"
    "psubusb    %[ftmp7],   %[ftmp3],           %[ftmp8]            \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    /* ftmp4: abs(p1-p0) */
    "pasubub    %[ftmp4],   %[ftmp5],           %[ftmp6]            \n\t"
    "psubusb    %[ftmp7],   %[ftmp4],           %[ftmp8]            \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    /* abs (p2-p1) */
    "pasubub    %[ftmp7],   %[ftmp2],           %[ftmp5]            \n\t"
    "psubusb    %[ftmp7],   %[ftmp7],           %[ftmp8]            \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    /* abs (p3-p2) */
    "pasubub    %[ftmp7],   %[ftmp1],           %[ftmp2]            \n\t"
    "psubusb    %[ftmp7],   %[ftmp7],           %[ftmp8]            \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"

    "gsldlc1    %[ftmp8],   0x07(%[blimit])                         \n\t"
    "gsldrc1    %[ftmp8],   0x00(%[blimit])                         \n\t"

    /* abs (p0-q0) */
    "pasubub    %[ftmp11],  %[ftmp9],           %[ftmp6]            \n\t"
    "paddusb    %[ftmp11],  %[ftmp11],          %[ftmp11]           \n\t"
    /* abs (p1-q1) */
    "pasubub    %[ftmp12],  %[ftmp10],          %[ftmp5]            \n\t"
    "and        %[ftmp12],  %[ftmp12],          %[ff_pb_fe]         \n\t"
    "li         %[tmp0],    0x01                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp1]                                \n\t"
    "psrlh      %[ftmp12],  %[ftmp12],          %[ftmp1]            \n\t"
    "paddusb    %[ftmp1],   %[ftmp11],          %[ftmp12]           \n\t"
    "psubusb    %[ftmp1],   %[ftmp1],           %[ftmp8]            \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"
    "xor        %[ftmp1],   %[ftmp1],           %[ftmp1]            \n\t"
    /* ftmp0:mask */
    "pcmpeqb    %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"

    "gsldlc1    %[ftmp8],   0x07(%[thresh])                         \n\t"
    "gsldrc1    %[ftmp8],   0x00(%[thresh])                         \n\t"

    /* ftmp3: abs(q1-q0)  ftmp4: abs(p1-p0) */
    "psubusb    %[ftmp4],   %[ftmp4],           %[ftmp8]            \n\t"
    "psubusb    %[ftmp3],   %[ftmp3],           %[ftmp8]            \n\t"
    "or         %[ftmp2],   %[ftmp4],           %[ftmp3]            \n\t"
    "pcmpeqb    %[ftmp2],   %[ftmp2],           %[ftmp1]            \n\t"
    "pcmpeqb    %[ftmp1],   %[ftmp1],           %[ftmp1]            \n\t"
    /* ftmp1:hev */
    "xor        %[ftmp1],   %[ftmp2],           %[ftmp1]            \n\t"

    "xor        %[ftmp10],  %[ftmp10],          %[ff_pb_80]         \n\t"
    "xor        %[ftmp9],   %[ftmp9],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp6],   %[ftmp6],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp5],   %[ftmp5],           %[ff_pb_80]         \n\t"

    "psubsb     %[ftmp2],   %[ftmp5],           %[ftmp10]           \n\t"
    "and        %[ftmp2],   %[ftmp2],           %[ftmp1]            \n\t"
    "psubsb     %[ftmp3],   %[ftmp9],           %[ftmp6]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp3]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp3]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp3]            \n\t"
    /* ftmp2:filter_value */
    "and        %[ftmp2],   %[ftmp2],           %[ftmp0]            \n\t"

    "paddsb     %[ftmp11],  %[ftmp2],           %[ff_pb_04]         \n\t"
    "paddsb     %[ftmp12],  %[ftmp2],           %[ff_pb_03]         \n\t"

    "li         %[tmp0],    0x0b                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp7]                                \n\t"
    "xor       %[ftmp0],    %[ftmp0],           %[ftmp0]            \n\t"
    "xor       %[ftmp8],    %[ftmp8],           %[ftmp8]            \n\t"
    "punpcklbh %[ftmp0],    %[ftmp0],           %[ftmp12]           \n\t"
    "punpckhbh %[ftmp8],    %[ftmp8],           %[ftmp12]           \n\t"
    "psrah     %[ftmp0],    %[ftmp0],           %[ftmp7]            \n\t"
    "psrah     %[ftmp8],    %[ftmp8],           %[ftmp7]            \n\t"
    "packsshb  %[ftmp12],   %[ftmp0],           %[ftmp8]            \n\t"

    "xor       %[ftmp0],    %[ftmp0],           %[ftmp0]            \n\t"
    "xor       %[ftmp8],    %[ftmp8],           %[ftmp8]            \n\t"
    "punpcklbh %[ftmp0],    %[ftmp0],           %[ftmp11]           \n\t"
    "punpckhbh %[ftmp8],    %[ftmp8],           %[ftmp11]           \n\t"
    "psrah     %[ftmp0],    %[ftmp0],           %[ftmp7]            \n\t"
    "psrah     %[ftmp8],    %[ftmp8],           %[ftmp7]            \n\t"
    "packsshb  %[ftmp11],   %[ftmp0],           %[ftmp8]            \n\t"

    "psubsb     %[ftmp9],   %[ftmp9],           %[ftmp11]           \n\t"
    "xor        %[ftmp9],   %[ftmp9],           %[ff_pb_80]         \n\t"
    "paddsb     %[ftmp6],   %[ftmp6],           %[ftmp12]           \n\t"
    "xor        %[ftmp6],   %[ftmp6],           %[ff_pb_80]         \n\t"
    "paddsh     %[ftmp0],   %[ftmp0],           %[ff_ph_01]         \n\t"
    "paddsh     %[ftmp8],   %[ftmp8],           %[ff_ph_01]         \n\t"

    "li         %[tmp0],    0x01                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp7]                                \n\t"
    "psrah      %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    "psrah      %[ftmp8],   %[ftmp8],           %[ftmp7]            \n\t"
    "packsshb   %[ftmp2],   %[ftmp0],           %[ftmp8]            \n\t"
    "pandn      %[ftmp2],   %[ftmp1],           %[ftmp2]            \n\t"
    "psubsb     %[ftmp10],  %[ftmp10],          %[ftmp2]            \n\t"
    "xor        %[ftmp10],  %[ftmp10],          %[ff_pb_80]         \n\t"
    "paddsb     %[ftmp5],   %[ftmp5],           %[ftmp2]            \n\t"
    "xor        %[ftmp5],   %[ftmp5],           %[ff_pb_80]         \n\t"

    /* ftmp5: *op1 ; ftmp6: *op0 */
    "punpcklbh  %[ftmp2],   %[ftmp5],           %[ftmp6]            \n\t"
    "punpckhbh  %[ftmp1],   %[ftmp5],           %[ftmp6]            \n\t"
    /* ftmp9: *oq0 ; ftmp10: *oq1 */
    "punpcklbh  %[ftmp4],   %[ftmp9],           %[ftmp10]           \n\t"
    "punpckhbh  %[ftmp3],   %[ftmp9],           %[ftmp10]           \n\t"
    "punpckhhw  %[ftmp6],   %[ftmp2],           %[ftmp4]            \n\t"
    "punpcklhw  %[ftmp2],   %[ftmp2],           %[ftmp4]            \n\t"
    "punpckhhw  %[ftmp5],   %[ftmp1],           %[ftmp3]            \n\t"
    "punpcklhw  %[ftmp1],   %[ftmp1],           %[ftmp3]            \n\t"

    MMI_SLL(%[tmp0], %[src_pixel_step], 0x02)
    MMI_SUBU(%[addr1], %[src_ptr], %[tmp0])
    "gsswlc1    %[ftmp2],   0x05(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp2],   0x02(%[addr1])                          \n\t"

    "li         %[tmp0],    0x20                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
    "dsrl       %[ftmp2],   %[ftmp2],           %[ftmp9]            \n\t"
    MMI_SLL(%[tmp0], %[src_pixel_step], 0x02)
    MMI_SUBU(%[addr1], %[addr0], %[tmp0])
    "gsswlc1    %[ftmp2],   0x05(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp2],   0x02(%[addr1])                          \n\t"

    MMI_SLL(%[tmp0], %[src_pixel_step], 0x01)
    MMI_SUBU(%[addr1], %[src_ptr], %[tmp0])
    "gsswlc1    %[ftmp6],   0x05(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp6],   0x02(%[addr1])                          \n\t"

    "dsrl       %[ftmp6],   %[ftmp6],           %[ftmp9]            \n\t"
    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step])
    "gsswlc1    %[ftmp6],   0x05(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp6],   0x02(%[addr1])                          \n\t"
    "gsswlc1    %[ftmp1],   0x05(%[src_ptr])                        \n\t"
    "gsswrc1    %[ftmp1],   0x02(%[src_ptr])                        \n\t"

    "dsrl       %[ftmp1],   %[ftmp1],           %[ftmp9]            \n\t"
    "gsswlc1    %[ftmp1],   0x05(%[addr0])                          \n\t"
    "gsswrc1    %[ftmp1],   0x02(%[addr0])                          \n\t"
    MMI_ADDU(%[addr1], %[addr0], %[src_pixel_step])
    "gsswlc1    %[ftmp5],   0x05(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp5],   0x02(%[addr1])                          \n\t"

    "dsrl       %[ftmp5],   %[ftmp5],           %[ftmp9]            \n\t"
    MMI_ADDU(%[addr1], %[addr0], %[tmp0])
    "gsswlc1    %[ftmp5],   0x05(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp5],   0x02(%[addr1])                          \n\t"

    MMI_ADDIU(%[count], %[count], -0x01)
    MMI_SLL(%[tmp0], %[src_pixel_step], 0x03)
    MMI_ADDU(%[src_ptr], %[src_ptr], %[tmp0])
    "bnez       %[count],   1b                                      \n\t"
    : [ftmp0]"=&f"(ftmp[0]),              [ftmp1]"=&f"(ftmp[1]),
      [ftmp2]"=&f"(ftmp[2]),              [ftmp3]"=&f"(ftmp[3]),
      [ftmp4]"=&f"(ftmp[4]),              [ftmp5]"=&f"(ftmp[5]),
      [ftmp6]"=&f"(ftmp[6]),              [ftmp7]"=&f"(ftmp[7]),
      [ftmp8]"=&f"(ftmp[8]),              [ftmp9]"=&f"(ftmp[9]),
      [ftmp10]"=&f"(ftmp[10]),            [ftmp11]"=&f"(ftmp[11]),
      [ftmp12]"=&f"(ftmp[12]),            [tmp0]"=&r"(tmp[0]),
      [addr0]"=&r"(addr[0]),            [addr1]"=&r"(addr[1]),
      [src_ptr]"+&r"(src_ptr),          [count]"+&r"(count)
    : [limit]"r"(limit),                [blimit]"r"(blimit),
      [thresh]"r"(thresh),
      [src_pixel_step]"r"((mips_reg)src_pixel_step),
      [ff_ph_01]"f"(ff_ph_01),          [ff_pb_03]"f"(ff_pb_03),
      [ff_pb_04]"f"(ff_pb_04),          [ff_pb_80]"f"(ff_pb_80),
      [ff_pb_fe]"f"(ff_pb_fe)
    : "memory"
  );
}

464
/* clang-format off */
465
#define VP8_MBLOOP_HPSRAB                                               \
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
  "punpcklbh  %[ftmp10],  %[ftmp10],          %[ftmp0]            \n\t" \
  "punpckhbh  %[ftmp11],  %[ftmp11],          %[ftmp0]            \n\t" \
  "psrah      %[ftmp10],  %[ftmp10],          %[ftmp9]            \n\t" \
  "psrah      %[ftmp11],  %[ftmp11],          %[ftmp9]            \n\t" \
  "packsshb   %[ftmp0],   %[ftmp10],          %[ftmp11]            \n\t"

#define VP8_MBLOOP_HPSRAB_ADD(reg)                                      \
  "punpcklbh  %[ftmp1],   %[ftmp0],           %[ftmp12]           \n\t" \
  "punpckhbh  %[ftmp2],   %[ftmp0],           %[ftmp12]           \n\t" \
  "pmulhh     %[ftmp1],   %[ftmp1],         " #reg "              \n\t" \
  "pmulhh     %[ftmp2],   %[ftmp2],         " #reg "              \n\t" \
  "paddh      %[ftmp1],   %[ftmp1],           %[ff_ph_003f]       \n\t" \
  "paddh      %[ftmp2],   %[ftmp2],           %[ff_ph_003f]       \n\t" \
  "psrah      %[ftmp1],   %[ftmp1],           %[ftmp9]            \n\t" \
  "psrah      %[ftmp2],   %[ftmp2],           %[ftmp9]            \n\t" \
  "packsshb   %[ftmp1],   %[ftmp1],           %[ftmp2]            \n\t"
/* clang-format on */
483 484 485 486 487

void vp8_mbloop_filter_horizontal_edge_mmi(
    unsigned char *src_ptr, int src_pixel_step, const unsigned char *blimit,
    const unsigned char *limit, const unsigned char *thresh, int count) {
  uint32_t tmp[1];
488
  double ftmp[13];
489 490

  __asm__ volatile (
491 492
    MMI_SLL(%[tmp0], %[src_pixel_step], 0x02)
    MMI_SUBU(%[src_ptr], %[src_ptr], %[tmp0])
493 494 495
    "1:                                                             \n\t"
    "gsldlc1    %[ftmp9],   0x07(%[limit])                          \n\t"
    "gsldrc1    %[ftmp9],   0x00(%[limit])                          \n\t"
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
    /* ftmp1: p3 */
    "gsldlc1    %[ftmp1],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp1],   0x00(%[src_ptr])                        \n\t"
    /* ftmp3: p2 */
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp3],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp3],   0x00(%[src_ptr])                        \n\t"
    /* ftmp4: p1 */
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp4],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp4],   0x00(%[src_ptr])                        \n\t"
    /* ftmp5: p0 */
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp5],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp5],   0x00(%[src_ptr])                        \n\t"
    /* ftmp6: q0 */
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp6],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp6],   0x00(%[src_ptr])                        \n\t"
    /* ftmp7: q1 */
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp7],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp7],   0x00(%[src_ptr])                        \n\t"
    /* ftmp8: q2 */
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp8],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp8],   0x00(%[src_ptr])                        \n\t"
    /* ftmp2: q3 */
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp2],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp2],   0x00(%[src_ptr])                        \n\t"

    "gsldlc1    %[ftmp12],  0x07(%[blimit])                         \n\t"
    "gsldrc1    %[ftmp12],  0x00(%[blimit])                         \n\t"
530 531 532 533 534 535

    "pasubub    %[ftmp0],   %[ftmp1],           %[ftmp3]            \n\t"
    "psubusb    %[ftmp0],   %[ftmp0],           %[ftmp9]            \n\t"
    "pasubub    %[ftmp1],   %[ftmp3],           %[ftmp4]            \n\t"
    "psubusb    %[ftmp1],   %[ftmp1],           %[ftmp9]            \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"
536 537
    "pasubub    %[ftmp10],  %[ftmp4],           %[ftmp5]            \n\t"
    "psubusb    %[ftmp1],   %[ftmp10],          %[ftmp9]            \n\t"
538
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"
539 540
    "pasubub    %[ftmp11],  %[ftmp7],           %[ftmp6]            \n\t"
    "psubusb    %[ftmp1],   %[ftmp11],          %[ftmp9]            \n\t"
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"
    "pasubub    %[ftmp1],   %[ftmp8],           %[ftmp7]            \n\t"
    "psubusb    %[ftmp1],   %[ftmp1],           %[ftmp9]            \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"
    "pasubub    %[ftmp1],   %[ftmp2],           %[ftmp8]            \n\t"
    "psubusb    %[ftmp1],   %[ftmp1],           %[ftmp9]            \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"

    "pasubub    %[ftmp1],   %[ftmp5],           %[ftmp6]            \n\t"
    "paddusb    %[ftmp1],   %[ftmp1],           %[ftmp1]            \n\t"
    "pasubub    %[ftmp2],   %[ftmp4],           %[ftmp7]            \n\t"
    "and        %[ftmp2],   %[ftmp2],           %[ff_pb_fe]         \n\t"
    "li         %[tmp0],    0x01                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
    "psrlh      %[ftmp2],   %[ftmp2],           %[ftmp9]            \n\t"
    "paddusb    %[ftmp1],   %[ftmp1],           %[ftmp2]            \n\t"
557
    "psubusb    %[ftmp1],   %[ftmp1],           %[ftmp12]           \n\t"
558 559 560 561 562 563 564
    "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"
    "xor        %[ftmp9],   %[ftmp9],           %[ftmp9]            \n\t"
    /* ftmp0: mask */
    "pcmpeqb    %[ftmp0],   %[ftmp0],           %[ftmp9]            \n\t"

    "gsldlc1    %[ftmp9],   0x07(%[thresh])                         \n\t"
    "gsldrc1    %[ftmp9],   0x00(%[thresh])                         \n\t"
565 566
    "psubusb    %[ftmp1],   %[ftmp10],          %[ftmp9]            \n\t"
    "psubusb    %[ftmp2],   %[ftmp11],          %[ftmp9]            \n\t"
567 568 569 570
    "paddb      %[ftmp1],   %[ftmp1],           %[ftmp2]            \n\t"
    "xor        %[ftmp2],   %[ftmp2],           %[ftmp2]            \n\t"
    "pcmpeqb    %[ftmp1],   %[ftmp1],           %[ftmp2]            \n\t"
    "pcmpeqb    %[ftmp2],   %[ftmp2],           %[ftmp2]            \n\t"
571
    /* ftmp1: hev */
572 573 574 575 576 577 578 579 580 581 582 583
    "xor        %[ftmp1],   %[ftmp1],           %[ftmp2]            \n\t"

    "xor        %[ftmp4],   %[ftmp4],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp5],   %[ftmp5],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp6],   %[ftmp6],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp7],   %[ftmp7],           %[ff_pb_80]         \n\t"
    "psubsb     %[ftmp2],   %[ftmp4],           %[ftmp7]            \n\t"
    "psubsb     %[ftmp9],   %[ftmp6],           %[ftmp5]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp9]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp9]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp9]            \n\t"
    "and        %[ftmp2],   %[ftmp2],           %[ftmp0]            \n\t"
584
    "pandn      %[ftmp12],  %[ftmp1],           %[ftmp2]            \n\t"
585 586 587 588 589 590 591 592 593 594 595 596 597
    "and        %[ftmp2],   %[ftmp2],           %[ftmp1]            \n\t"

    "li         %[tmp0],    0x0b                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
    "paddsb     %[ftmp0],   %[ftmp2],           %[ff_pb_03]         \n\t"
    VP8_MBLOOP_HPSRAB
    "paddsb     %[ftmp5],   %[ftmp5],           %[ftmp0]            \n\t"
    "paddsb     %[ftmp0],   %[ftmp2],           %[ff_pb_04]         \n\t"
    VP8_MBLOOP_HPSRAB
    "psubsb     %[ftmp6],   %[ftmp6],           %[ftmp0]            \n\t"

    "li         %[tmp0],    0x07                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
598 599
    "xor        %[ftmp0],   %[ftmp0],           %[ftmp0]            \n\t"

600
    VP8_MBLOOP_HPSRAB_ADD(%[ff_ph_1b00])
601 602
    "psubsb     %[ftmp6],   %[ftmp6],           %[ftmp1]            \n\t"
    "paddsb     %[ftmp5],   %[ftmp5],           %[ftmp1]            \n\t"
603 604
    "xor        %[ftmp6],   %[ftmp6],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp5],   %[ftmp5],           %[ff_pb_80]         \n\t"
605 606 607 608 609
    MMI_SLL(%[tmp0], %[src_pixel_step], 0x02)
    MMI_SUBU(%[src_ptr], %[src_ptr], %[tmp0])
    "gssdlc1    %[ftmp5],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp5],   0x00(%[src_ptr])                        \n\t"
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
610 611
    "gssdlc1    %[ftmp6],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp6],   0x00(%[src_ptr])                        \n\t"
612

613
    VP8_MBLOOP_HPSRAB_ADD(%[ff_ph_1200])
614 615
    "paddsb     %[ftmp4],   %[ftmp4],           %[ftmp1]            \n\t"
    "psubsb     %[ftmp7],   %[ftmp7],           %[ftmp1]            \n\t"
616 617
    "xor        %[ftmp4],   %[ftmp4],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp7],   %[ftmp7],           %[ff_pb_80]         \n\t"
618 619 620 621 622 623 624
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gssdlc1    %[ftmp7],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp7],   0x00(%[src_ptr])                        \n\t"
    MMI_SUBU(%[src_ptr], %[src_ptr], %[tmp0])
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gssdlc1    %[ftmp4],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp4],   0x00(%[src_ptr])                        \n\t"
625 626

    VP8_MBLOOP_HPSRAB_ADD(%[ff_ph_0900])
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
    "xor        %[ftmp3],   %[ftmp3],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp8],   %[ftmp8],           %[ff_pb_80]         \n\t"
    "paddsb     %[ftmp3],   %[ftmp3],           %[ftmp1]            \n\t"
    "psubsb     %[ftmp8],   %[ftmp8],           %[ftmp1]            \n\t"
    "xor        %[ftmp3],   %[ftmp3],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp8],   %[ftmp8],           %[ff_pb_80]         \n\t"
    MMI_ADDU(%[src_ptr], %[src_ptr], %[tmp0])
    "gssdlc1    %[ftmp8],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp8],   0x00(%[src_ptr])                        \n\t"
    MMI_SUBU(%[src_ptr], %[src_ptr], %[tmp0])
    MMI_SUBU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gssdlc1    %[ftmp3],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp3],   0x00(%[src_ptr])                        \n\t"

    MMI_SUBU(%[src_ptr], %[src_ptr], %[src_pixel_step])
642
    MMI_ADDIU(%[src_ptr], %[src_ptr], 0x08)
643
    "addiu      %[count],   %[count],           -0x01               \n\t"
644 645 646 647 648 649
    "bnez       %[count],   1b                                      \n\t"
    : [ftmp0]"=&f"(ftmp[0]),              [ftmp1]"=&f"(ftmp[1]),
      [ftmp2]"=&f"(ftmp[2]),              [ftmp3]"=&f"(ftmp[3]),
      [ftmp4]"=&f"(ftmp[4]),              [ftmp5]"=&f"(ftmp[5]),
      [ftmp6]"=&f"(ftmp[6]),              [ftmp7]"=&f"(ftmp[7]),
      [ftmp8]"=&f"(ftmp[8]),              [ftmp9]"=&f"(ftmp[9]),
650 651 652 653 654
      [ftmp10]"=&f"(ftmp[10]),            [ftmp11]"=&f"(ftmp[11]),
      [ftmp12]"=&f"(ftmp[12]),            [tmp0]"=&r"(tmp[0]),
      [src_ptr]"+&r"(src_ptr),            [count]"+&r"(count)
    : [limit]"r"(limit),                  [blimit]"r"(blimit),
      [thresh]"r"(thresh),
655
      [src_pixel_step]"r"((mips_reg)src_pixel_step),
656 657 658 659
      [ff_pb_fe]"f"(ff_pb_fe),            [ff_pb_80]"f"(ff_pb_80),
      [ff_pb_04]"f"(ff_pb_04),            [ff_pb_03]"f"(ff_pb_03),
      [ff_ph_0900]"f"(ff_ph_0900),        [ff_ph_1b00]"f"(ff_ph_1b00),
      [ff_ph_1200]"f"(ff_ph_1200),        [ff_ph_003f]"f"(ff_ph_003f)
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
    : "memory"
  );
}

#define VP8_MBLOOP_VPSRAB_ADDH                                          \
  "xor        %[ftmp7],   %[ftmp7],           %[ftmp7]            \n\t" \
  "xor        %[ftmp8],   %[ftmp8],           %[ftmp8]            \n\t" \
  "punpcklbh  %[ftmp7],   %[ftmp7],           %[ftmp0]            \n\t" \
  "punpckhbh  %[ftmp8],   %[ftmp8],           %[ftmp0]            \n\t"

#define VP8_MBLOOP_VPSRAB_ADDT                                          \
  "paddh      %[ftmp7],   %[ftmp7],           %[ff_ph_003f]       \n\t" \
  "paddh      %[ftmp8],   %[ftmp8],           %[ff_ph_003f]       \n\t" \
  "psrah      %[ftmp7],   %[ftmp7],           %[ftmp12]           \n\t" \
  "psrah      %[ftmp8],   %[ftmp8],           %[ftmp12]           \n\t" \
  "packsshb   %[ftmp3],   %[ftmp7],           %[ftmp8]            \n\t"

void vp8_mbloop_filter_vertical_edge_mmi(
    unsigned char *src_ptr, int src_pixel_step, const unsigned char *blimit,
    const unsigned char *limit, const unsigned char *thresh, int count) {
  mips_reg tmp[1];
  DECLARE_ALIGNED(8, const uint64_t, srct[1]);
682
  double ftmp[14];
683 684 685 686 687

  __asm__ volatile (
    MMI_SUBU(%[src_ptr], %[src_ptr], 0x04)

    "1:                                                             \n\t"
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
    "gsldlc1    %[ftmp5],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp5],   0x00(%[src_ptr])                        \n\t"
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp6],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp6],   0x00(%[src_ptr])                        \n\t"
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp7],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp7],   0x00(%[src_ptr])                        \n\t"
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp8],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp8],   0x00(%[src_ptr])                        \n\t"

    "punpcklbh  %[ftmp11],  %[ftmp5],           %[ftmp6]            \n\t"
    "punpckhbh  %[ftmp12],  %[ftmp5],           %[ftmp6]            \n\t"
    "punpcklbh  %[ftmp9],   %[ftmp7],           %[ftmp8]            \n\t"
    "punpckhbh  %[ftmp10],  %[ftmp7],           %[ftmp8]            \n\t"

    "punpcklhw  %[ftmp1],   %[ftmp12],          %[ftmp10]           \n\t"
    "punpckhhw  %[ftmp2],   %[ftmp12],          %[ftmp10]           \n\t"
    "punpcklhw  %[ftmp3],   %[ftmp11],          %[ftmp9]            \n\t"
    "punpckhhw  %[ftmp4],   %[ftmp11],          %[ftmp9]            \n\t"

    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp5],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp5],   0x00(%[src_ptr])                        \n\t"
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp6],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp6],   0x00(%[src_ptr])                        \n\t"
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp7],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp7],   0x00(%[src_ptr])                        \n\t"
    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp8],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp8],   0x00(%[src_ptr])                        \n\t"

    "punpcklbh  %[ftmp11],  %[ftmp5],           %[ftmp6]            \n\t"
    "punpckhbh  %[ftmp12],  %[ftmp5],           %[ftmp6]            \n\t"
    "punpcklbh  %[ftmp9],   %[ftmp7],           %[ftmp8]            \n\t"
    "punpckhbh  %[ftmp10],  %[ftmp7],           %[ftmp8]            \n\t"

    "punpcklhw  %[ftmp5],   %[ftmp12],          %[ftmp10]           \n\t"
    "punpckhhw  %[ftmp6],   %[ftmp12],          %[ftmp10]           \n\t"
    "punpcklhw  %[ftmp7],   %[ftmp11],          %[ftmp9]            \n\t"
    "punpckhhw  %[ftmp8],   %[ftmp11],          %[ftmp9]            \n\t"

    "gsldlc1    %[ftmp13],  0x07(%[limit])                          \n\t"
    "gsldrc1    %[ftmp13],  0x00(%[limit])                          \n\t"
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
    /* ftmp9:q0  ftmp10:q1 */
    "punpcklwd  %[ftmp9],   %[ftmp1],           %[ftmp5]            \n\t"
    "punpckhwd  %[ftmp10],  %[ftmp1],           %[ftmp5]            \n\t"
    /* ftmp11:q2  ftmp12:q3 */
    "punpcklwd  %[ftmp11],  %[ftmp2],           %[ftmp6]            \n\t"
    "punpckhwd  %[ftmp12],  %[ftmp2],           %[ftmp6]            \n\t"
    /* srct[0x00]: q3 */
    "sdc1       %[ftmp12],  0x00(%[srct])                           \n\t"
    /* ftmp1:p3  ftmp2:p2 */
    "punpcklwd  %[ftmp1],   %[ftmp3],           %[ftmp7]            \n\t"
    "punpckhwd  %[ftmp2],   %[ftmp3],           %[ftmp7]            \n\t"
    /* srct[0x08]: p3 */
    "sdc1       %[ftmp1],   0x08(%[srct])                           \n\t"
    /* ftmp5:p1  ftmp6:p0 */
    "punpcklwd  %[ftmp5],   %[ftmp4],           %[ftmp8]            \n\t"
    "punpckhwd  %[ftmp6],   %[ftmp4],           %[ftmp8]            \n\t"

    /* abs (q3-q2) */
    "pasubub    %[ftmp7],   %[ftmp12],          %[ftmp11]           \n\t"
754
    "psubusb    %[ftmp0],   %[ftmp7],           %[ftmp13]           \n\t"
755 756
    /* abs (q2-q1) */
    "pasubub    %[ftmp7],   %[ftmp11],          %[ftmp10]           \n\t"
757
    "psubusb    %[ftmp7],   %[ftmp7],           %[ftmp13]           \n\t"
758 759 760
    "or         %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    /* ftmp3: abs(q1-q0) */
    "pasubub    %[ftmp3],   %[ftmp10],          %[ftmp9]            \n\t"
761
    "psubusb    %[ftmp7],   %[ftmp3],           %[ftmp13]           \n\t"
762 763 764
    "or         %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    /* ftmp4: abs(p1-p0) */
    "pasubub    %[ftmp4],   %[ftmp5],           %[ftmp6]            \n\t"
765
    "psubusb    %[ftmp7],   %[ftmp4],           %[ftmp13]           \n\t"
766 767 768
    "or         %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    /* abs (p2-p1) */
    "pasubub    %[ftmp7],   %[ftmp2],           %[ftmp5]            \n\t"
769
    "psubusb    %[ftmp7],   %[ftmp7],           %[ftmp13]           \n\t"
770 771 772
    "or         %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    /* abs (p3-p2) */
    "pasubub    %[ftmp7],   %[ftmp1],           %[ftmp2]            \n\t"
773
    "psubusb    %[ftmp7],   %[ftmp7],           %[ftmp13]           \n\t"
774
    "or         %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
775 776 777 778 779 780

    "gsldlc1    %[ftmp13],  0x07(%[blimit])                         \n\t"
    "gsldrc1    %[ftmp13],  0x00(%[blimit])                         \n\t"
    "gsldlc1    %[ftmp7],   0x07(%[thresh])                         \n\t"
    "gsldrc1    %[ftmp7],   0x00(%[thresh])                         \n\t"
    /* abs (p0-q0) * 2 */
781 782
    "pasubub    %[ftmp1],   %[ftmp9],           %[ftmp6]            \n\t"
    "paddusb    %[ftmp1],   %[ftmp1],           %[ftmp1]            \n\t"
783
    /* abs (p1-q1) / 2 */
784 785 786 787 788 789
    "pasubub    %[ftmp12],  %[ftmp10],          %[ftmp5]            \n\t"
    "and        %[ftmp12],  %[ftmp12],          %[ff_pb_fe]         \n\t"
    "li         %[tmp0],    0x01                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp8]                                \n\t"
    "psrlh      %[ftmp12],  %[ftmp12],          %[ftmp8]            \n\t"
    "paddusb    %[ftmp12],  %[ftmp1],           %[ftmp12]           \n\t"
790
    "psubusb    %[ftmp12],  %[ftmp12],          %[ftmp13]           \n\t"
791 792
    "or         %[ftmp0],   %[ftmp0],           %[ftmp12]           \n\t"
    "xor        %[ftmp12],  %[ftmp12],          %[ftmp12]           \n\t"
793
    /* ftmp0: mask */
794 795
    "pcmpeqb    %[ftmp0],   %[ftmp0],           %[ftmp12]           \n\t"

796 797 798 799
    /* abs(p1-p0) - thresh */
    "psubusb    %[ftmp4],   %[ftmp4],           %[ftmp7]            \n\t"
    /* abs(q1-q0) - thresh */
    "psubusb    %[ftmp3],   %[ftmp3],           %[ftmp7]            \n\t"
800 801 802
    "or         %[ftmp3],   %[ftmp4],           %[ftmp3]            \n\t"
    "pcmpeqb    %[ftmp3],   %[ftmp3],           %[ftmp12]           \n\t"
    "pcmpeqb    %[ftmp1],   %[ftmp1],           %[ftmp1]            \n\t"
803
    /* ftmp1: hev */
804 805
    "xor        %[ftmp1],   %[ftmp3],           %[ftmp1]            \n\t"

806
    /* ftmp2:ps2, ftmp5:ps1, ftmp6:ps0, ftmp9:qs0, ftmp10:qs1, ftmp11:qs2 */
807 808 809 810 811 812 813 814 815 816 817 818
    "xor        %[ftmp11],  %[ftmp11],          %[ff_pb_80]         \n\t"
    "xor        %[ftmp10],  %[ftmp10],          %[ff_pb_80]         \n\t"
    "xor        %[ftmp9],   %[ftmp9],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp6],   %[ftmp6],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp5],   %[ftmp5],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp2],   %[ftmp2],           %[ff_pb_80]         \n\t"

    "psubsb     %[ftmp3],   %[ftmp5],           %[ftmp10]           \n\t"
    "psubsb     %[ftmp4],   %[ftmp9],           %[ftmp6]            \n\t"
    "paddsb     %[ftmp3],   %[ftmp3],           %[ftmp4]            \n\t"
    "paddsb     %[ftmp3],   %[ftmp3],           %[ftmp4]            \n\t"
    "paddsb     %[ftmp3],   %[ftmp3],           %[ftmp4]            \n\t"
819
    /* filter_value &= mask */
820
    "and        %[ftmp0],   %[ftmp0],           %[ftmp3]            \n\t"
821
    /* Filter2 = filter_value & hev */
822
    "and        %[ftmp3],   %[ftmp1],           %[ftmp0]            \n\t"
823
    /* filter_value &= ~hev */
824 825 826 827 828 829 830 831 832 833
    "pandn      %[ftmp0],   %[ftmp1],           %[ftmp0]            \n\t"

    "paddsb     %[ftmp4],   %[ftmp3],           %[ff_pb_04]         \n\t"
    "li         %[tmp0],    0x0b                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp12]                               \n\t"
    "punpcklbh  %[ftmp7],   %[ftmp7],           %[ftmp4]            \n\t"
    "punpckhbh  %[ftmp8],   %[ftmp8],           %[ftmp4]            \n\t"
    "psrah      %[ftmp7],   %[ftmp7],           %[ftmp12]           \n\t"
    "psrah      %[ftmp8],   %[ftmp8],           %[ftmp12]           \n\t"
    "packsshb   %[ftmp4],   %[ftmp7],           %[ftmp8]            \n\t"
834
    /* ftmp9: qs0 */
835 836 837 838 839 840 841
    "psubsb     %[ftmp9],   %[ftmp9],           %[ftmp4]            \n\t"
    "paddsb     %[ftmp3],   %[ftmp3],           %[ff_pb_03]         \n\t"
    "punpcklbh  %[ftmp7],   %[ftmp7],           %[ftmp3]            \n\t"
    "punpckhbh  %[ftmp8],   %[ftmp8],           %[ftmp3]            \n\t"
    "psrah      %[ftmp7],   %[ftmp7],           %[ftmp12]           \n\t"
    "psrah      %[ftmp8],   %[ftmp8],           %[ftmp12]           \n\t"
    "packsshb   %[ftmp3],   %[ftmp7],           %[ftmp8]            \n\t"
842
    /* ftmp6: ps0 */
843 844 845 846 847 848 849 850 851 852 853
    "paddsb     %[ftmp6],   %[ftmp6],           %[ftmp3]            \n\t"

    "li         %[tmp0],    0x07                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp12]                               \n\t"
    VP8_MBLOOP_VPSRAB_ADDH
    "paddh      %[ftmp1],   %[ff_ph_0900],      %[ff_ph_0900]       \n\t"
    "paddh      %[ftmp1],   %[ftmp1],           %[ff_ph_0900]       \n\t"
    "pmulhh     %[ftmp7],   %[ftmp7],           %[ftmp1]            \n\t"
    "pmulhh     %[ftmp8],   %[ftmp8],           %[ftmp1]            \n\t"
    VP8_MBLOOP_VPSRAB_ADDT
    "psubsb     %[ftmp4],   %[ftmp9],           %[ftmp3]            \n\t"
854
    /* ftmp9: oq0 */
855 856
    "xor        %[ftmp9],   %[ftmp4],           %[ff_pb_80]         \n\t"
    "paddsb     %[ftmp4],   %[ftmp6],           %[ftmp3]            \n\t"
857
    /* ftmp6: op0 */
858 859 860 861 862 863 864 865
    "xor        %[ftmp6],   %[ftmp4],           %[ff_pb_80]         \n\t"

    VP8_MBLOOP_VPSRAB_ADDH
    "paddh      %[ftmp1],   %[ff_ph_0900],      %[ff_ph_0900]       \n\t"
    "pmulhh     %[ftmp7],   %[ftmp7],           %[ftmp1]            \n\t"
    "pmulhh     %[ftmp8],   %[ftmp8],           %[ftmp1]            \n\t"
    VP8_MBLOOP_VPSRAB_ADDT
    "psubsb     %[ftmp4],   %[ftmp10],          %[ftmp3]            \n\t"
866
    /* ftmp10: oq1 */
867 868
    "xor        %[ftmp10],   %[ftmp4],          %[ff_pb_80]         \n\t"
    "paddsb     %[ftmp4],   %[ftmp5],           %[ftmp3]            \n\t"
869
    /* ftmp5: op1 */
870 871 872 873 874 875 876
    "xor        %[ftmp5],   %[ftmp4],           %[ff_pb_80]         \n\t"

    VP8_MBLOOP_VPSRAB_ADDH
    "pmulhh     %[ftmp7],   %[ftmp7],           %[ff_ph_0900]       \n\t"
    "pmulhh     %[ftmp8],   %[ftmp8],           %[ff_ph_0900]       \n\t"
    VP8_MBLOOP_VPSRAB_ADDT
    "psubsb     %[ftmp4],   %[ftmp11],          %[ftmp3]            \n\t"
877
    /* ftmp11: oq2 */
878 879
    "xor        %[ftmp11],  %[ftmp4],           %[ff_pb_80]         \n\t"
    "paddsb     %[ftmp4],   %[ftmp2],           %[ftmp3]            \n\t"
880
    /* ftmp2: op2 */
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
    "xor        %[ftmp2],   %[ftmp4],           %[ff_pb_80]         \n\t"

    "ldc1       %[ftmp12],  0x00(%[srct])                           \n\t"
    "ldc1       %[ftmp8],   0x08(%[srct])                           \n\t"

    "punpcklbh  %[ftmp0],   %[ftmp8],           %[ftmp2]            \n\t"
    "punpckhbh  %[ftmp1],   %[ftmp8],           %[ftmp2]            \n\t"
    "punpcklbh  %[ftmp2],   %[ftmp5],           %[ftmp6]            \n\t"
    "punpckhbh  %[ftmp3],   %[ftmp5],           %[ftmp6]            \n\t"
    "punpcklhw  %[ftmp4],   %[ftmp0],           %[ftmp2]            \n\t"
    "punpckhhw  %[ftmp5],   %[ftmp0],           %[ftmp2]            \n\t"
    "punpcklhw  %[ftmp6],   %[ftmp1],           %[ftmp3]            \n\t"
    "punpckhhw  %[ftmp7],   %[ftmp1],           %[ftmp3]            \n\t"

    "punpcklbh  %[ftmp0],   %[ftmp9],           %[ftmp10]           \n\t"
    "punpckhbh  %[ftmp1],   %[ftmp9],           %[ftmp10]           \n\t"
    "punpcklbh  %[ftmp2],   %[ftmp11],          %[ftmp12]           \n\t"
    "punpckhbh  %[ftmp3],   %[ftmp11],          %[ftmp12]           \n\t"
    "punpcklhw  %[ftmp8],   %[ftmp0],           %[ftmp2]            \n\t"
    "punpckhhw  %[ftmp9],   %[ftmp0],           %[ftmp2]            \n\t"
    "punpcklhw  %[ftmp10],  %[ftmp1],           %[ftmp3]            \n\t"
    "punpckhhw  %[ftmp11],  %[ftmp1],           %[ftmp3]            \n\t"

904 905 906 907 908 909 910 911
    "punpcklwd  %[ftmp0],   %[ftmp7],           %[ftmp11]           \n\t"
    "punpckhwd  %[ftmp1],   %[ftmp7],           %[ftmp11]           \n\t"
    "gssdlc1    %[ftmp1],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp1],   0x00(%[src_ptr])                        \n\t"
    MMI_SUBU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gssdlc1    %[ftmp0],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp0],   0x00(%[src_ptr])                        \n\t"

912 913
    "punpcklwd  %[ftmp0],   %[ftmp6],           %[ftmp10]           \n\t"
    "punpckhwd  %[ftmp1],   %[ftmp6],           %[ftmp10]           \n\t"
914 915 916 917
    MMI_SUBU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gssdlc1    %[ftmp1],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp1],   0x00(%[src_ptr])                        \n\t"
    MMI_SUBU(%[src_ptr], %[src_ptr], %[src_pixel_step])
918 919 920 921 922
    "gssdlc1    %[ftmp0],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp0],   0x00(%[src_ptr])                        \n\t"

    "punpcklwd  %[ftmp1],   %[ftmp5],           %[ftmp9]            \n\t"
    "punpckhwd  %[ftmp0],   %[ftmp5],           %[ftmp9]            \n\t"
923 924 925 926 927 928
    MMI_SUBU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gssdlc1    %[ftmp0],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp0],   0x00(%[src_ptr])                        \n\t"
    MMI_SUBU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gssdlc1    %[ftmp1],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp1],   0x00(%[src_ptr])                        \n\t"
929 930 931

    "punpcklwd  %[ftmp1],   %[ftmp4],           %[ftmp8]            \n\t"
    "punpckhwd  %[ftmp0],   %[ftmp4],           %[ftmp8]            \n\t"
932 933 934 935 936 937
    MMI_SUBU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gssdlc1    %[ftmp0],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp0],   0x00(%[src_ptr])                        \n\t"
    MMI_SUBU(%[src_ptr], %[src_ptr], %[src_pixel_step])
    "gssdlc1    %[ftmp1],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp1],   0x00(%[src_ptr])                        \n\t"
938 939 940 941 942 943 944 945 946 947 948
    "addiu      %[count],   %[count],           -0x01               \n\t"

    MMI_SLL(%[tmp0], %[src_pixel_step], 0x03)
    MMI_ADDU(%[src_ptr], %[src_ptr], %[tmp0])
    "bnez       %[count],   1b                                      \n\t"
    : [ftmp0]"=&f"(ftmp[0]),              [ftmp1]"=&f"(ftmp[1]),
      [ftmp2]"=&f"(ftmp[2]),              [ftmp3]"=&f"(ftmp[3]),
      [ftmp4]"=&f"(ftmp[4]),              [ftmp5]"=&f"(ftmp[5]),
      [ftmp6]"=&f"(ftmp[6]),              [ftmp7]"=&f"(ftmp[7]),
      [ftmp8]"=&f"(ftmp[8]),              [ftmp9]"=&f"(ftmp[9]),
      [ftmp10]"=&f"(ftmp[10]),            [ftmp11]"=&f"(ftmp[11]),
949 950 951
      [ftmp12]"=&f"(ftmp[12]),            [ftmp13]"=&f"(ftmp[13]),
      [tmp0]"=&r"(tmp[0]),                [src_ptr]"+&r"(src_ptr),
      [count]"+&r"(count)
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337
    : [limit]"r"(limit),                [blimit]"r"(blimit),
      [srct]"r"(srct),                  [thresh]"r"(thresh),
      [src_pixel_step]"r"((mips_reg)src_pixel_step),
      [ff_ph_003f]"f"(ff_ph_003f),      [ff_ph_0900]"f"(ff_ph_0900),
      [ff_pb_03]"f"(ff_pb_03),          [ff_pb_04]"f"(ff_pb_04),
      [ff_pb_80]"f"(ff_pb_80),          [ff_pb_fe]"f"(ff_pb_fe)
    : "memory"
  );
}

#define VP8_SIMPLE_HPSRAB                                               \
  "psllh      %[ftmp0],   %[ftmp5],           %[ftmp8]            \n\t" \
  "psrah      %[ftmp0],   %[ftmp0],           %[ftmp9]            \n\t" \
  "psrlh      %[ftmp0],   %[ftmp0],           %[ftmp8]            \n\t" \
  "psrah      %[ftmp1],   %[ftmp5],           %[ftmp10]           \n\t" \
  "psllh      %[ftmp1],   %[ftmp1],           %[ftmp8]            \n\t" \
  "or         %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"

void vp8_loop_filter_simple_horizontal_edge_mmi(unsigned char *src_ptr,
                                                int src_pixel_step,
                                                const unsigned char *blimit) {
  uint32_t tmp[1], count = 2;
  mips_reg addr[2];
  double ftmp[12];

  __asm__ volatile (
    "li         %[tmp0],    0x08                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp8]                                \n\t"
    "li         %[tmp0],    0x03                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
    "li         %[tmp0],    0x0b                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp10]                               \n\t"
    "li         %[tmp0],    0x01                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp11]                               \n\t"

    "1:                                                             \n\t"
    "gsldlc1    %[ftmp3],   0x07(%[blimit])                         \n\t"
    "gsldrc1    %[ftmp3],   0x00(%[blimit])                         \n\t"

    MMI_ADDU(%[addr0], %[src_ptr], %[src_pixel_step])

    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step_x2])
    "gsldlc1    %[ftmp2],   0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp2],   0x00(%[addr1])                          \n\t"
    "gsldlc1    %[ftmp7],   0x07(%[addr0])                          \n\t"
    "gsldrc1    %[ftmp7],   0x00(%[addr0])                          \n\t"
    "pasubub    %[ftmp1],   %[ftmp7],           %[ftmp2]            \n\t"
    "and        %[ftmp1],   %[ftmp1],           %[ff_pb_fe]         \n\t"
    "psrlh      %[ftmp1],   %[ftmp1],           %[ftmp11]           \n\t"

    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step])
    "gsldlc1    %[ftmp6],   0x07(%[addr1])                          \n\t"
    "gsldrc1    %[ftmp6],   0x00(%[addr1])                          \n\t"
    "gsldlc1    %[ftmp0],   0x07(%[src_ptr])                        \n\t"
    "gsldrc1    %[ftmp0],   0x00(%[src_ptr])                        \n\t"
    "pasubub    %[ftmp5],   %[ftmp6],           %[ftmp0]            \n\t"
    "paddusb    %[ftmp5],   %[ftmp5],           %[ftmp5]            \n\t"
    "paddusb    %[ftmp5],   %[ftmp5],           %[ftmp1]            \n\t"
    "psubusb    %[ftmp5],   %[ftmp5],           %[ftmp3]            \n\t"
    "xor        %[ftmp3],   %[ftmp3],           %[ftmp3]            \n\t"
    "pcmpeqb    %[ftmp5],   %[ftmp5],           %[ftmp3]            \n\t"

    "xor        %[ftmp2],   %[ftmp2],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp7],   %[ftmp7],           %[ff_pb_80]         \n\t"
    "psubsb     %[ftmp2],   %[ftmp2],           %[ftmp7]            \n\t"
    "xor        %[ftmp6],   %[ftmp6],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp3],   %[ftmp0],           %[ff_pb_80]         \n\t"
    "psubsb     %[ftmp0],   %[ftmp3],           %[ftmp6]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp0]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp0]            \n\t"
    "paddsb     %[ftmp2],   %[ftmp2],           %[ftmp0]            \n\t"
    "and        %[ftmp5],   %[ftmp5],           %[ftmp2]            \n\t"

    "paddsb     %[ftmp5],   %[ftmp5],           %[ff_pb_04]         \n\t"
    VP8_SIMPLE_HPSRAB
    "psubsb     %[ftmp3],   %[ftmp3],           %[ftmp0]            \n\t"
    "xor        %[ftmp3],   %[ftmp3],           %[ff_pb_80]         \n\t"
    "gssdlc1    %[ftmp3],   0x07(%[src_ptr])                        \n\t"
    "gssdrc1    %[ftmp3],   0x00(%[src_ptr])                        \n\t"

    "psubsb     %[ftmp5],   %[ftmp5],           %[ff_pb_01]         \n\t"
    VP8_SIMPLE_HPSRAB
    "paddsb     %[ftmp6],   %[ftmp6],           %[ftmp0]            \n\t"
    "xor        %[ftmp6],   %[ftmp6],           %[ff_pb_80]         \n\t"
    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step])
    "gssdlc1    %[ftmp6],   0x07(%[addr1])                          \n\t"
    "gssdrc1    %[ftmp6],   0x00(%[addr1])                          \n\t"

    "addiu      %[count],   %[count],           -0x01               \n\t"
    MMI_ADDIU(%[src_ptr], %[src_ptr], 0x08)
    "bnez       %[count],   1b                                      \n\t"
    : [ftmp0]"=&f"(ftmp[0]),              [ftmp1]"=&f"(ftmp[1]),
      [ftmp2]"=&f"(ftmp[2]),              [ftmp3]"=&f"(ftmp[3]),
      [ftmp4]"=&f"(ftmp[4]),              [ftmp5]"=&f"(ftmp[5]),
      [ftmp6]"=&f"(ftmp[6]),              [ftmp7]"=&f"(ftmp[7]),
      [ftmp8]"=&f"(ftmp[8]),              [ftmp9]"=&f"(ftmp[9]),
      [ftmp10]"=&f"(ftmp[10]),            [ftmp11]"=&f"(ftmp[11]),
      [tmp0]"=&r"(tmp[0]),
      [addr0]"=&r"(addr[0]),            [addr1]"=&r"(addr[1]),
      [src_ptr]"+&r"(src_ptr),          [count]"+&r"(count)
    : [blimit]"r"(blimit),
      [src_pixel_step]"r"((mips_reg)src_pixel_step),
      [src_pixel_step_x2]"r"((mips_reg)(src_pixel_step<<1)),
      [ff_pb_fe]"f"(ff_pb_fe),          [ff_pb_80]"f"(ff_pb_80),
      [ff_pb_04]"f"(ff_pb_04),          [ff_pb_01]"f"(ff_pb_01)
    : "memory"
  );
}

void vp8_loop_filter_simple_vertical_edge_mmi(unsigned char *src_ptr,
                                              int src_pixel_step,
                                              const unsigned char *blimit) {
  uint32_t tmp[1], count = 2;
  mips_reg addr[2];
  DECLARE_ALIGNED(8, const uint64_t, srct[1]);
  double ftmp[12];

  __asm__ volatile (
    "li         %[tmp0],    0x08                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp8]                                \n\t"
    "li         %[tmp0],    0x20                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp10]                               \n\t"

    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step_x4])
    MMI_SUBU(%[src_ptr], %[src_ptr], 0x02)

    "1:                                                             \n\t"
    MMI_ADDU(%[addr0], %[src_ptr], %[src_pixel_step])
    MMI_ADDU(%[addr1], %[addr0], %[src_pixel_step_x2])
    "gslwlc1    %[ftmp0],   0x03(%[addr1])                          \n\t"
    "gslwrc1    %[ftmp0],   0x00(%[addr1])                          \n\t"
    MMI_ADDU(%[addr1], %[src_ptr], %[src_pixel_step_x2])
    "gslwlc1    %[ftmp6],   0x03(%[addr1])                          \n\t"
    "gslwrc1    %[ftmp6],   0x00(%[addr1])                          \n\t"
    "punpcklbh  %[ftmp6],   %[ftmp6],           %[ftmp0]            \n\t"

    MMI_ADDU(%[addr1], %[src_ptr], %[src_pixel_step])
    "gslwlc1    %[ftmp0],   0x03(%[addr1])                          \n\t"
    "gslwrc1    %[ftmp0],   0x00(%[addr1])                          \n\t"
    "gslwlc1    %[ftmp4],   0x03(%[src_ptr])                        \n\t"
    "gslwrc1    %[ftmp4],   0x00(%[src_ptr])                        \n\t"

    "punpcklbh  %[ftmp4],   %[ftmp4],           %[ftmp0]            \n\t"
    "punpckhhw  %[ftmp5],   %[ftmp4],           %[ftmp6]            \n\t"
    "punpcklhw  %[ftmp4],   %[ftmp4],           %[ftmp6]            \n\t"

    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step])
    "gslwlc1    %[ftmp7],   0x03(%[addr1])                          \n\t"
    "gslwrc1    %[ftmp7],   0x00(%[addr1])                          \n\t"
    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step_x2])
    "gslwlc1    %[ftmp6],   0x03(%[addr1])                          \n\t"
    "gslwrc1    %[ftmp6],   0x00(%[addr1])                          \n\t"
    "punpcklbh  %[ftmp6],   %[ftmp6],           %[ftmp7]            \n\t"

    MMI_SUBU(%[addr1], %[addr0], %[src_pixel_step_x4])
    "gslwlc1    %[ftmp1],   0x03(%[addr1])                          \n\t"
    "gslwrc1    %[ftmp1],   0x00(%[addr1])                          \n\t"
    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step_x4])
    "gslwlc1    %[ftmp0],   0x03(%[addr1])                          \n\t"
    "gslwrc1    %[ftmp0],   0x00(%[addr1])                          \n\t"
    "punpcklbh  %[ftmp0],   %[ftmp0],           %[ftmp1]            \n\t"

    "punpckhhw  %[ftmp2],   %[ftmp0],           %[ftmp6]            \n\t"
    "punpcklhw  %[ftmp0],   %[ftmp0],           %[ftmp6]            \n\t"
    "punpckhwd  %[ftmp1],   %[ftmp0],           %[ftmp4]            \n\t"
    "punpcklwd  %[ftmp0],   %[ftmp0],           %[ftmp4]            \n\t"
    "punpckhwd  %[ftmp3],   %[ftmp2],           %[ftmp5]            \n\t"
    "punpcklwd  %[ftmp2],   %[ftmp2],           %[ftmp5]            \n\t"

    "li         %[tmp0],    0x01                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
    "pasubub    %[ftmp6],   %[ftmp3],           %[ftmp0]            \n\t"
    "and        %[ftmp6],   %[ftmp6],           %[ff_pb_fe]         \n\t"
    "psrlh      %[ftmp6],   %[ftmp6],           %[ftmp9]            \n\t"
    "pasubub    %[ftmp5],   %[ftmp1],           %[ftmp2]            \n\t"
    "paddusb    %[ftmp5],   %[ftmp5],           %[ftmp5]            \n\t"
    "paddusb    %[ftmp5],   %[ftmp5],           %[ftmp6]            \n\t"

    "gsldlc1    %[ftmp7],   0x07(%[blimit])                         \n\t"
    "gsldrc1    %[ftmp7],   0x00(%[blimit])                         \n\t"
    "psubusb    %[ftmp5],   %[ftmp5],           %[ftmp7]            \n\t"
    "xor        %[ftmp7],   %[ftmp7],           %[ftmp7]            \n\t"
    "pcmpeqb    %[ftmp5],   %[ftmp5],           %[ftmp7]            \n\t"

    "sdc1       %[ftmp0],   0x00(%[srct])                           \n\t"
    "sdc1       %[ftmp3],   0x08(%[srct])                           \n\t"

    "xor        %[ftmp0],   %[ftmp0],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp3],   %[ftmp3],           %[ff_pb_80]         \n\t"
    "psubsb     %[ftmp0],   %[ftmp0],           %[ftmp3]            \n\t"

    "xor        %[ftmp6],   %[ftmp1],           %[ff_pb_80]         \n\t"
    "xor        %[ftmp3],   %[ftmp2],           %[ff_pb_80]         \n\t"
    "psubsb     %[ftmp7],   %[ftmp3],           %[ftmp6]            \n\t"
    "paddsb     %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    "paddsb     %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    "paddsb     %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    "and        %[ftmp5],   %[ftmp5],           %[ftmp0]            \n\t"
    "paddsb     %[ftmp5],   %[ftmp5],           %[ff_pb_04]         \n\t"

    "li         %[tmp0],    0x03                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
    "psllh      %[ftmp0],   %[ftmp5],           %[ftmp8]            \n\t"
    "psrah      %[ftmp0],   %[ftmp0],           %[ftmp9]            \n\t"
    "psrlh      %[ftmp0],   %[ftmp0],           %[ftmp8]            \n\t"

    "li         %[tmp0],    0x0b                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
    "psrah      %[ftmp7],   %[ftmp5],           %[ftmp9]            \n\t"
    "psllh      %[ftmp7],   %[ftmp7],           %[ftmp8]            \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp7]            \n\t"
    "psubsb     %[ftmp3],   %[ftmp3],           %[ftmp0]            \n\t"
    "xor        %[ftmp3],   %[ftmp3],           %[ff_pb_80]         \n\t"
    "psubsb     %[ftmp5],   %[ftmp5],           %[ff_pb_01]         \n\t"

    "li         %[tmp0],    0x03                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
    "psllh      %[ftmp0],   %[ftmp5],           %[ftmp8]            \n\t"
    "psrah      %[ftmp0],   %[ftmp0],           %[ftmp9]            \n\t"
    "psrlh      %[ftmp0],   %[ftmp0],           %[ftmp8]            \n\t"

    "li         %[tmp0],    0x0b                                    \n\t"
    "mtc1       %[tmp0],    %[ftmp9]                                \n\t"
    "psrah      %[ftmp5],   %[ftmp5],           %[ftmp9]            \n\t"
    "psllh      %[ftmp5],   %[ftmp5],           %[ftmp8]            \n\t"
    "or         %[ftmp0],   %[ftmp0],           %[ftmp5]            \n\t"
    "paddsb     %[ftmp6],   %[ftmp6],           %[ftmp0]            \n\t"
    "xor        %[ftmp6],   %[ftmp6],           %[ff_pb_80]         \n\t"

    "ldc1       %[ftmp0],   0x00(%[srct])                           \n\t"
    "ldc1       %[ftmp4],   0x08(%[srct])                           \n\t"

    "punpckhbh  %[ftmp1],   %[ftmp0],           %[ftmp6]            \n\t"
    "punpcklbh  %[ftmp0],   %[ftmp0],           %[ftmp6]            \n\t"
    "punpcklbh  %[ftmp2],   %[ftmp3],           %[ftmp4]            \n\t"
    "punpckhbh  %[ftmp3],   %[ftmp3],           %[ftmp4]            \n\t"

    "punpckhhw  %[ftmp6],   %[ftmp0],           %[ftmp2]            \n\t"
    "punpcklhw  %[ftmp0],   %[ftmp0],           %[ftmp2]            \n\t"

    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step_x4])
    "gsswlc1    %[ftmp0],   0x03(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp0],   0x00(%[addr1])                          \n\t"
    "punpckhhw  %[ftmp5],   %[ftmp1],           %[ftmp3]            \n\t"
    "punpcklhw  %[ftmp1],   %[ftmp1],           %[ftmp3]            \n\t"

    "dsrl       %[ftmp0],   %[ftmp0],           %[ftmp10]           \n\t"
    MMI_SUBU(%[addr1], %[addr0], %[src_pixel_step_x4])
    "gsswlc1    %[ftmp0],   0x03(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp0],   0x00(%[addr1])                          \n\t"
    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step_x2])
    "gsswlc1    %[ftmp6],   0x03(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp6],   0x00(%[addr1])                          \n\t"

    "dsrl       %[ftmp6],   %[ftmp6],           %[ftmp10]           \n\t"
    "gsswlc1    %[ftmp1],   0x03(%[src_ptr])                        \n\t"
    "gsswrc1    %[ftmp1],   0x00(%[src_ptr])                        \n\t"

    MMI_SUBU(%[addr1], %[src_ptr], %[src_pixel_step])
    "gsswlc1    %[ftmp6],   0x03(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp6],   0x00(%[addr1])                          \n\t"

    MMI_ADDU(%[addr1], %[src_ptr], %[src_pixel_step_x2])
    "gsswlc1    %[ftmp5],   0x03(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp5],   0x00(%[addr1])                          \n\t"

    "dsrl       %[ftmp1],   %[ftmp1],           %[ftmp10]           \n\t"
    "gsswlc1    %[ftmp1],   0x03(%[addr0])                          \n\t"
    "gsswrc1    %[ftmp1],   0x00(%[addr0])                          \n\t"

    "dsrl       %[ftmp5],   %[ftmp5],           %[ftmp10]           \n\t"
    MMI_ADDU(%[addr1], %[addr0], %[src_pixel_step_x2])
    "gsswlc1    %[ftmp5],   0x03(%[addr1])                          \n\t"
    "gsswrc1    %[ftmp5],   0x00(%[addr1])                          \n\t"

    MMI_ADDU(%[src_ptr], %[src_ptr], %[src_pixel_step_x8])
    "addiu      %[count],   %[count],           -0x01               \n\t"
    "bnez       %[count],   1b                                      \n\t"
    : [ftmp0]"=&f"(ftmp[0]),              [ftmp1]"=&f"(ftmp[1]),
      [ftmp2]"=&f"(ftmp[2]),              [ftmp3]"=&f"(ftmp[3]),
      [ftmp4]"=&f"(ftmp[4]),              [ftmp5]"=&f"(ftmp[5]),
      [ftmp6]"=&f"(ftmp[6]),              [ftmp7]"=&f"(ftmp[7]),
      [ftmp8]"=&f"(ftmp[8]),              [ftmp9]"=&f"(ftmp[9]),
      [ftmp10]"=&f"(ftmp[10]),            [ftmp11]"=&f"(ftmp[11]),
      [tmp0]"=&r"(tmp[0]),
      [addr0]"=&r"(addr[0]),            [addr1]"=&r"(addr[1]),
      [src_ptr]"+&r"(src_ptr),          [count]"+&r"(count)
    : [blimit]"r"(blimit),              [srct]"r"(srct),
      [src_pixel_step]"r"((mips_reg)src_pixel_step),
      [src_pixel_step_x2]"r"((mips_reg)(src_pixel_step<<1)),
      [src_pixel_step_x4]"r"((mips_reg)(src_pixel_step<<2)),
      [src_pixel_step_x8]"r"((mips_reg)(src_pixel_step<<3)),
      [ff_pb_fe]"f"(ff_pb_fe),          [ff_pb_80]"f"(ff_pb_80),
      [ff_pb_04]"f"(ff_pb_04),          [ff_pb_01]"f"(ff_pb_01)
    : "memory"
  );
}

/* Horizontal MB filtering */
void vp8_loop_filter_mbh_mmi(unsigned char *y_ptr, unsigned char *u_ptr,
                             unsigned char *v_ptr, int y_stride, int uv_stride,
                             loop_filter_info *lfi) {
  vp8_mbloop_filter_horizontal_edge_mmi(y_ptr, y_stride, lfi->mblim, lfi->lim,
                                        lfi->hev_thr, 2);

  if (u_ptr)
    vp8_mbloop_filter_horizontal_edge_mmi(u_ptr, uv_stride, lfi->mblim,
                                          lfi->lim, lfi->hev_thr, 1);

  if (v_ptr)
    vp8_mbloop_filter_horizontal_edge_mmi(v_ptr, uv_stride, lfi->mblim,
                                          lfi->lim, lfi->hev_thr, 1);
}

/* Vertical MB Filtering */
void vp8_loop_filter_mbv_mmi(unsigned char *y_ptr, unsigned char *u_ptr,
                             unsigned char *v_ptr, int y_stride, int uv_stride,
                             loop_filter_info *lfi) {
  vp8_mbloop_filter_vertical_edge_mmi(y_ptr, y_stride, lfi->mblim, lfi->lim,
                                      lfi->hev_thr, 2);

  if (u_ptr)
    vp8_mbloop_filter_vertical_edge_mmi(u_ptr, uv_stride, lfi->mblim, lfi->lim,
                                        lfi->hev_thr, 1);

  if (v_ptr)
    vp8_mbloop_filter_vertical_edge_mmi(v_ptr, uv_stride, lfi->mblim, lfi->lim,
                                        lfi->hev_thr, 1);
}

/* Horizontal B Filtering */
void vp8_loop_filter_bh_mmi(unsigned char *y_ptr, unsigned char *u_ptr,
                            unsigned char *v_ptr, int y_stride, int uv_stride,
                            loop_filter_info *lfi) {
  vp8_loop_filter_horizontal_edge_mmi(y_ptr + 4 * y_stride, y_stride, lfi->blim,
                                      lfi->lim, lfi->hev_thr, 2);
  vp8_loop_filter_horizontal_edge_mmi(y_ptr + 8 * y_stride, y_stride, lfi->blim,
                                      lfi->lim, lfi->hev_thr, 2);
  vp8_loop_filter_horizontal_edge_mmi(y_ptr + 12 * y_stride, y_stride,
                                      lfi->blim, lfi->lim, lfi->hev_thr, 2);

  if (u_ptr)
    vp8_loop_filter_horizontal_edge_mmi(u_ptr + 4 * uv_stride, uv_stride,
                                        lfi->blim, lfi->lim, lfi->hev_thr, 1);

  if (v_ptr)
    vp8_loop_filter_horizontal_edge_mmi(v_ptr + 4 * uv_stride, uv_stride,
                                        lfi->blim, lfi->lim, lfi->hev_thr, 1);
}

/* Vertical B Filtering */
void vp8_loop_filter_bv_mmi(unsigned char *y_ptr, unsigned char *u_ptr,
                            unsigned char *v_ptr, int y_stride, int uv_stride,
                            loop_filter_info *lfi) {
  vp8_loop_filter_vertical_edge_mmi(y_ptr + 4, y_stride, lfi->blim, lfi->lim,
                                    lfi->hev_thr, 2);
  vp8_loop_filter_vertical_edge_mmi(y_ptr + 8, y_stride, lfi->blim, lfi->lim,
                                    lfi->hev_thr, 2);
  vp8_loop_filter_vertical_edge_mmi(y_ptr + 12, y_stride, lfi->blim, lfi->lim,
                                    lfi->hev_thr, 2);

  if (u_ptr)
    vp8_loop_filter_vertical_edge_mmi(u_ptr + 4, uv_stride, lfi->blim, lfi->lim,
                                      lfi->hev_thr, 1);

  if (v_ptr)
    vp8_loop_filter_vertical_edge_mmi(v_ptr + 4, uv_stride, lfi->blim, lfi->lim,
                                      lfi->hev_thr, 1);
}

void vp8_loop_filter_bhs_mmi(unsigned char *y_ptr, int y_stride,
                             const unsigned char *blimit) {
  vp8_loop_filter_simple_horizontal_edge_mmi(y_ptr + 4 * y_stride, y_stride,
                                             blimit);
  vp8_loop_filter_simple_horizontal_edge_mmi(y_ptr + 8 * y_stride, y_stride,
                                             blimit);
  vp8_loop_filter_simple_horizontal_edge_mmi(y_ptr + 12 * y_stride, y_stride,
                                             blimit);
}

void vp8_loop_filter_bvs_mmi(unsigned char *y_ptr, int y_stride,
                             const unsigned char *blimit) {
  vp8_loop_filter_simple_vertical_edge_mmi(y_ptr + 4, y_stride, blimit);
  vp8_loop_filter_simple_vertical_edge_mmi(y_ptr + 8, y_stride, blimit);
  vp8_loop_filter_simple_vertical_edge_mmi(y_ptr + 12, y_stride, blimit);
}