Blame src/dsp/alpha_processing_mips_dsp_r2.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
// Utilities for processing transparent channel.
Packit 9c6abc
//
Packit 9c6abc
// Author(s): Branimir Vasic (branimir.vasic@imgtec.com)
Packit 9c6abc
//            Djordje Pesut  (djordje.pesut@imgtec.com)
Packit 9c6abc
Packit 9c6abc
#include "src/dsp/dsp.h"
Packit 9c6abc
Packit 9c6abc
#if defined(WEBP_USE_MIPS_DSP_R2)
Packit 9c6abc
Packit 9c6abc
static int DispatchAlpha_MIPSdspR2(const uint8_t* alpha, int alpha_stride,
Packit 9c6abc
                                   int width, int height,
Packit 9c6abc
                                   uint8_t* dst, int dst_stride) {
Packit 9c6abc
  uint32_t alpha_mask = 0xffffffff;
Packit 9c6abc
  int i, j, temp0;
Packit 9c6abc
Packit 9c6abc
  for (j = 0; j < height; ++j) {
Packit 9c6abc
    uint8_t* pdst = dst;
Packit 9c6abc
    const uint8_t* palpha = alpha;
Packit 9c6abc
    for (i = 0; i < (width >> 2); ++i) {
Packit 9c6abc
      int temp1, temp2, temp3;
Packit 9c6abc
Packit 9c6abc
      __asm__ volatile (
Packit 9c6abc
        "ulw    %[temp0],      0(%[palpha])                \n\t"
Packit 9c6abc
        "addiu  %[palpha],     %[palpha],     4            \n\t"
Packit 9c6abc
        "addiu  %[pdst],       %[pdst],       16           \n\t"
Packit 9c6abc
        "srl    %[temp1],      %[temp0],      8            \n\t"
Packit 9c6abc
        "srl    %[temp2],      %[temp0],      16           \n\t"
Packit 9c6abc
        "srl    %[temp3],      %[temp0],      24           \n\t"
Packit 9c6abc
        "and    %[alpha_mask], %[alpha_mask], %[temp0]     \n\t"
Packit 9c6abc
        "sb     %[temp0],      -16(%[pdst])                \n\t"
Packit 9c6abc
        "sb     %[temp1],      -12(%[pdst])                \n\t"
Packit 9c6abc
        "sb     %[temp2],      -8(%[pdst])                 \n\t"
Packit 9c6abc
        "sb     %[temp3],      -4(%[pdst])                 \n\t"
Packit 9c6abc
        : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
Packit 9c6abc
          [temp3]"=&r"(temp3), [palpha]"+r"(palpha), [pdst]"+r"(pdst),
Packit 9c6abc
          [alpha_mask]"+r"(alpha_mask)
Packit 9c6abc
        :
Packit 9c6abc
        : "memory"
Packit 9c6abc
      );
Packit 9c6abc
    }
Packit 9c6abc
Packit 9c6abc
    for (i = 0; i < (width & 3); ++i) {
Packit 9c6abc
      __asm__ volatile (
Packit 9c6abc
        "lbu    %[temp0],      0(%[palpha])                \n\t"
Packit 9c6abc
        "addiu  %[palpha],     %[palpha],     1            \n\t"
Packit 9c6abc
        "sb     %[temp0],      0(%[pdst])                  \n\t"
Packit 9c6abc
        "and    %[alpha_mask], %[alpha_mask], %[temp0]     \n\t"
Packit 9c6abc
        "addiu  %[pdst],       %[pdst],       4            \n\t"
Packit 9c6abc
        : [temp0]"=&r"(temp0), [palpha]"+r"(palpha), [pdst]"+r"(pdst),
Packit 9c6abc
          [alpha_mask]"+r"(alpha_mask)
Packit 9c6abc
        :
Packit 9c6abc
        : "memory"
Packit 9c6abc
      );
Packit 9c6abc
    }
Packit 9c6abc
    alpha += alpha_stride;
Packit 9c6abc
    dst += dst_stride;
Packit 9c6abc
  }
Packit 9c6abc
Packit 9c6abc
  __asm__ volatile (
Packit 9c6abc
    "ext    %[temp0],      %[alpha_mask], 0, 16            \n\t"
Packit 9c6abc
    "srl    %[alpha_mask], %[alpha_mask], 16               \n\t"
Packit 9c6abc
    "and    %[alpha_mask], %[alpha_mask], %[temp0]         \n\t"
Packit 9c6abc
    "ext    %[temp0],      %[alpha_mask], 0, 8             \n\t"
Packit 9c6abc
    "srl    %[alpha_mask], %[alpha_mask], 8                \n\t"
Packit 9c6abc
    "and    %[alpha_mask], %[alpha_mask], %[temp0]         \n\t"
Packit 9c6abc
    : [temp0]"=&r"(temp0), [alpha_mask]"+r"(alpha_mask)
Packit 9c6abc
    :
Packit 9c6abc
  );
Packit 9c6abc
Packit 9c6abc
  return (alpha_mask != 0xff);
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
static void MultARGBRow_MIPSdspR2(uint32_t* const ptr, int width,
Packit 9c6abc
                                  int inverse) {
Packit 9c6abc
  int x;
Packit 9c6abc
  const uint32_t c_00ffffff = 0x00ffffffu;
Packit 9c6abc
  const uint32_t c_ff000000 = 0xff000000u;
Packit 9c6abc
  const uint32_t c_8000000  = 0x00800000u;
Packit 9c6abc
  const uint32_t c_8000080  = 0x00800080u;
Packit 9c6abc
  for (x = 0; x < width; ++x) {
Packit 9c6abc
    const uint32_t argb = ptr[x];
Packit 9c6abc
    if (argb < 0xff000000u) {      // alpha < 255
Packit 9c6abc
      if (argb <= 0x00ffffffu) {   // alpha == 0
Packit 9c6abc
        ptr[x] = 0;
Packit 9c6abc
      } else {
Packit 9c6abc
        int temp0, temp1, temp2, temp3, alpha;
Packit 9c6abc
        __asm__ volatile (
Packit 9c6abc
          "srl          %[alpha],   %[argb],       24                \n\t"
Packit 9c6abc
          "replv.qb     %[temp0],   %[alpha]                         \n\t"
Packit 9c6abc
          "and          %[temp0],   %[temp0],      %[c_00ffffff]     \n\t"
Packit 9c6abc
          "beqz         %[inverse], 0f                               \n\t"
Packit 9c6abc
          "divu         $zero,      %[c_ff000000], %[alpha]          \n\t"
Packit 9c6abc
          "mflo         %[temp0]                                     \n\t"
Packit 9c6abc
        "0:                                                          \n\t"
Packit 9c6abc
          "andi         %[temp1],   %[argb],       0xff              \n\t"
Packit 9c6abc
          "ext          %[temp2],   %[argb],       8,             8  \n\t"
Packit 9c6abc
          "ext          %[temp3],   %[argb],       16,            8  \n\t"
Packit 9c6abc
          "mul          %[temp1],   %[temp1],      %[temp0]          \n\t"
Packit 9c6abc
          "mul          %[temp2],   %[temp2],      %[temp0]          \n\t"
Packit 9c6abc
          "mul          %[temp3],   %[temp3],      %[temp0]          \n\t"
Packit 9c6abc
          "precrq.ph.w  %[temp1],   %[temp2],      %[temp1]          \n\t"
Packit 9c6abc
          "addu         %[temp3],   %[temp3],      %[c_8000000]      \n\t"
Packit 9c6abc
          "addu         %[temp1],   %[temp1],      %[c_8000080]      \n\t"
Packit 9c6abc
          "precrq.ph.w  %[temp3],   %[argb],       %[temp3]          \n\t"
Packit 9c6abc
          "precrq.qb.ph %[temp1],   %[temp3],      %[temp1]          \n\t"
Packit 9c6abc
          : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
Packit 9c6abc
            [temp3]"=&r"(temp3), [alpha]"=&r"(alpha)
Packit 9c6abc
          : [inverse]"r"(inverse), [c_00ffffff]"r"(c_00ffffff),
Packit 9c6abc
            [c_8000000]"r"(c_8000000), [c_8000080]"r"(c_8000080),
Packit 9c6abc
            [c_ff000000]"r"(c_ff000000), [argb]"r"(argb)
Packit 9c6abc
          : "memory", "hi", "lo"
Packit 9c6abc
        );
Packit 9c6abc
        ptr[x] = temp1;
Packit 9c6abc
      }
Packit 9c6abc
    }
Packit 9c6abc
  }
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
#ifdef WORDS_BIGENDIAN
Packit 9c6abc
static void PackARGB_MIPSdspR2(const uint8_t* a, const uint8_t* r,
Packit 9c6abc
                               const uint8_t* g, const uint8_t* b, int len,
Packit 9c6abc
                               uint32_t* out) {
Packit 9c6abc
  int temp0, temp1, temp2, temp3, offset;
Packit 9c6abc
  const int rest = len & 1;
Packit 9c6abc
  const uint32_t* const loop_end = out + len - rest;
Packit 9c6abc
  const int step = 4;
Packit 9c6abc
  __asm__ volatile (
Packit 9c6abc
    "xor          %[offset],   %[offset], %[offset]    \n\t"
Packit 9c6abc
    "beq          %[loop_end], %[out],    0f           \n\t"
Packit 9c6abc
  "2:                                                  \n\t"
Packit 9c6abc
    "lbux         %[temp0],    %[offset](%[a])         \n\t"
Packit 9c6abc
    "lbux         %[temp1],    %[offset](%[r])         \n\t"
Packit 9c6abc
    "lbux         %[temp2],    %[offset](%[g])         \n\t"
Packit 9c6abc
    "lbux         %[temp3],    %[offset](%[b])         \n\t"
Packit 9c6abc
    "ins          %[temp1],    %[temp0],  16,     16   \n\t"
Packit 9c6abc
    "ins          %[temp3],    %[temp2],  16,     16   \n\t"
Packit 9c6abc
    "addiu        %[out],      %[out],    4            \n\t"
Packit 9c6abc
    "precr.qb.ph  %[temp0],    %[temp1],  %[temp3]     \n\t"
Packit 9c6abc
    "sw           %[temp0],    -4(%[out])              \n\t"
Packit 9c6abc
    "addu         %[offset],   %[offset], %[step]      \n\t"
Packit 9c6abc
    "bne          %[loop_end], %[out],    2b           \n\t"
Packit 9c6abc
  "0:                                                  \n\t"
Packit 9c6abc
    "beq          %[rest],     $zero,     1f           \n\t"
Packit 9c6abc
    "lbux         %[temp0],    %[offset](%[a])         \n\t"
Packit 9c6abc
    "lbux         %[temp1],    %[offset](%[r])         \n\t"
Packit 9c6abc
    "lbux         %[temp2],    %[offset](%[g])         \n\t"
Packit 9c6abc
    "lbux         %[temp3],    %[offset](%[b])         \n\t"
Packit 9c6abc
    "ins          %[temp1],    %[temp0],  16,     16   \n\t"
Packit 9c6abc
    "ins          %[temp3],    %[temp2],  16,     16   \n\t"
Packit 9c6abc
    "precr.qb.ph  %[temp0],    %[temp1],  %[temp3]     \n\t"
Packit 9c6abc
    "sw           %[temp0],    0(%[out])               \n\t"
Packit 9c6abc
  "1:                                                  \n\t"
Packit 9c6abc
    : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
Packit 9c6abc
      [temp3]"=&r"(temp3), [offset]"=&r"(offset), [out]"+&r"(out)
Packit 9c6abc
    : [a]"r"(a), [r]"r"(r), [g]"r"(g), [b]"r"(b), [step]"r"(step),
Packit 9c6abc
      [loop_end]"r"(loop_end), [rest]"r"(rest)
Packit 9c6abc
    : "memory"
Packit 9c6abc
  );
Packit 9c6abc
}
Packit 9c6abc
#endif  // WORDS_BIGENDIAN
Packit 9c6abc
Packit 9c6abc
static void PackRGB_MIPSdspR2(const uint8_t* r, const uint8_t* g,
Packit 9c6abc
                              const uint8_t* b, int len, int step,
Packit 9c6abc
                              uint32_t* out) {
Packit 9c6abc
  int temp0, temp1, temp2, offset;
Packit 9c6abc
  const int rest = len & 1;
Packit 9c6abc
  const int a = 0xff;
Packit 9c6abc
  const uint32_t* const loop_end = out + len - rest;
Packit 9c6abc
  __asm__ volatile (
Packit 9c6abc
    "xor          %[offset],   %[offset], %[offset]    \n\t"
Packit 9c6abc
    "beq          %[loop_end], %[out],    0f           \n\t"
Packit 9c6abc
  "2:                                                  \n\t"
Packit 9c6abc
    "lbux         %[temp0],    %[offset](%[r])         \n\t"
Packit 9c6abc
    "lbux         %[temp1],    %[offset](%[g])         \n\t"
Packit 9c6abc
    "lbux         %[temp2],    %[offset](%[b])         \n\t"
Packit 9c6abc
    "ins          %[temp0],    %[a],      16,     16   \n\t"
Packit 9c6abc
    "ins          %[temp2],    %[temp1],  16,     16   \n\t"
Packit 9c6abc
    "addiu        %[out],      %[out],    4            \n\t"
Packit 9c6abc
    "precr.qb.ph  %[temp0],    %[temp0],  %[temp2]     \n\t"
Packit 9c6abc
    "sw           %[temp0],    -4(%[out])              \n\t"
Packit 9c6abc
    "addu         %[offset],   %[offset], %[step]      \n\t"
Packit 9c6abc
    "bne          %[loop_end], %[out],    2b           \n\t"
Packit 9c6abc
  "0:                                                  \n\t"
Packit 9c6abc
    "beq          %[rest],     $zero,     1f           \n\t"
Packit 9c6abc
    "lbux         %[temp0],    %[offset](%[r])         \n\t"
Packit 9c6abc
    "lbux         %[temp1],    %[offset](%[g])         \n\t"
Packit 9c6abc
    "lbux         %[temp2],    %[offset](%[b])         \n\t"
Packit 9c6abc
    "ins          %[temp0],    %[a],      16,     16   \n\t"
Packit 9c6abc
    "ins          %[temp2],    %[temp1],  16,     16   \n\t"
Packit 9c6abc
    "precr.qb.ph  %[temp0],    %[temp0],  %[temp2]     \n\t"
Packit 9c6abc
    "sw           %[temp0],    0(%[out])               \n\t"
Packit 9c6abc
  "1:                                                  \n\t"
Packit 9c6abc
    : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
Packit 9c6abc
      [offset]"=&r"(offset), [out]"+&r"(out)
Packit 9c6abc
    : [a]"r"(a), [r]"r"(r), [g]"r"(g), [b]"r"(b), [step]"r"(step),
Packit 9c6abc
      [loop_end]"r"(loop_end), [rest]"r"(rest)
Packit 9c6abc
    : "memory"
Packit 9c6abc
  );
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Entry point
Packit 9c6abc
Packit 9c6abc
extern void WebPInitAlphaProcessingMIPSdspR2(void);
Packit 9c6abc
Packit 9c6abc
WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessingMIPSdspR2(void) {
Packit 9c6abc
  WebPDispatchAlpha = DispatchAlpha_MIPSdspR2;
Packit 9c6abc
  WebPMultARGBRow = MultARGBRow_MIPSdspR2;
Packit 9c6abc
#ifdef WORDS_BIGENDIAN
Packit 9c6abc
  WebPPackARGB = PackARGB_MIPSdspR2;
Packit 9c6abc
#endif
Packit 9c6abc
  WebPPackRGB = PackRGB_MIPSdspR2;
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
#else  // !WEBP_USE_MIPS_DSP_R2
Packit 9c6abc
Packit 9c6abc
WEBP_DSP_INIT_STUB(WebPInitAlphaProcessingMIPSdspR2)
Packit 9c6abc
Packit 9c6abc
#endif  // WEBP_USE_MIPS_DSP_R2