Blame src/dsp/rescaler_mips32.c

Packit 9c6abc
// Copyright 2014 Google Inc. All Rights Reserved.
Packit 9c6abc
//
Packit 9c6abc
// Use of this source code is governed by a BSD-style license
Packit 9c6abc
// that can be found in the COPYING file in the root of the source
Packit 9c6abc
// tree. An additional intellectual property rights grant can be found
Packit 9c6abc
// in the file PATENTS. All contributing project authors may
Packit 9c6abc
// be found in the AUTHORS file in the root of the source tree.
Packit 9c6abc
// -----------------------------------------------------------------------------
Packit 9c6abc
//
Packit 9c6abc
// MIPS version of rescaling functions
Packit 9c6abc
//
Packit 9c6abc
// Author(s): Djordje Pesut (djordje.pesut@imgtec.com)
Packit 9c6abc
Packit 9c6abc
#include "src/dsp/dsp.h"
Packit 9c6abc
Packit 9c6abc
#if defined(WEBP_USE_MIPS32) && !defined(WEBP_REDUCE_SIZE)
Packit 9c6abc
Packit 9c6abc
#include <assert.h>
Packit 9c6abc
#include "src/utils/rescaler_utils.h"
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Row import
Packit 9c6abc
Packit 9c6abc
static void ImportRowShrink_MIPS32(WebPRescaler* const wrk,
Packit 9c6abc
                                   const uint8_t* src) {
Packit 9c6abc
  const int x_stride = wrk->num_channels;
Packit 9c6abc
  const int x_out_max = wrk->dst_width * wrk->num_channels;
Packit 9c6abc
  const int fx_scale = wrk->fx_scale;
Packit 9c6abc
  const int x_add = wrk->x_add;
Packit 9c6abc
  const int x_sub = wrk->x_sub;
Packit 9c6abc
  const int x_stride1 = x_stride << 2;
Packit 9c6abc
  int channel;
Packit 9c6abc
  assert(!wrk->x_expand);
Packit 9c6abc
  assert(!WebPRescalerInputDone(wrk));
Packit 9c6abc
Packit 9c6abc
  for (channel = 0; channel < x_stride; ++channel) {
Packit 9c6abc
    const uint8_t* src1 = src + channel;
Packit 9c6abc
    rescaler_t* frow = wrk->frow + channel;
Packit 9c6abc
    int temp1, temp2, temp3;
Packit 9c6abc
    int base, frac, sum;
Packit 9c6abc
    int accum, accum1;
Packit 9c6abc
    int loop_c = x_out_max - channel;
Packit 9c6abc
Packit 9c6abc
    __asm__ volatile (
Packit 9c6abc
      "li     %[temp1],   0x8000                    \n\t"
Packit 9c6abc
      "li     %[temp2],   0x10000                   \n\t"
Packit 9c6abc
      "li     %[sum],     0                         \n\t"
Packit 9c6abc
      "li     %[accum],   0                         \n\t"
Packit 9c6abc
    "1:                                             \n\t"
Packit 9c6abc
      "addu   %[accum],   %[accum],   %[x_add]      \n\t"
Packit 9c6abc
      "li     %[base],    0                         \n\t"
Packit 9c6abc
      "blez   %[accum],   3f                        \n\t"
Packit 9c6abc
    "2:                                             \n\t"
Packit 9c6abc
      "lbu    %[base],    0(%[src1])                \n\t"
Packit 9c6abc
      "subu   %[accum],   %[accum],   %[x_sub]      \n\t"
Packit 9c6abc
      "addu   %[src1],    %[src1],    %[x_stride]   \n\t"
Packit 9c6abc
      "addu   %[sum],     %[sum],     %[base]       \n\t"
Packit 9c6abc
      "bgtz   %[accum],   2b                        \n\t"
Packit 9c6abc
    "3:                                             \n\t"
Packit 9c6abc
      "negu   %[accum1],  %[accum]                  \n\t"
Packit 9c6abc
      "mul    %[frac],    %[base],    %[accum1]     \n\t"
Packit 9c6abc
      "mul    %[temp3],   %[sum],     %[x_sub]      \n\t"
Packit 9c6abc
      "subu   %[loop_c],  %[loop_c],  %[x_stride]   \n\t"
Packit 9c6abc
      "mult   %[temp1],   %[temp2]                  \n\t"
Packit 9c6abc
      "maddu  %[frac],    %[fx_scale]               \n\t"
Packit 9c6abc
      "mfhi   %[sum]                                \n\t"
Packit 9c6abc
      "subu   %[temp3],   %[temp3],   %[frac]       \n\t"
Packit 9c6abc
      "sw     %[temp3],   0(%[frow])                \n\t"
Packit 9c6abc
      "addu   %[frow],    %[frow],    %[x_stride1]  \n\t"
Packit 9c6abc
      "bgtz   %[loop_c],  1b                        \n\t"
Packit 9c6abc
      : [accum]"=&r"(accum), [src1]"+r"(src1), [temp3]"=&r"(temp3),
Packit 9c6abc
        [sum]"=&r"(sum), [base]"=&r"(base), [frac]"=&r"(frac),
Packit 9c6abc
        [frow]"+r"(frow), [accum1]"=&r"(accum1),
Packit 9c6abc
        [temp2]"=&r"(temp2), [temp1]"=&r"(temp1)
Packit 9c6abc
      : [x_stride]"r"(x_stride), [fx_scale]"r"(fx_scale),
Packit 9c6abc
        [x_sub]"r"(x_sub), [x_add]"r"(x_add),
Packit 9c6abc
        [loop_c]"r"(loop_c), [x_stride1]"r"(x_stride1)
Packit 9c6abc
      : "memory", "hi", "lo"
Packit 9c6abc
    );
Packit 9c6abc
    assert(accum == 0);
Packit 9c6abc
  }
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
static void ImportRowExpand_MIPS32(WebPRescaler* const wrk,
Packit 9c6abc
                                   const uint8_t* src) {
Packit 9c6abc
  const int x_stride = wrk->num_channels;
Packit 9c6abc
  const int x_out_max = wrk->dst_width * wrk->num_channels;
Packit 9c6abc
  const int x_add = wrk->x_add;
Packit 9c6abc
  const int x_sub = wrk->x_sub;
Packit 9c6abc
  const int src_width = wrk->src_width;
Packit 9c6abc
  const int x_stride1 = x_stride << 2;
Packit 9c6abc
  int channel;
Packit 9c6abc
  assert(wrk->x_expand);
Packit 9c6abc
  assert(!WebPRescalerInputDone(wrk));
Packit 9c6abc
Packit 9c6abc
  for (channel = 0; channel < x_stride; ++channel) {
Packit 9c6abc
    const uint8_t* src1 = src + channel;
Packit 9c6abc
    rescaler_t* frow = wrk->frow + channel;
Packit 9c6abc
    int temp1, temp2, temp3, temp4;
Packit 9c6abc
    int frac;
Packit 9c6abc
    int accum;
Packit 9c6abc
    int x_out = channel;
Packit 9c6abc
Packit 9c6abc
    __asm__ volatile (
Packit 9c6abc
      "addiu  %[temp3],   %[src_width], -1            \n\t"
Packit 9c6abc
      "lbu    %[temp2],   0(%[src1])                  \n\t"
Packit 9c6abc
      "addu   %[src1],    %[src1],      %[x_stride]   \n\t"
Packit 9c6abc
      "bgtz   %[temp3],   0f                          \n\t"
Packit 9c6abc
      "addiu  %[temp1],   %[temp2],     0             \n\t"
Packit 9c6abc
      "b      3f                                      \n\t"
Packit 9c6abc
    "0:                                               \n\t"
Packit 9c6abc
      "lbu    %[temp1],   0(%[src1])                  \n\t"
Packit 9c6abc
    "3:                                               \n\t"
Packit 9c6abc
      "addiu  %[accum],   %[x_add],     0             \n\t"
Packit 9c6abc
    "1:                                               \n\t"
Packit 9c6abc
      "subu   %[temp3],   %[temp2],     %[temp1]      \n\t"
Packit 9c6abc
      "mul    %[temp3],   %[temp3],     %[accum]      \n\t"
Packit 9c6abc
      "mul    %[temp4],   %[temp1],     %[x_add]      \n\t"
Packit 9c6abc
      "addu   %[temp3],   %[temp4],     %[temp3]      \n\t"
Packit 9c6abc
      "sw     %[temp3],   0(%[frow])                  \n\t"
Packit 9c6abc
      "addu   %[frow],    %[frow],      %[x_stride1]  \n\t"
Packit 9c6abc
      "addu   %[x_out],   %[x_out],     %[x_stride]   \n\t"
Packit 9c6abc
      "subu   %[temp3],   %[x_out],     %[x_out_max]  \n\t"
Packit 9c6abc
      "bgez   %[temp3],   2f                          \n\t"
Packit 9c6abc
      "subu   %[accum],   %[accum],     %[x_sub]      \n\t"
Packit 9c6abc
      "bgez   %[accum],   4f                          \n\t"
Packit 9c6abc
      "addiu  %[temp2],   %[temp1],     0             \n\t"
Packit 9c6abc
      "addu   %[src1],    %[src1],      %[x_stride]   \n\t"
Packit 9c6abc
      "lbu    %[temp1],   0(%[src1])                  \n\t"
Packit 9c6abc
      "addu   %[accum],   %[accum],     %[x_add]      \n\t"
Packit 9c6abc
    "4:                                               \n\t"
Packit 9c6abc
      "b      1b                                      \n\t"
Packit 9c6abc
    "2:                                               \n\t"
Packit 9c6abc
      : [src1]"+r"(src1), [accum]"=&r"(accum), [temp1]"=&r"(temp1),
Packit 9c6abc
        [temp2]"=&r"(temp2), [temp3]"=&r"(temp3), [temp4]"=&r"(temp4),
Packit 9c6abc
        [x_out]"+r"(x_out), [frac]"=&r"(frac), [frow]"+r"(frow)
Packit 9c6abc
      : [x_stride]"r"(x_stride), [x_add]"r"(x_add), [x_sub]"r"(x_sub),
Packit 9c6abc
        [x_stride1]"r"(x_stride1), [src_width]"r"(src_width),
Packit 9c6abc
        [x_out_max]"r"(x_out_max)
Packit 9c6abc
      : "memory", "hi", "lo"
Packit 9c6abc
    );
Packit 9c6abc
    assert(wrk->x_sub == 0 /* <- special case for src_width=1 */ || accum == 0);
Packit 9c6abc
  }
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Row export
Packit 9c6abc
Packit 9c6abc
static void ExportRowExpand_MIPS32(WebPRescaler* const wrk) {
Packit 9c6abc
  uint8_t* dst = wrk->dst;
Packit 9c6abc
  rescaler_t* irow = wrk->irow;
Packit 9c6abc
  const int x_out_max = wrk->dst_width * wrk->num_channels;
Packit 9c6abc
  const rescaler_t* frow = wrk->frow;
Packit 9c6abc
  int temp0, temp1, temp3, temp4, temp5, loop_end;
Packit 9c6abc
  const int temp2 = (int)wrk->fy_scale;
Packit 9c6abc
  const int temp6 = x_out_max << 2;
Packit 9c6abc
  assert(!WebPRescalerOutputDone(wrk));
Packit 9c6abc
  assert(wrk->y_accum <= 0);
Packit 9c6abc
  assert(wrk->y_expand);
Packit 9c6abc
  assert(wrk->y_sub != 0);
Packit 9c6abc
  if (wrk->y_accum == 0) {
Packit 9c6abc
    __asm__ volatile (
Packit 9c6abc
      "li       %[temp3],    0x10000                    \n\t"
Packit 9c6abc
      "li       %[temp4],    0x8000                     \n\t"
Packit 9c6abc
      "addu     %[loop_end], %[frow],     %[temp6]      \n\t"
Packit 9c6abc
    "1:                                                 \n\t"
Packit 9c6abc
      "lw       %[temp0],    0(%[frow])                 \n\t"
Packit 9c6abc
      "addiu    %[dst],      %[dst],      1             \n\t"
Packit 9c6abc
      "addiu    %[frow],     %[frow],     4             \n\t"
Packit 9c6abc
      "mult     %[temp3],    %[temp4]                   \n\t"
Packit 9c6abc
      "maddu    %[temp0],    %[temp2]                   \n\t"
Packit 9c6abc
      "mfhi     %[temp5]                                \n\t"
Packit 9c6abc
      "sb       %[temp5],    -1(%[dst])                 \n\t"
Packit 9c6abc
      "bne      %[frow],     %[loop_end], 1b            \n\t"
Packit 9c6abc
      : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp3]"=&r"(temp3),
Packit 9c6abc
        [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), [frow]"+r"(frow),
Packit 9c6abc
        [dst]"+r"(dst), [loop_end]"=&r"(loop_end)
Packit 9c6abc
      : [temp2]"r"(temp2), [temp6]"r"(temp6)
Packit 9c6abc
      : "memory", "hi", "lo"
Packit 9c6abc
    );
Packit 9c6abc
  } else {
Packit 9c6abc
    const uint32_t B = WEBP_RESCALER_FRAC(-wrk->y_accum, wrk->y_sub);
Packit 9c6abc
    const uint32_t A = (uint32_t)(WEBP_RESCALER_ONE - B);
Packit 9c6abc
    __asm__ volatile (
Packit 9c6abc
      "li       %[temp3],    0x10000                    \n\t"
Packit 9c6abc
      "li       %[temp4],    0x8000                     \n\t"
Packit 9c6abc
      "addu     %[loop_end], %[frow],     %[temp6]      \n\t"
Packit 9c6abc
    "1:                                                 \n\t"
Packit 9c6abc
      "lw       %[temp0],    0(%[frow])                 \n\t"
Packit 9c6abc
      "lw       %[temp1],    0(%[irow])                 \n\t"
Packit 9c6abc
      "addiu    %[dst],      %[dst],      1             \n\t"
Packit 9c6abc
      "mult     %[temp3],    %[temp4]                   \n\t"
Packit 9c6abc
      "maddu    %[A],        %[temp0]                   \n\t"
Packit 9c6abc
      "maddu    %[B],        %[temp1]                   \n\t"
Packit 9c6abc
      "addiu    %[frow],     %[frow],     4             \n\t"
Packit 9c6abc
      "addiu    %[irow],     %[irow],     4             \n\t"
Packit 9c6abc
      "mfhi     %[temp5]                                \n\t"
Packit 9c6abc
      "mult     %[temp3],    %[temp4]                   \n\t"
Packit 9c6abc
      "maddu    %[temp5],    %[temp2]                   \n\t"
Packit 9c6abc
      "mfhi     %[temp5]                                \n\t"
Packit 9c6abc
      "sb       %[temp5],    -1(%[dst])                 \n\t"
Packit 9c6abc
      "bne      %[frow],     %[loop_end], 1b            \n\t"
Packit 9c6abc
      : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp3]"=&r"(temp3),
Packit 9c6abc
        [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), [frow]"+r"(frow),
Packit 9c6abc
        [irow]"+r"(irow), [dst]"+r"(dst), [loop_end]"=&r"(loop_end)
Packit 9c6abc
      : [temp2]"r"(temp2), [temp6]"r"(temp6), [A]"r"(A), [B]"r"(B)
Packit 9c6abc
      : "memory", "hi", "lo"
Packit 9c6abc
    );
Packit 9c6abc
  }
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
static void ExportRowShrink_MIPS32(WebPRescaler* const wrk) {
Packit 9c6abc
  const int x_out_max = wrk->dst_width * wrk->num_channels;
Packit 9c6abc
  uint8_t* dst = wrk->dst;
Packit 9c6abc
  rescaler_t* irow = wrk->irow;
Packit 9c6abc
  const rescaler_t* frow = wrk->frow;
Packit 9c6abc
  const int yscale = wrk->fy_scale * (-wrk->y_accum);
Packit 9c6abc
  int temp0, temp1, temp3, temp4, temp5, loop_end;
Packit 9c6abc
  const int temp2 = (int)wrk->fxy_scale;
Packit 9c6abc
  const int temp6 = x_out_max << 2;
Packit 9c6abc
Packit 9c6abc
  assert(!WebPRescalerOutputDone(wrk));
Packit 9c6abc
  assert(wrk->y_accum <= 0);
Packit 9c6abc
  assert(!wrk->y_expand);
Packit 9c6abc
  assert(wrk->fxy_scale != 0);
Packit 9c6abc
  if (yscale) {
Packit 9c6abc
    __asm__ volatile (
Packit 9c6abc
      "li       %[temp3],    0x10000                    \n\t"
Packit 9c6abc
      "li       %[temp4],    0x8000                     \n\t"
Packit 9c6abc
      "addu     %[loop_end], %[frow],     %[temp6]      \n\t"
Packit 9c6abc
    "1:                                                 \n\t"
Packit 9c6abc
      "lw       %[temp0],    0(%[frow])                 \n\t"
Packit 9c6abc
      "mult     %[temp3],    %[temp4]                   \n\t"
Packit 9c6abc
      "addiu    %[frow],     %[frow],     4             \n\t"
Packit 9c6abc
      "maddu    %[temp0],    %[yscale]                  \n\t"
Packit 9c6abc
      "mfhi     %[temp1]                                \n\t"
Packit 9c6abc
      "lw       %[temp0],    0(%[irow])                 \n\t"
Packit 9c6abc
      "addiu    %[dst],      %[dst],      1             \n\t"
Packit 9c6abc
      "addiu    %[irow],     %[irow],     4             \n\t"
Packit 9c6abc
      "subu     %[temp0],    %[temp0],    %[temp1]      \n\t"
Packit 9c6abc
      "mult     %[temp3],    %[temp4]                   \n\t"
Packit 9c6abc
      "maddu    %[temp0],    %[temp2]                   \n\t"
Packit 9c6abc
      "mfhi     %[temp5]                                \n\t"
Packit 9c6abc
      "sw       %[temp1],    -4(%[irow])                \n\t"
Packit 9c6abc
      "sb       %[temp5],    -1(%[dst])                 \n\t"
Packit 9c6abc
      "bne      %[frow],     %[loop_end], 1b            \n\t"
Packit 9c6abc
      : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp3]"=&r"(temp3),
Packit 9c6abc
        [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), [frow]"+r"(frow),
Packit 9c6abc
        [irow]"+r"(irow), [dst]"+r"(dst), [loop_end]"=&r"(loop_end)
Packit 9c6abc
      : [temp2]"r"(temp2), [yscale]"r"(yscale), [temp6]"r"(temp6)
Packit 9c6abc
      : "memory", "hi", "lo"
Packit 9c6abc
    );
Packit 9c6abc
  } else {
Packit 9c6abc
    __asm__ volatile (
Packit 9c6abc
      "li       %[temp3],    0x10000                    \n\t"
Packit 9c6abc
      "li       %[temp4],    0x8000                     \n\t"
Packit 9c6abc
      "addu     %[loop_end], %[irow],     %[temp6]      \n\t"
Packit 9c6abc
    "1:                                                 \n\t"
Packit 9c6abc
      "lw       %[temp0],    0(%[irow])                 \n\t"
Packit 9c6abc
      "addiu    %[dst],      %[dst],      1             \n\t"
Packit 9c6abc
      "addiu    %[irow],     %[irow],     4             \n\t"
Packit 9c6abc
      "mult     %[temp3],    %[temp4]                   \n\t"
Packit 9c6abc
      "maddu    %[temp0],    %[temp2]                   \n\t"
Packit 9c6abc
      "mfhi     %[temp5]                                \n\t"
Packit 9c6abc
      "sw       $zero,       -4(%[irow])                \n\t"
Packit 9c6abc
      "sb       %[temp5],    -1(%[dst])                 \n\t"
Packit 9c6abc
      "bne      %[irow],     %[loop_end], 1b            \n\t"
Packit 9c6abc
      : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp3]"=&r"(temp3),
Packit 9c6abc
        [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), [irow]"+r"(irow),
Packit 9c6abc
        [dst]"+r"(dst), [loop_end]"=&r"(loop_end)
Packit 9c6abc
      : [temp2]"r"(temp2), [temp6]"r"(temp6)
Packit 9c6abc
      : "memory", "hi", "lo"
Packit 9c6abc
    );
Packit 9c6abc
  }
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Entry point
Packit 9c6abc
Packit 9c6abc
extern void WebPRescalerDspInitMIPS32(void);
Packit 9c6abc
Packit 9c6abc
WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInitMIPS32(void) {
Packit 9c6abc
  WebPRescalerImportRowExpand = ImportRowExpand_MIPS32;
Packit 9c6abc
  WebPRescalerImportRowShrink = ImportRowShrink_MIPS32;
Packit 9c6abc
  WebPRescalerExportRowExpand = ExportRowExpand_MIPS32;
Packit 9c6abc
  WebPRescalerExportRowShrink = ExportRowShrink_MIPS32;
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
#else  // !WEBP_USE_MIPS32
Packit 9c6abc
Packit 9c6abc
WEBP_DSP_INIT_STUB(WebPRescalerDspInitMIPS32)
Packit 9c6abc
Packit 9c6abc
#endif  // WEBP_USE_MIPS32