Path: blob/master/thirdparty/libwebp/src/dsp/cost_mips32.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_MIPS32)1415#include "src/enc/cost_enc.h"1617static int GetResidualCost_MIPS32(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"sll %[temp0], %[n], 1 \n\t"45"blez %[temp1], 2f \n\t"46" addu %[res_coeffs], %[res_coeffs], %[temp0] \n\t"47"1: \n\t"48"lh %[v_reg], 0(%[res_coeffs]) \n\t"49"addiu %[n], %[n], 1 \n\t"50"negu %[temp0], %[v_reg] \n\t"51"slti %[temp1], %[v_reg], 0 \n\t"52"movn %[v_reg], %[temp0], %[temp1] \n\t"53"sltiu %[temp0], %[v_reg], 2 \n\t"54"move %[ctx_reg], %[v_reg] \n\t"55"movz %[ctx_reg], %[const_2], %[temp0] \n\t"56"sll %[temp1], %[v_reg], 1 \n\t"57"addu %[temp1], %[temp1], %[VP8LevelFixedCosts] \n\t"58"lhu %[temp1], 0(%[temp1]) \n\t"59"slt %[temp0], %[v_reg], %[const_max_level] \n\t"60"movz %[v_reg], %[const_max_level], %[temp0] \n\t"61"addu %[cost], %[cost], %[temp1] \n\t"62"sll %[v_reg], %[v_reg], 1 \n\t"63"sll %[ctx_reg], %[ctx_reg], 2 \n\t"64"addu %[v_reg], %[v_reg], %[t] \n\t"65"lhu %[temp0], 0(%[v_reg]) \n\t"66"addu %[p_costs], %[p_costs], %[inc_p_costs] \n\t"67"addu %[t], %[p_costs], %[ctx_reg] \n\t"68"addu %[cost], %[cost], %[temp0] \n\t"69"addiu %[res_coeffs], %[res_coeffs], 2 \n\t"70"bne %[n], %[res_last], 1b \n\t"71" lw %[t], 0(%[t]) \n\t"72"2: \n\t"73".set pop \n\t"74: [cost]"+&r"(cost), [t]"+&r"(t), [n]"+&r"(n), [v_reg]"=&r"(v_reg),75[ctx_reg]"=&r"(ctx_reg), [p_costs]"+&r"(p_costs), [temp0]"=&r"(temp0),76[temp1]"=&r"(temp1), [res_coeffs]"+&r"(res_coeffs)77: [const_2]"r"(const_2), [const_max_level]"r"(const_max_level),78[VP8LevelFixedCosts]"r"(VP8LevelFixedCosts), [res_last]"r"(res_last),79[inc_p_costs]"r"(inc_p_costs)80: "memory"81);8283// Last coefficient is always non-zero84{85const int v = abs(res->coeffs[n]);86assert(v != 0);87cost += VP8LevelCost(t, v);88if (n < 15) {89const int b = VP8EncBands[n + 1];90const int ctx = (v == 1) ? 1 : 2;91const int last_p0 = res->prob[b][ctx][0];92cost += VP8BitCost(0, last_p0);93}94}95return cost;96}9798static void SetResidualCoeffs_MIPS32(const int16_t* WEBP_RESTRICT const coeffs,99VP8Residual* WEBP_RESTRICT const res) {100const int16_t* p_coeffs = (int16_t*)coeffs;101int temp0, temp1, temp2, n, n1;102assert(res->first == 0 || coeffs[0] == 0);103104__asm__ volatile (105".set push \n\t"106".set noreorder \n\t"107"addiu %[p_coeffs], %[p_coeffs], 28 \n\t"108"li %[n], 15 \n\t"109"li %[temp2], -1 \n\t"110"0: \n\t"111"ulw %[temp0], 0(%[p_coeffs]) \n\t"112"beqz %[temp0], 1f \n\t"113#if defined(WORDS_BIGENDIAN)114" sll %[temp1], %[temp0], 16 \n\t"115#else116" srl %[temp1], %[temp0], 16 \n\t"117#endif118"addiu %[n1], %[n], -1 \n\t"119"movz %[temp0], %[n1], %[temp1] \n\t"120"movn %[temp0], %[n], %[temp1] \n\t"121"j 2f \n\t"122" addiu %[temp2], %[temp0], 0 \n\t"123"1: \n\t"124"addiu %[n], %[n], -2 \n\t"125"bgtz %[n], 0b \n\t"126" addiu %[p_coeffs], %[p_coeffs], -4 \n\t"127"2: \n\t"128".set pop \n\t"129: [p_coeffs]"+&r"(p_coeffs), [temp0]"=&r"(temp0),130[temp1]"=&r"(temp1), [temp2]"=&r"(temp2),131[n]"=&r"(n), [n1]"=&r"(n1)132:133: "memory"134);135res->last = temp2;136res->coeffs = coeffs;137}138139//------------------------------------------------------------------------------140// Entry point141142extern void VP8EncDspCostInitMIPS32(void);143144WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspCostInitMIPS32(void) {145VP8GetResidualCost = GetResidualCost_MIPS32;146VP8SetResidualCoeffs = SetResidualCoeffs_MIPS32;147}148149#else // !WEBP_USE_MIPS32150151WEBP_DSP_INIT_STUB(VP8EncDspCostInitMIPS32)152153#endif // WEBP_USE_MIPS32154155156