Path: blob/master/3rdparty/libwebp/src/dsp/lossless_mips_dsp_r2.c
16348 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// Image transforms and color space conversion methods for lossless decoder.10//11// Author(s): Djordje Pesut ([email protected])12// Jovan Zelincevic ([email protected])1314#include "src/dsp/dsp.h"1516#if defined(WEBP_USE_MIPS_DSP_R2)1718#include "src/dsp/lossless.h"19#include "src/dsp/lossless_common.h"2021#define MAP_COLOR_FUNCS(FUNC_NAME, TYPE, GET_INDEX, GET_VALUE) \22static void FUNC_NAME(const TYPE* src, \23const uint32_t* const color_map, \24TYPE* dst, int y_start, int y_end, \25int width) { \26int y; \27for (y = y_start; y < y_end; ++y) { \28int x; \29for (x = 0; x < (width >> 2); ++x) { \30int tmp1, tmp2, tmp3, tmp4; \31__asm__ volatile ( \32".ifc " #TYPE ", uint8_t \n\t" \33"lbu %[tmp1], 0(%[src]) \n\t" \34"lbu %[tmp2], 1(%[src]) \n\t" \35"lbu %[tmp3], 2(%[src]) \n\t" \36"lbu %[tmp4], 3(%[src]) \n\t" \37"addiu %[src], %[src], 4 \n\t" \38".endif \n\t" \39".ifc " #TYPE ", uint32_t \n\t" \40"lw %[tmp1], 0(%[src]) \n\t" \41"lw %[tmp2], 4(%[src]) \n\t" \42"lw %[tmp3], 8(%[src]) \n\t" \43"lw %[tmp4], 12(%[src]) \n\t" \44"ext %[tmp1], %[tmp1], 8, 8 \n\t" \45"ext %[tmp2], %[tmp2], 8, 8 \n\t" \46"ext %[tmp3], %[tmp3], 8, 8 \n\t" \47"ext %[tmp4], %[tmp4], 8, 8 \n\t" \48"addiu %[src], %[src], 16 \n\t" \49".endif \n\t" \50"sll %[tmp1], %[tmp1], 2 \n\t" \51"sll %[tmp2], %[tmp2], 2 \n\t" \52"sll %[tmp3], %[tmp3], 2 \n\t" \53"sll %[tmp4], %[tmp4], 2 \n\t" \54"lwx %[tmp1], %[tmp1](%[color_map]) \n\t" \55"lwx %[tmp2], %[tmp2](%[color_map]) \n\t" \56"lwx %[tmp3], %[tmp3](%[color_map]) \n\t" \57"lwx %[tmp4], %[tmp4](%[color_map]) \n\t" \58".ifc " #TYPE ", uint8_t \n\t" \59"ext %[tmp1], %[tmp1], 8, 8 \n\t" \60"ext %[tmp2], %[tmp2], 8, 8 \n\t" \61"ext %[tmp3], %[tmp3], 8, 8 \n\t" \62"ext %[tmp4], %[tmp4], 8, 8 \n\t" \63"sb %[tmp1], 0(%[dst]) \n\t" \64"sb %[tmp2], 1(%[dst]) \n\t" \65"sb %[tmp3], 2(%[dst]) \n\t" \66"sb %[tmp4], 3(%[dst]) \n\t" \67"addiu %[dst], %[dst], 4 \n\t" \68".endif \n\t" \69".ifc " #TYPE ", uint32_t \n\t" \70"sw %[tmp1], 0(%[dst]) \n\t" \71"sw %[tmp2], 4(%[dst]) \n\t" \72"sw %[tmp3], 8(%[dst]) \n\t" \73"sw %[tmp4], 12(%[dst]) \n\t" \74"addiu %[dst], %[dst], 16 \n\t" \75".endif \n\t" \76: [tmp1]"=&r"(tmp1), [tmp2]"=&r"(tmp2), [tmp3]"=&r"(tmp3), \77[tmp4]"=&r"(tmp4), [src]"+&r"(src), [dst]"+r"(dst) \78: [color_map]"r"(color_map) \79: "memory" \80); \81} \82for (x = 0; x < (width & 3); ++x) { \83*dst++ = GET_VALUE(color_map[GET_INDEX(*src++)]); \84} \85} \86}8788MAP_COLOR_FUNCS(MapARGB_MIPSdspR2, uint32_t, VP8GetARGBIndex, VP8GetARGBValue)89MAP_COLOR_FUNCS(MapAlpha_MIPSdspR2, uint8_t, VP8GetAlphaIndex, VP8GetAlphaValue)9091#undef MAP_COLOR_FUNCS9293static WEBP_INLINE uint32_t ClampedAddSubtractFull(uint32_t c0, uint32_t c1,94uint32_t c2) {95int temp0, temp1, temp2, temp3, temp4, temp5;96__asm__ volatile (97"preceu.ph.qbr %[temp1], %[c0] \n\t"98"preceu.ph.qbl %[temp2], %[c0] \n\t"99"preceu.ph.qbr %[temp3], %[c1] \n\t"100"preceu.ph.qbl %[temp4], %[c1] \n\t"101"preceu.ph.qbr %[temp5], %[c2] \n\t"102"preceu.ph.qbl %[temp0], %[c2] \n\t"103"subq.ph %[temp3], %[temp3], %[temp5] \n\t"104"subq.ph %[temp4], %[temp4], %[temp0] \n\t"105"addq.ph %[temp1], %[temp1], %[temp3] \n\t"106"addq.ph %[temp2], %[temp2], %[temp4] \n\t"107"shll_s.ph %[temp1], %[temp1], 7 \n\t"108"shll_s.ph %[temp2], %[temp2], 7 \n\t"109"precrqu_s.qb.ph %[temp2], %[temp2], %[temp1] \n\t"110: [temp0]"=r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),111[temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5)112: [c0]"r"(c0), [c1]"r"(c1), [c2]"r"(c2)113: "memory"114);115return temp2;116}117118static WEBP_INLINE uint32_t ClampedAddSubtractHalf(uint32_t c0, uint32_t c1,119uint32_t c2) {120int temp0, temp1, temp2, temp3, temp4, temp5;121__asm__ volatile (122"adduh.qb %[temp5], %[c0], %[c1] \n\t"123"preceu.ph.qbr %[temp3], %[c2] \n\t"124"preceu.ph.qbr %[temp1], %[temp5] \n\t"125"preceu.ph.qbl %[temp2], %[temp5] \n\t"126"preceu.ph.qbl %[temp4], %[c2] \n\t"127"subq.ph %[temp3], %[temp1], %[temp3] \n\t"128"subq.ph %[temp4], %[temp2], %[temp4] \n\t"129"shrl.ph %[temp5], %[temp3], 15 \n\t"130"shrl.ph %[temp0], %[temp4], 15 \n\t"131"addq.ph %[temp3], %[temp3], %[temp5] \n\t"132"addq.ph %[temp4], %[temp0], %[temp4] \n\t"133"shra.ph %[temp3], %[temp3], 1 \n\t"134"shra.ph %[temp4], %[temp4], 1 \n\t"135"addq.ph %[temp1], %[temp1], %[temp3] \n\t"136"addq.ph %[temp2], %[temp2], %[temp4] \n\t"137"shll_s.ph %[temp1], %[temp1], 7 \n\t"138"shll_s.ph %[temp2], %[temp2], 7 \n\t"139"precrqu_s.qb.ph %[temp1], %[temp2], %[temp1] \n\t"140: [temp0]"=r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),141[temp3]"=&r"(temp3), [temp4]"=r"(temp4), [temp5]"=&r"(temp5)142: [c0]"r"(c0), [c1]"r"(c1), [c2]"r"(c2)143: "memory"144);145return temp1;146}147148static WEBP_INLINE uint32_t Select(uint32_t a, uint32_t b, uint32_t c) {149int temp0, temp1, temp2, temp3, temp4, temp5;150__asm__ volatile (151"cmpgdu.lt.qb %[temp1], %[c], %[b] \n\t"152"pick.qb %[temp1], %[b], %[c] \n\t"153"pick.qb %[temp2], %[c], %[b] \n\t"154"cmpgdu.lt.qb %[temp4], %[c], %[a] \n\t"155"pick.qb %[temp4], %[a], %[c] \n\t"156"pick.qb %[temp5], %[c], %[a] \n\t"157"subu.qb %[temp3], %[temp1], %[temp2] \n\t"158"subu.qb %[temp0], %[temp4], %[temp5] \n\t"159"raddu.w.qb %[temp3], %[temp3] \n\t"160"raddu.w.qb %[temp0], %[temp0] \n\t"161"subu %[temp3], %[temp3], %[temp0] \n\t"162"slti %[temp0], %[temp3], 0x1 \n\t"163"movz %[a], %[b], %[temp0] \n\t"164: [temp1]"=&r"(temp1), [temp2]"=&r"(temp2), [temp3]"=&r"(temp3),165[temp4]"=&r"(temp4), [temp5]"=&r"(temp5), [temp0]"=&r"(temp0),166[a]"+&r"(a)167: [b]"r"(b), [c]"r"(c)168);169return a;170}171172static WEBP_INLINE uint32_t Average2(uint32_t a0, uint32_t a1) {173__asm__ volatile (174"adduh.qb %[a0], %[a0], %[a1] \n\t"175: [a0]"+r"(a0)176: [a1]"r"(a1)177);178return a0;179}180181static WEBP_INLINE uint32_t Average3(uint32_t a0, uint32_t a1, uint32_t a2) {182return Average2(Average2(a0, a2), a1);183}184185static WEBP_INLINE uint32_t Average4(uint32_t a0, uint32_t a1,186uint32_t a2, uint32_t a3) {187return Average2(Average2(a0, a1), Average2(a2, a3));188}189190static uint32_t Predictor5_MIPSdspR2(uint32_t left, const uint32_t* const top) {191return Average3(left, top[0], top[1]);192}193194static uint32_t Predictor6_MIPSdspR2(uint32_t left, const uint32_t* const top) {195return Average2(left, top[-1]);196}197198static uint32_t Predictor7_MIPSdspR2(uint32_t left, const uint32_t* const top) {199return Average2(left, top[0]);200}201202static uint32_t Predictor8_MIPSdspR2(uint32_t left, const uint32_t* const top) {203(void)left;204return Average2(top[-1], top[0]);205}206207static uint32_t Predictor9_MIPSdspR2(uint32_t left, const uint32_t* const top) {208(void)left;209return Average2(top[0], top[1]);210}211212static uint32_t Predictor10_MIPSdspR2(uint32_t left,213const uint32_t* const top) {214return Average4(left, top[-1], top[0], top[1]);215}216217static uint32_t Predictor11_MIPSdspR2(uint32_t left,218const uint32_t* const top) {219return Select(top[0], left, top[-1]);220}221222static uint32_t Predictor12_MIPSdspR2(uint32_t left,223const uint32_t* const top) {224return ClampedAddSubtractFull(left, top[0], top[-1]);225}226227static uint32_t Predictor13_MIPSdspR2(uint32_t left,228const uint32_t* const top) {229return ClampedAddSubtractHalf(left, top[0], top[-1]);230}231232// Add green to blue and red channels (i.e. perform the inverse transform of233// 'subtract green').234static void AddGreenToBlueAndRed_MIPSdspR2(const uint32_t* src, int num_pixels,235uint32_t* dst) {236uint32_t temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;237const uint32_t* const p_loop1_end = src + (num_pixels & ~3);238const uint32_t* const p_loop2_end = src + num_pixels;239__asm__ volatile (240".set push \n\t"241".set noreorder \n\t"242"beq %[src], %[p_loop1_end], 3f \n\t"243" nop \n\t"244"0: \n\t"245"lw %[temp0], 0(%[src]) \n\t"246"lw %[temp1], 4(%[src]) \n\t"247"lw %[temp2], 8(%[src]) \n\t"248"lw %[temp3], 12(%[src]) \n\t"249"ext %[temp4], %[temp0], 8, 8 \n\t"250"ext %[temp5], %[temp1], 8, 8 \n\t"251"ext %[temp6], %[temp2], 8, 8 \n\t"252"ext %[temp7], %[temp3], 8, 8 \n\t"253"addiu %[src], %[src], 16 \n\t"254"addiu %[dst], %[dst], 16 \n\t"255"replv.ph %[temp4], %[temp4] \n\t"256"replv.ph %[temp5], %[temp5] \n\t"257"replv.ph %[temp6], %[temp6] \n\t"258"replv.ph %[temp7], %[temp7] \n\t"259"addu.qb %[temp0], %[temp0], %[temp4] \n\t"260"addu.qb %[temp1], %[temp1], %[temp5] \n\t"261"addu.qb %[temp2], %[temp2], %[temp6] \n\t"262"addu.qb %[temp3], %[temp3], %[temp7] \n\t"263"sw %[temp0], -16(%[dst]) \n\t"264"sw %[temp1], -12(%[dst]) \n\t"265"sw %[temp2], -8(%[dst]) \n\t"266"bne %[src], %[p_loop1_end], 0b \n\t"267" sw %[temp3], -4(%[dst]) \n\t"268"3: \n\t"269"beq %[src], %[p_loop2_end], 2f \n\t"270" nop \n\t"271"1: \n\t"272"lw %[temp0], 0(%[src]) \n\t"273"addiu %[src], %[src], 4 \n\t"274"addiu %[dst], %[dst], 4 \n\t"275"ext %[temp4], %[temp0], 8, 8 \n\t"276"replv.ph %[temp4], %[temp4] \n\t"277"addu.qb %[temp0], %[temp0], %[temp4] \n\t"278"bne %[src], %[p_loop2_end], 1b \n\t"279" sw %[temp0], -4(%[dst]) \n\t"280"2: \n\t"281".set pop \n\t"282: [dst]"+&r"(dst), [src]"+&r"(src), [temp0]"=&r"(temp0),283[temp1]"=&r"(temp1), [temp2]"=&r"(temp2), [temp3]"=&r"(temp3),284[temp4]"=&r"(temp4), [temp5]"=&r"(temp5), [temp6]"=&r"(temp6),285[temp7]"=&r"(temp7)286: [p_loop1_end]"r"(p_loop1_end), [p_loop2_end]"r"(p_loop2_end)287: "memory"288);289}290291static void TransformColorInverse_MIPSdspR2(const VP8LMultipliers* const m,292const uint32_t* src, int num_pixels,293uint32_t* dst) {294int temp0, temp1, temp2, temp3, temp4, temp5;295uint32_t argb, argb1, new_red;296const uint32_t G_to_R = m->green_to_red_;297const uint32_t G_to_B = m->green_to_blue_;298const uint32_t R_to_B = m->red_to_blue_;299const uint32_t* const p_loop_end = src + (num_pixels & ~1);300__asm__ volatile (301".set push \n\t"302".set noreorder \n\t"303"beq %[src], %[p_loop_end], 1f \n\t"304" nop \n\t"305"replv.ph %[temp0], %[G_to_R] \n\t"306"replv.ph %[temp1], %[G_to_B] \n\t"307"replv.ph %[temp2], %[R_to_B] \n\t"308"shll.ph %[temp0], %[temp0], 8 \n\t"309"shll.ph %[temp1], %[temp1], 8 \n\t"310"shll.ph %[temp2], %[temp2], 8 \n\t"311"shra.ph %[temp0], %[temp0], 8 \n\t"312"shra.ph %[temp1], %[temp1], 8 \n\t"313"shra.ph %[temp2], %[temp2], 8 \n\t"314"0: \n\t"315"lw %[argb], 0(%[src]) \n\t"316"lw %[argb1], 4(%[src]) \n\t"317"sw %[argb], 0(%[dst]) \n\t"318"sw %[argb1], 4(%[dst]) \n\t"319"addiu %[src], %[src], 8 \n\t"320"addiu %[dst], %[dst], 8 \n\t"321"precrq.qb.ph %[temp3], %[argb], %[argb1] \n\t"322"preceu.ph.qbra %[temp3], %[temp3] \n\t"323"shll.ph %[temp3], %[temp3], 8 \n\t"324"shra.ph %[temp3], %[temp3], 8 \n\t"325"mul.ph %[temp5], %[temp3], %[temp0] \n\t"326"mul.ph %[temp3], %[temp3], %[temp1] \n\t"327"precrq.ph.w %[new_red], %[argb], %[argb1] \n\t"328"ins %[argb1], %[argb], 16, 16 \n\t"329"shra.ph %[temp5], %[temp5], 5 \n\t"330"shra.ph %[temp3], %[temp3], 5 \n\t"331"addu.ph %[new_red], %[new_red], %[temp5] \n\t"332"addu.ph %[argb1], %[argb1], %[temp3] \n\t"333"preceu.ph.qbra %[temp5], %[new_red] \n\t"334"shll.ph %[temp4], %[temp5], 8 \n\t"335"shra.ph %[temp4], %[temp4], 8 \n\t"336"mul.ph %[temp4], %[temp4], %[temp2] \n\t"337"sb %[temp5], -2(%[dst]) \n\t"338"sra %[temp5], %[temp5], 16 \n\t"339"shra.ph %[temp4], %[temp4], 5 \n\t"340"addu.ph %[argb1], %[argb1], %[temp4] \n\t"341"preceu.ph.qbra %[temp3], %[argb1] \n\t"342"sb %[temp5], -6(%[dst]) \n\t"343"sb %[temp3], -4(%[dst]) \n\t"344"sra %[temp3], %[temp3], 16 \n\t"345"bne %[src], %[p_loop_end], 0b \n\t"346" sb %[temp3], -8(%[dst]) \n\t"347"1: \n\t"348".set pop \n\t"349: [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),350[temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),351[new_red]"=&r"(new_red), [argb]"=&r"(argb),352[argb1]"=&r"(argb1), [dst]"+&r"(dst), [src]"+&r"(src)353: [G_to_R]"r"(G_to_R), [R_to_B]"r"(R_to_B),354[G_to_B]"r"(G_to_B), [p_loop_end]"r"(p_loop_end)355: "memory", "hi", "lo"356);357358// Fall-back to C-version for left-overs.359if (num_pixels & 1) VP8LTransformColorInverse_C(m, src, 1, dst);360}361362static void ConvertBGRAToRGB_MIPSdspR2(const uint32_t* src,363int num_pixels, uint8_t* dst) {364int temp0, temp1, temp2, temp3;365const uint32_t* const p_loop1_end = src + (num_pixels & ~3);366const uint32_t* const p_loop2_end = src + num_pixels;367__asm__ volatile (368".set push \n\t"369".set noreorder \n\t"370"beq %[src], %[p_loop1_end], 3f \n\t"371" nop \n\t"372"0: \n\t"373"lw %[temp3], 12(%[src]) \n\t"374"lw %[temp2], 8(%[src]) \n\t"375"lw %[temp1], 4(%[src]) \n\t"376"lw %[temp0], 0(%[src]) \n\t"377"ins %[temp3], %[temp2], 24, 8 \n\t"378"sll %[temp2], %[temp2], 8 \n\t"379"rotr %[temp3], %[temp3], 16 \n\t"380"ins %[temp2], %[temp1], 0, 16 \n\t"381"sll %[temp1], %[temp1], 8 \n\t"382"wsbh %[temp3], %[temp3] \n\t"383"balign %[temp0], %[temp1], 1 \n\t"384"wsbh %[temp2], %[temp2] \n\t"385"wsbh %[temp0], %[temp0] \n\t"386"usw %[temp3], 8(%[dst]) \n\t"387"rotr %[temp0], %[temp0], 16 \n\t"388"usw %[temp2], 4(%[dst]) \n\t"389"addiu %[src], %[src], 16 \n\t"390"usw %[temp0], 0(%[dst]) \n\t"391"bne %[src], %[p_loop1_end], 0b \n\t"392" addiu %[dst], %[dst], 12 \n\t"393"3: \n\t"394"beq %[src], %[p_loop2_end], 2f \n\t"395" nop \n\t"396"1: \n\t"397"lw %[temp0], 0(%[src]) \n\t"398"addiu %[src], %[src], 4 \n\t"399"wsbh %[temp1], %[temp0] \n\t"400"addiu %[dst], %[dst], 3 \n\t"401"ush %[temp1], -2(%[dst]) \n\t"402"sra %[temp0], %[temp0], 16 \n\t"403"bne %[src], %[p_loop2_end], 1b \n\t"404" sb %[temp0], -3(%[dst]) \n\t"405"2: \n\t"406".set pop \n\t"407: [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),408[temp3]"=&r"(temp3), [dst]"+&r"(dst), [src]"+&r"(src)409: [p_loop1_end]"r"(p_loop1_end), [p_loop2_end]"r"(p_loop2_end)410: "memory"411);412}413414static void ConvertBGRAToRGBA_MIPSdspR2(const uint32_t* src,415int num_pixels, uint8_t* dst) {416int temp0, temp1, temp2, temp3;417const uint32_t* const p_loop1_end = src + (num_pixels & ~3);418const uint32_t* const p_loop2_end = src + num_pixels;419__asm__ volatile (420".set push \n\t"421".set noreorder \n\t"422"beq %[src], %[p_loop1_end], 3f \n\t"423" nop \n\t"424"0: \n\t"425"lw %[temp0], 0(%[src]) \n\t"426"lw %[temp1], 4(%[src]) \n\t"427"lw %[temp2], 8(%[src]) \n\t"428"lw %[temp3], 12(%[src]) \n\t"429"wsbh %[temp0], %[temp0] \n\t"430"wsbh %[temp1], %[temp1] \n\t"431"wsbh %[temp2], %[temp2] \n\t"432"wsbh %[temp3], %[temp3] \n\t"433"addiu %[src], %[src], 16 \n\t"434"balign %[temp0], %[temp0], 1 \n\t"435"balign %[temp1], %[temp1], 1 \n\t"436"balign %[temp2], %[temp2], 1 \n\t"437"balign %[temp3], %[temp3], 1 \n\t"438"usw %[temp0], 0(%[dst]) \n\t"439"usw %[temp1], 4(%[dst]) \n\t"440"usw %[temp2], 8(%[dst]) \n\t"441"usw %[temp3], 12(%[dst]) \n\t"442"bne %[src], %[p_loop1_end], 0b \n\t"443" addiu %[dst], %[dst], 16 \n\t"444"3: \n\t"445"beq %[src], %[p_loop2_end], 2f \n\t"446" nop \n\t"447"1: \n\t"448"lw %[temp0], 0(%[src]) \n\t"449"wsbh %[temp0], %[temp0] \n\t"450"addiu %[src], %[src], 4 \n\t"451"balign %[temp0], %[temp0], 1 \n\t"452"usw %[temp0], 0(%[dst]) \n\t"453"bne %[src], %[p_loop2_end], 1b \n\t"454" addiu %[dst], %[dst], 4 \n\t"455"2: \n\t"456".set pop \n\t"457: [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),458[temp3]"=&r"(temp3), [dst]"+&r"(dst), [src]"+&r"(src)459: [p_loop1_end]"r"(p_loop1_end), [p_loop2_end]"r"(p_loop2_end)460: "memory"461);462}463464static void ConvertBGRAToRGBA4444_MIPSdspR2(const uint32_t* src,465int num_pixels, uint8_t* dst) {466int temp0, temp1, temp2, temp3, temp4, temp5;467const uint32_t* const p_loop1_end = src + (num_pixels & ~3);468const uint32_t* const p_loop2_end = src + num_pixels;469__asm__ volatile (470".set push \n\t"471".set noreorder \n\t"472"beq %[src], %[p_loop1_end], 3f \n\t"473" nop \n\t"474"0: \n\t"475"lw %[temp0], 0(%[src]) \n\t"476"lw %[temp1], 4(%[src]) \n\t"477"lw %[temp2], 8(%[src]) \n\t"478"lw %[temp3], 12(%[src]) \n\t"479"ext %[temp4], %[temp0], 28, 4 \n\t"480"ext %[temp5], %[temp0], 12, 4 \n\t"481"ins %[temp0], %[temp4], 0, 4 \n\t"482"ext %[temp4], %[temp1], 28, 4 \n\t"483"ins %[temp0], %[temp5], 16, 4 \n\t"484"ext %[temp5], %[temp1], 12, 4 \n\t"485"ins %[temp1], %[temp4], 0, 4 \n\t"486"ext %[temp4], %[temp2], 28, 4 \n\t"487"ins %[temp1], %[temp5], 16, 4 \n\t"488"ext %[temp5], %[temp2], 12, 4 \n\t"489"ins %[temp2], %[temp4], 0, 4 \n\t"490"ext %[temp4], %[temp3], 28, 4 \n\t"491"ins %[temp2], %[temp5], 16, 4 \n\t"492"ext %[temp5], %[temp3], 12, 4 \n\t"493"ins %[temp3], %[temp4], 0, 4 \n\t"494"precr.qb.ph %[temp1], %[temp1], %[temp0] \n\t"495"ins %[temp3], %[temp5], 16, 4 \n\t"496"addiu %[src], %[src], 16 \n\t"497"precr.qb.ph %[temp3], %[temp3], %[temp2] \n\t"498#if (WEBP_SWAP_16BIT_CSP == 1)499"usw %[temp1], 0(%[dst]) \n\t"500"usw %[temp3], 4(%[dst]) \n\t"501#else502"wsbh %[temp1], %[temp1] \n\t"503"wsbh %[temp3], %[temp3] \n\t"504"usw %[temp1], 0(%[dst]) \n\t"505"usw %[temp3], 4(%[dst]) \n\t"506#endif507"bne %[src], %[p_loop1_end], 0b \n\t"508" addiu %[dst], %[dst], 8 \n\t"509"3: \n\t"510"beq %[src], %[p_loop2_end], 2f \n\t"511" nop \n\t"512"1: \n\t"513"lw %[temp0], 0(%[src]) \n\t"514"ext %[temp4], %[temp0], 28, 4 \n\t"515"ext %[temp5], %[temp0], 12, 4 \n\t"516"ins %[temp0], %[temp4], 0, 4 \n\t"517"ins %[temp0], %[temp5], 16, 4 \n\t"518"addiu %[src], %[src], 4 \n\t"519"precr.qb.ph %[temp0], %[temp0], %[temp0] \n\t"520#if (WEBP_SWAP_16BIT_CSP == 1)521"ush %[temp0], 0(%[dst]) \n\t"522#else523"wsbh %[temp0], %[temp0] \n\t"524"ush %[temp0], 0(%[dst]) \n\t"525#endif526"bne %[src], %[p_loop2_end], 1b \n\t"527" addiu %[dst], %[dst], 2 \n\t"528"2: \n\t"529".set pop \n\t"530: [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),531[temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),532[dst]"+&r"(dst), [src]"+&r"(src)533: [p_loop1_end]"r"(p_loop1_end), [p_loop2_end]"r"(p_loop2_end)534: "memory"535);536}537538static void ConvertBGRAToRGB565_MIPSdspR2(const uint32_t* src,539int num_pixels, uint8_t* dst) {540int temp0, temp1, temp2, temp3, temp4, temp5;541const uint32_t* const p_loop1_end = src + (num_pixels & ~3);542const uint32_t* const p_loop2_end = src + num_pixels;543__asm__ volatile (544".set push \n\t"545".set noreorder \n\t"546"beq %[src], %[p_loop1_end], 3f \n\t"547" nop \n\t"548"0: \n\t"549"lw %[temp0], 0(%[src]) \n\t"550"lw %[temp1], 4(%[src]) \n\t"551"lw %[temp2], 8(%[src]) \n\t"552"lw %[temp3], 12(%[src]) \n\t"553"ext %[temp4], %[temp0], 8, 16 \n\t"554"ext %[temp5], %[temp0], 5, 11 \n\t"555"ext %[temp0], %[temp0], 3, 5 \n\t"556"ins %[temp4], %[temp5], 0, 11 \n\t"557"ext %[temp5], %[temp1], 5, 11 \n\t"558"ins %[temp4], %[temp0], 0, 5 \n\t"559"ext %[temp0], %[temp1], 8, 16 \n\t"560"ext %[temp1], %[temp1], 3, 5 \n\t"561"ins %[temp0], %[temp5], 0, 11 \n\t"562"ext %[temp5], %[temp2], 5, 11 \n\t"563"ins %[temp0], %[temp1], 0, 5 \n\t"564"ext %[temp1], %[temp2], 8, 16 \n\t"565"ext %[temp2], %[temp2], 3, 5 \n\t"566"ins %[temp1], %[temp5], 0, 11 \n\t"567"ext %[temp5], %[temp3], 5, 11 \n\t"568"ins %[temp1], %[temp2], 0, 5 \n\t"569"ext %[temp2], %[temp3], 8, 16 \n\t"570"ext %[temp3], %[temp3], 3, 5 \n\t"571"ins %[temp2], %[temp5], 0, 11 \n\t"572"append %[temp0], %[temp4], 16 \n\t"573"ins %[temp2], %[temp3], 0, 5 \n\t"574"addiu %[src], %[src], 16 \n\t"575"append %[temp2], %[temp1], 16 \n\t"576#if (WEBP_SWAP_16BIT_CSP == 1)577"usw %[temp0], 0(%[dst]) \n\t"578"usw %[temp2], 4(%[dst]) \n\t"579#else580"wsbh %[temp0], %[temp0] \n\t"581"wsbh %[temp2], %[temp2] \n\t"582"usw %[temp0], 0(%[dst]) \n\t"583"usw %[temp2], 4(%[dst]) \n\t"584#endif585"bne %[src], %[p_loop1_end], 0b \n\t"586" addiu %[dst], %[dst], 8 \n\t"587"3: \n\t"588"beq %[src], %[p_loop2_end], 2f \n\t"589" nop \n\t"590"1: \n\t"591"lw %[temp0], 0(%[src]) \n\t"592"ext %[temp4], %[temp0], 8, 16 \n\t"593"ext %[temp5], %[temp0], 5, 11 \n\t"594"ext %[temp0], %[temp0], 3, 5 \n\t"595"ins %[temp4], %[temp5], 0, 11 \n\t"596"addiu %[src], %[src], 4 \n\t"597"ins %[temp4], %[temp0], 0, 5 \n\t"598#if (WEBP_SWAP_16BIT_CSP == 1)599"ush %[temp4], 0(%[dst]) \n\t"600#else601"wsbh %[temp4], %[temp4] \n\t"602"ush %[temp4], 0(%[dst]) \n\t"603#endif604"bne %[src], %[p_loop2_end], 1b \n\t"605" addiu %[dst], %[dst], 2 \n\t"606"2: \n\t"607".set pop \n\t"608: [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),609[temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5),610[dst]"+&r"(dst), [src]"+&r"(src)611: [p_loop1_end]"r"(p_loop1_end), [p_loop2_end]"r"(p_loop2_end)612: "memory"613);614}615616static void ConvertBGRAToBGR_MIPSdspR2(const uint32_t* src,617int num_pixels, uint8_t* dst) {618int temp0, temp1, temp2, temp3;619const uint32_t* const p_loop1_end = src + (num_pixels & ~3);620const uint32_t* const p_loop2_end = src + num_pixels;621__asm__ volatile (622".set push \n\t"623".set noreorder \n\t"624"beq %[src], %[p_loop1_end], 3f \n\t"625" nop \n\t"626"0: \n\t"627"lw %[temp0], 0(%[src]) \n\t"628"lw %[temp1], 4(%[src]) \n\t"629"lw %[temp2], 8(%[src]) \n\t"630"lw %[temp3], 12(%[src]) \n\t"631"ins %[temp0], %[temp1], 24, 8 \n\t"632"sra %[temp1], %[temp1], 8 \n\t"633"ins %[temp1], %[temp2], 16, 16 \n\t"634"sll %[temp2], %[temp2], 8 \n\t"635"balign %[temp3], %[temp2], 1 \n\t"636"addiu %[src], %[src], 16 \n\t"637"usw %[temp0], 0(%[dst]) \n\t"638"usw %[temp1], 4(%[dst]) \n\t"639"usw %[temp3], 8(%[dst]) \n\t"640"bne %[src], %[p_loop1_end], 0b \n\t"641" addiu %[dst], %[dst], 12 \n\t"642"3: \n\t"643"beq %[src], %[p_loop2_end], 2f \n\t"644" nop \n\t"645"1: \n\t"646"lw %[temp0], 0(%[src]) \n\t"647"addiu %[src], %[src], 4 \n\t"648"addiu %[dst], %[dst], 3 \n\t"649"ush %[temp0], -3(%[dst]) \n\t"650"sra %[temp0], %[temp0], 16 \n\t"651"bne %[src], %[p_loop2_end], 1b \n\t"652" sb %[temp0], -1(%[dst]) \n\t"653"2: \n\t"654".set pop \n\t"655: [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),656[temp3]"=&r"(temp3), [dst]"+&r"(dst), [src]"+&r"(src)657: [p_loop1_end]"r"(p_loop1_end), [p_loop2_end]"r"(p_loop2_end)658: "memory"659);660}661662//------------------------------------------------------------------------------663// Entry point664665extern void VP8LDspInitMIPSdspR2(void);666667WEBP_TSAN_IGNORE_FUNCTION void VP8LDspInitMIPSdspR2(void) {668VP8LMapColor32b = MapARGB_MIPSdspR2;669VP8LMapColor8b = MapAlpha_MIPSdspR2;670671VP8LPredictors[5] = Predictor5_MIPSdspR2;672VP8LPredictors[6] = Predictor6_MIPSdspR2;673VP8LPredictors[7] = Predictor7_MIPSdspR2;674VP8LPredictors[8] = Predictor8_MIPSdspR2;675VP8LPredictors[9] = Predictor9_MIPSdspR2;676VP8LPredictors[10] = Predictor10_MIPSdspR2;677VP8LPredictors[11] = Predictor11_MIPSdspR2;678VP8LPredictors[12] = Predictor12_MIPSdspR2;679VP8LPredictors[13] = Predictor13_MIPSdspR2;680681VP8LAddGreenToBlueAndRed = AddGreenToBlueAndRed_MIPSdspR2;682VP8LTransformColorInverse = TransformColorInverse_MIPSdspR2;683684VP8LConvertBGRAToRGB = ConvertBGRAToRGB_MIPSdspR2;685VP8LConvertBGRAToRGBA = ConvertBGRAToRGBA_MIPSdspR2;686VP8LConvertBGRAToRGBA4444 = ConvertBGRAToRGBA4444_MIPSdspR2;687VP8LConvertBGRAToRGB565 = ConvertBGRAToRGB565_MIPSdspR2;688VP8LConvertBGRAToBGR = ConvertBGRAToBGR_MIPSdspR2;689}690691#else // !WEBP_USE_MIPS_DSP_R2692693WEBP_DSP_INIT_STUB(VP8LDspInitMIPSdspR2)694695#endif // WEBP_USE_MIPS_DSP_R2696697698