Path: blob/master/thirdparty/libwebp/src/dsp/alpha_processing_mips_dsp_r2.c
9913 views
// Copyright 2014 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// Utilities for processing transparent channel.10//11// Author(s): Branimir Vasic ([email protected])12// Djordje Pesut ([email protected])1314#include "src/dsp/dsp.h"1516#if defined(WEBP_USE_MIPS_DSP_R2)1718static int DispatchAlpha_MIPSdspR2(const uint8_t* alpha, int alpha_stride,19int width, int height,20uint8_t* dst, int dst_stride) {21uint32_t alpha_mask = 0xffffffff;22int i, j, temp0;2324for (j = 0; j < height; ++j) {25uint8_t* pdst = dst;26const uint8_t* palpha = alpha;27for (i = 0; i < (width >> 2); ++i) {28int temp1, temp2, temp3;2930__asm__ volatile (31"ulw %[temp0], 0(%[palpha]) \n\t"32"addiu %[palpha], %[palpha], 4 \n\t"33"addiu %[pdst], %[pdst], 16 \n\t"34"srl %[temp1], %[temp0], 8 \n\t"35"srl %[temp2], %[temp0], 16 \n\t"36"srl %[temp3], %[temp0], 24 \n\t"37"and %[alpha_mask], %[alpha_mask], %[temp0] \n\t"38"sb %[temp0], -16(%[pdst]) \n\t"39"sb %[temp1], -12(%[pdst]) \n\t"40"sb %[temp2], -8(%[pdst]) \n\t"41"sb %[temp3], -4(%[pdst]) \n\t"42: [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),43[temp3]"=&r"(temp3), [palpha]"+r"(palpha), [pdst]"+r"(pdst),44[alpha_mask]"+r"(alpha_mask)45:46: "memory"47);48}4950for (i = 0; i < (width & 3); ++i) {51__asm__ volatile (52"lbu %[temp0], 0(%[palpha]) \n\t"53"addiu %[palpha], %[palpha], 1 \n\t"54"sb %[temp0], 0(%[pdst]) \n\t"55"and %[alpha_mask], %[alpha_mask], %[temp0] \n\t"56"addiu %[pdst], %[pdst], 4 \n\t"57: [temp0]"=&r"(temp0), [palpha]"+r"(palpha), [pdst]"+r"(pdst),58[alpha_mask]"+r"(alpha_mask)59:60: "memory"61);62}63alpha += alpha_stride;64dst += dst_stride;65}6667__asm__ volatile (68"ext %[temp0], %[alpha_mask], 0, 16 \n\t"69"srl %[alpha_mask], %[alpha_mask], 16 \n\t"70"and %[alpha_mask], %[alpha_mask], %[temp0] \n\t"71"ext %[temp0], %[alpha_mask], 0, 8 \n\t"72"srl %[alpha_mask], %[alpha_mask], 8 \n\t"73"and %[alpha_mask], %[alpha_mask], %[temp0] \n\t"74: [temp0]"=&r"(temp0), [alpha_mask]"+r"(alpha_mask)75:76);7778return (alpha_mask != 0xff);79}8081static void MultARGBRow_MIPSdspR2(uint32_t* const ptr, int width,82int inverse) {83int x;84const uint32_t c_00ffffff = 0x00ffffffu;85const uint32_t c_ff000000 = 0xff000000u;86const uint32_t c_8000000 = 0x00800000u;87const uint32_t c_8000080 = 0x00800080u;88for (x = 0; x < width; ++x) {89const uint32_t argb = ptr[x];90if (argb < 0xff000000u) { // alpha < 25591if (argb <= 0x00ffffffu) { // alpha == 092ptr[x] = 0;93} else {94int temp0, temp1, temp2, temp3, alpha;95__asm__ volatile (96"srl %[alpha], %[argb], 24 \n\t"97"replv.qb %[temp0], %[alpha] \n\t"98"and %[temp0], %[temp0], %[c_00ffffff] \n\t"99"beqz %[inverse], 0f \n\t"100"divu $zero, %[c_ff000000], %[alpha] \n\t"101"mflo %[temp0] \n\t"102"0: \n\t"103"andi %[temp1], %[argb], 0xff \n\t"104"ext %[temp2], %[argb], 8, 8 \n\t"105"ext %[temp3], %[argb], 16, 8 \n\t"106"mul %[temp1], %[temp1], %[temp0] \n\t"107"mul %[temp2], %[temp2], %[temp0] \n\t"108"mul %[temp3], %[temp3], %[temp0] \n\t"109"precrq.ph.w %[temp1], %[temp2], %[temp1] \n\t"110"addu %[temp3], %[temp3], %[c_8000000] \n\t"111"addu %[temp1], %[temp1], %[c_8000080] \n\t"112"precrq.ph.w %[temp3], %[argb], %[temp3] \n\t"113"precrq.qb.ph %[temp1], %[temp3], %[temp1] \n\t"114: [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),115[temp3]"=&r"(temp3), [alpha]"=&r"(alpha)116: [inverse]"r"(inverse), [c_00ffffff]"r"(c_00ffffff),117[c_8000000]"r"(c_8000000), [c_8000080]"r"(c_8000080),118[c_ff000000]"r"(c_ff000000), [argb]"r"(argb)119: "memory", "hi", "lo"120);121ptr[x] = temp1;122}123}124}125}126127#ifdef WORDS_BIGENDIAN128static void PackARGB_MIPSdspR2(const uint8_t* a, const uint8_t* r,129const uint8_t* g, const uint8_t* b, int len,130uint32_t* out) {131int temp0, temp1, temp2, temp3, offset;132const int rest = len & 1;133const uint32_t* const loop_end = out + len - rest;134const int step = 4;135__asm__ volatile (136"xor %[offset], %[offset], %[offset] \n\t"137"beq %[loop_end], %[out], 0f \n\t"138"2: \n\t"139"lbux %[temp0], %[offset](%[a]) \n\t"140"lbux %[temp1], %[offset](%[r]) \n\t"141"lbux %[temp2], %[offset](%[g]) \n\t"142"lbux %[temp3], %[offset](%[b]) \n\t"143"ins %[temp1], %[temp0], 16, 16 \n\t"144"ins %[temp3], %[temp2], 16, 16 \n\t"145"addiu %[out], %[out], 4 \n\t"146"precr.qb.ph %[temp0], %[temp1], %[temp3] \n\t"147"sw %[temp0], -4(%[out]) \n\t"148"addu %[offset], %[offset], %[step] \n\t"149"bne %[loop_end], %[out], 2b \n\t"150"0: \n\t"151"beq %[rest], $zero, 1f \n\t"152"lbux %[temp0], %[offset](%[a]) \n\t"153"lbux %[temp1], %[offset](%[r]) \n\t"154"lbux %[temp2], %[offset](%[g]) \n\t"155"lbux %[temp3], %[offset](%[b]) \n\t"156"ins %[temp1], %[temp0], 16, 16 \n\t"157"ins %[temp3], %[temp2], 16, 16 \n\t"158"precr.qb.ph %[temp0], %[temp1], %[temp3] \n\t"159"sw %[temp0], 0(%[out]) \n\t"160"1: \n\t"161: [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),162[temp3]"=&r"(temp3), [offset]"=&r"(offset), [out]"+&r"(out)163: [a]"r"(a), [r]"r"(r), [g]"r"(g), [b]"r"(b), [step]"r"(step),164[loop_end]"r"(loop_end), [rest]"r"(rest)165: "memory"166);167}168#endif // WORDS_BIGENDIAN169170static void PackRGB_MIPSdspR2(const uint8_t* r, const uint8_t* g,171const uint8_t* b, int len, int step,172uint32_t* out) {173int temp0, temp1, temp2, offset;174const int rest = len & 1;175const int a = 0xff;176const uint32_t* const loop_end = out + len - rest;177__asm__ volatile (178"xor %[offset], %[offset], %[offset] \n\t"179"beq %[loop_end], %[out], 0f \n\t"180"2: \n\t"181"lbux %[temp0], %[offset](%[r]) \n\t"182"lbux %[temp1], %[offset](%[g]) \n\t"183"lbux %[temp2], %[offset](%[b]) \n\t"184"ins %[temp0], %[a], 16, 16 \n\t"185"ins %[temp2], %[temp1], 16, 16 \n\t"186"addiu %[out], %[out], 4 \n\t"187"precr.qb.ph %[temp0], %[temp0], %[temp2] \n\t"188"sw %[temp0], -4(%[out]) \n\t"189"addu %[offset], %[offset], %[step] \n\t"190"bne %[loop_end], %[out], 2b \n\t"191"0: \n\t"192"beq %[rest], $zero, 1f \n\t"193"lbux %[temp0], %[offset](%[r]) \n\t"194"lbux %[temp1], %[offset](%[g]) \n\t"195"lbux %[temp2], %[offset](%[b]) \n\t"196"ins %[temp0], %[a], 16, 16 \n\t"197"ins %[temp2], %[temp1], 16, 16 \n\t"198"precr.qb.ph %[temp0], %[temp0], %[temp2] \n\t"199"sw %[temp0], 0(%[out]) \n\t"200"1: \n\t"201: [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),202[offset]"=&r"(offset), [out]"+&r"(out)203: [a]"r"(a), [r]"r"(r), [g]"r"(g), [b]"r"(b), [step]"r"(step),204[loop_end]"r"(loop_end), [rest]"r"(rest)205: "memory"206);207}208209//------------------------------------------------------------------------------210// Entry point211212extern void WebPInitAlphaProcessingMIPSdspR2(void);213214WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessingMIPSdspR2(void) {215WebPDispatchAlpha = DispatchAlpha_MIPSdspR2;216WebPMultARGBRow = MultARGBRow_MIPSdspR2;217#ifdef WORDS_BIGENDIAN218WebPPackARGB = PackARGB_MIPSdspR2;219#endif220WebPPackRGB = PackRGB_MIPSdspR2;221}222223#else // !WEBP_USE_MIPS_DSP_R2224225WEBP_DSP_INIT_STUB(WebPInitAlphaProcessingMIPSdspR2)226227#endif // WEBP_USE_MIPS_DSP_R2228229230