yuv_mips_dsp_r2.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright 2014 Google Inc. All Rights Reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license
  4. // that can be found in the COPYING file in the root of the source
  5. // tree. An additional intellectual property rights grant can be found
  6. // in the file PATENTS. All contributing project authors may
  7. // be found in the AUTHORS file in the root of the source tree.
  8. // -----------------------------------------------------------------------------
  9. //
  10. // MIPS DSPr2 version of YUV to RGB upsampling functions.
  11. //
  12. // Author(s): Branimir Vasic (branimir.vasic@imgtec.com)
  13. // Djordje Pesut (djordje.pesut@imgtec.com)
  14. #include "./dsp.h"
  15. #if defined(WEBP_USE_MIPS_DSP_R2)
  16. #include "./yuv.h"
  17. //------------------------------------------------------------------------------
  18. // simple point-sampling
  19. #define ROW_FUNC_PART_1() \
  20. "lbu %[temp3], 0(%[v]) \n\t" \
  21. "lbu %[temp4], 0(%[u]) \n\t" \
  22. "lbu %[temp0], 0(%[y]) \n\t" \
  23. "mul %[temp1], %[t_con_1], %[temp3] \n\t" \
  24. "mul %[temp3], %[t_con_2], %[temp3] \n\t" \
  25. "mul %[temp2], %[t_con_3], %[temp4] \n\t" \
  26. "mul %[temp4], %[t_con_4], %[temp4] \n\t" \
  27. "mul %[temp0], %[t_con_5], %[temp0] \n\t" \
  28. "subu %[temp1], %[temp1], %[t_con_6] \n\t" \
  29. "subu %[temp3], %[temp3], %[t_con_7] \n\t" \
  30. "addu %[temp2], %[temp2], %[temp3] \n\t" \
  31. "subu %[temp4], %[temp4], %[t_con_8] \n\t" \
  32. #define ROW_FUNC_PART_2(R, G, B, K) \
  33. "addu %[temp5], %[temp0], %[temp1] \n\t" \
  34. "subu %[temp6], %[temp0], %[temp2] \n\t" \
  35. "addu %[temp7], %[temp0], %[temp4] \n\t" \
  36. ".if " #K " \n\t" \
  37. "lbu %[temp0], 1(%[y]) \n\t" \
  38. ".endif \n\t" \
  39. "shll_s.w %[temp5], %[temp5], 17 \n\t" \
  40. "shll_s.w %[temp6], %[temp6], 17 \n\t" \
  41. ".if " #K " \n\t" \
  42. "mul %[temp0], %[t_con_5], %[temp0] \n\t" \
  43. ".endif \n\t" \
  44. "shll_s.w %[temp7], %[temp7], 17 \n\t" \
  45. "precrqu_s.qb.ph %[temp5], %[temp5], $zero \n\t" \
  46. "precrqu_s.qb.ph %[temp6], %[temp6], $zero \n\t" \
  47. "precrqu_s.qb.ph %[temp7], %[temp7], $zero \n\t" \
  48. "srl %[temp5], %[temp5], 24 \n\t" \
  49. "srl %[temp6], %[temp6], 24 \n\t" \
  50. "srl %[temp7], %[temp7], 24 \n\t" \
  51. "sb %[temp5], " #R "(%[dst]) \n\t" \
  52. "sb %[temp6], " #G "(%[dst]) \n\t" \
  53. "sb %[temp7], " #B "(%[dst]) \n\t" \
  54. #define ASM_CLOBBER_LIST() \
  55. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2), \
  56. [temp3]"=&r"(temp3), [temp4]"=&r"(temp4), [temp5]"=&r"(temp5), \
  57. [temp6]"=&r"(temp6), [temp7]"=&r"(temp7) \
  58. : [t_con_1]"r"(t_con_1), [t_con_2]"r"(t_con_2), [t_con_3]"r"(t_con_3), \
  59. [t_con_4]"r"(t_con_4), [t_con_5]"r"(t_con_5), [t_con_6]"r"(t_con_6), \
  60. [u]"r"(u), [v]"r"(v), [y]"r"(y), [dst]"r"(dst), \
  61. [t_con_7]"r"(t_con_7), [t_con_8]"r"(t_con_8) \
  62. : "memory", "hi", "lo" \
  63. #define ROW_FUNC(FUNC_NAME, XSTEP, R, G, B, A) \
  64. static void FUNC_NAME(const uint8_t* y, \
  65. const uint8_t* u, const uint8_t* v, \
  66. uint8_t* dst, int len) { \
  67. int i; \
  68. uint32_t temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; \
  69. const int t_con_1 = 26149; \
  70. const int t_con_2 = 13320; \
  71. const int t_con_3 = 6419; \
  72. const int t_con_4 = 33050; \
  73. const int t_con_5 = 19077; \
  74. const int t_con_6 = 14234; \
  75. const int t_con_7 = 8708; \
  76. const int t_con_8 = 17685; \
  77. for (i = 0; i < (len >> 1); i++) { \
  78. __asm__ volatile ( \
  79. ROW_FUNC_PART_1() \
  80. ROW_FUNC_PART_2(R, G, B, 1) \
  81. ROW_FUNC_PART_2(R + XSTEP, G + XSTEP, B + XSTEP, 0) \
  82. ASM_CLOBBER_LIST() \
  83. ); \
  84. if (A) dst[A] = dst[A + XSTEP] = 0xff; \
  85. y += 2; \
  86. ++u; \
  87. ++v; \
  88. dst += 2 * XSTEP; \
  89. } \
  90. if (len & 1) { \
  91. __asm__ volatile ( \
  92. ROW_FUNC_PART_1() \
  93. ROW_FUNC_PART_2(R, G, B, 0) \
  94. ASM_CLOBBER_LIST() \
  95. ); \
  96. if (A) dst[A] = 0xff; \
  97. } \
  98. }
  99. ROW_FUNC(YuvToRgbRow_MIPSdspR2, 3, 0, 1, 2, 0)
  100. ROW_FUNC(YuvToRgbaRow_MIPSdspR2, 4, 0, 1, 2, 3)
  101. ROW_FUNC(YuvToBgrRow_MIPSdspR2, 3, 2, 1, 0, 0)
  102. ROW_FUNC(YuvToBgraRow_MIPSdspR2, 4, 2, 1, 0, 3)
  103. #undef ROW_FUNC
  104. #undef ASM_CLOBBER_LIST
  105. #undef ROW_FUNC_PART_2
  106. #undef ROW_FUNC_PART_1
  107. //------------------------------------------------------------------------------
  108. // Entry point
  109. extern void WebPInitSamplersMIPSdspR2(void);
  110. WEBP_TSAN_IGNORE_FUNCTION void WebPInitSamplersMIPSdspR2(void) {
  111. WebPSamplers[MODE_RGB] = YuvToRgbRow_MIPSdspR2;
  112. WebPSamplers[MODE_RGBA] = YuvToRgbaRow_MIPSdspR2;
  113. WebPSamplers[MODE_BGR] = YuvToBgrRow_MIPSdspR2;
  114. WebPSamplers[MODE_BGRA] = YuvToBgraRow_MIPSdspR2;
  115. }
  116. #else // !WEBP_USE_MIPS_DSP_R2
  117. WEBP_DSP_INIT_STUB(WebPInitSamplersMIPSdspR2)
  118. #endif // WEBP_USE_MIPS_DSP_R2