Path: blob/master/thirdparty/libwebp/src/dsp/cost_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// Author: Djordje Pesut ([email protected])1011#include "src/dsp/dsp.h"1213#if defined(WEBP_USE_MIPS_DSP_R2)1415#include "src/enc/cost_enc.h"1617static int GetResidualCost_MIPSdspR2(int ctx0, const VP8Residual* const res) {18int temp0, temp1;19int v_reg, ctx_reg;20int n = res->first;21// should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 122int p0 = res->prob[n][ctx0][0];23CostArrayPtr const costs = res->costs;24const uint16_t* t = costs[n][ctx0];25// bit_cost(1, p0) is already incorporated in t[] tables, but only if ctx != 026// (as required by the syntax). For ctx0 == 0, we need to add it here or it'll27// be missing during the loop.28int cost = (ctx0 == 0) ? VP8BitCost(1, p0) : 0;29const int16_t* res_coeffs = res->coeffs;30const int res_last = res->last;31const int const_max_level = MAX_VARIABLE_LEVEL;32const int const_2 = 2;33const uint16_t** p_costs = &costs[n][0];34const size_t inc_p_costs = NUM_CTX * sizeof(*p_costs);3536if (res->last < 0) {37return VP8BitCost(0, p0);38}3940__asm__ volatile (41".set push \n\t"42".set noreorder \n\t"43"subu %[temp1], %[res_last], %[n] \n\t"44"blez %[temp1], 2f \n\t"45" nop \n\t"46"1: \n\t"47"sll %[temp0], %[n], 1 \n\t"48"lhx %[v_reg], %[temp0](%[res_coeffs]) \n\t"49"addiu %[n], %[n], 1 \n\t"50"absq_s.w %[v_reg], %[v_reg] \n\t"51"sltiu %[temp0], %[v_reg], 2 \n\t"52"move %[ctx_reg], %[v_reg] \n\t"53"movz %[ctx_reg], %[const_2], %[temp0] \n\t"54"sll %[temp1], %[v_reg], 1 \n\t"55"lhx %[temp1], %[temp1](%[VP8LevelFixedCosts]) \n\t"56"slt %[temp0], %[v_reg], %[const_max_level] \n\t"57"movz %[v_reg], %[const_max_level], %[temp0] \n\t"58"addu %[cost], %[cost], %[temp1] \n\t"59"sll %[v_reg], %[v_reg], 1 \n\t"60"sll %[ctx_reg], %[ctx_reg], 2 \n\t"61"lhx %[temp0], %[v_reg](%[t]) \n\t"62"addu %[p_costs], %[p_costs], %[inc_p_costs] \n\t"63"addu %[t], %[p_costs], %[ctx_reg] \n\t"64"addu %[cost], %[cost], %[temp0] \n\t"65"bne %[n], %[res_last], 1b \n\t"66" lw %[t], 0(%[t]) \n\t"67"2: \n\t"68".set pop \n\t"69: [cost]"+&r"(cost), [t]"+&r"(t), [n]"+&r"(n), [v_reg]"=&r"(v_reg),70[ctx_reg]"=&r"(ctx_reg), [p_costs]"+&r"(p_costs), [temp0]"=&r"(temp0),71[temp1]"=&r"(temp1)72: [const_2]"r"(const_2), [const_max_level]"r"(const_max_level),73[VP8LevelFixedCosts]"r"(VP8LevelFixedCosts), [res_last]"r"(res_last),74[res_coeffs]"r"(res_coeffs), [inc_p_costs]"r"(inc_p_costs)75: "memory"76);7778// Last coefficient is always non-zero79{80const int v = abs(res->coeffs[n]);81assert(v != 0);82cost += VP8LevelCost(t, v);83if (n < 15) {84const int b = VP8EncBands[n + 1];85const int ctx = (v == 1) ? 1 : 2;86const int last_p0 = res->prob[b][ctx][0];87cost += VP8BitCost(0, last_p0);88}89}90return cost;91}9293//------------------------------------------------------------------------------94// Entry point9596extern void VP8EncDspCostInitMIPSdspR2(void);9798WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspCostInitMIPSdspR2(void) {99VP8GetResidualCost = GetResidualCost_MIPSdspR2;100}101102#else // !WEBP_USE_MIPS_DSP_R2103104WEBP_DSP_INIT_STUB(VP8EncDspCostInitMIPSdspR2)105106#endif // WEBP_USE_MIPS_DSP_R2107108109