argb_mips_dsp_r2.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // ARGB making functions (mips version).
  11. //
  12. // Author: Djordje Pesut (djordje.pesut@imgtec.com)
  13. #include "./dsp.h"
  14. #if defined(WEBP_USE_MIPS_DSP_R2)
  15. static void PackARGB(const uint8_t* a, const uint8_t* r, const uint8_t* g,
  16. const uint8_t* b, int len, uint32_t* out) {
  17. int temp0, temp1, temp2, temp3, offset;
  18. const int rest = len & 1;
  19. const uint32_t* const loop_end = out + len - rest;
  20. const int step = 4;
  21. __asm__ volatile (
  22. "xor %[offset], %[offset], %[offset] \n\t"
  23. "beq %[loop_end], %[out], 0f \n\t"
  24. "2: \n\t"
  25. "lbux %[temp0], %[offset](%[a]) \n\t"
  26. "lbux %[temp1], %[offset](%[r]) \n\t"
  27. "lbux %[temp2], %[offset](%[g]) \n\t"
  28. "lbux %[temp3], %[offset](%[b]) \n\t"
  29. "ins %[temp1], %[temp0], 16, 16 \n\t"
  30. "ins %[temp3], %[temp2], 16, 16 \n\t"
  31. "addiu %[out], %[out], 4 \n\t"
  32. "precr.qb.ph %[temp0], %[temp1], %[temp3] \n\t"
  33. "sw %[temp0], -4(%[out]) \n\t"
  34. "addu %[offset], %[offset], %[step] \n\t"
  35. "bne %[loop_end], %[out], 2b \n\t"
  36. "0: \n\t"
  37. "beq %[rest], $zero, 1f \n\t"
  38. "lbux %[temp0], %[offset](%[a]) \n\t"
  39. "lbux %[temp1], %[offset](%[r]) \n\t"
  40. "lbux %[temp2], %[offset](%[g]) \n\t"
  41. "lbux %[temp3], %[offset](%[b]) \n\t"
  42. "ins %[temp1], %[temp0], 16, 16 \n\t"
  43. "ins %[temp3], %[temp2], 16, 16 \n\t"
  44. "precr.qb.ph %[temp0], %[temp1], %[temp3] \n\t"
  45. "sw %[temp0], 0(%[out]) \n\t"
  46. "1: \n\t"
  47. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  48. [temp3]"=&r"(temp3), [offset]"=&r"(offset), [out]"+&r"(out)
  49. : [a]"r"(a), [r]"r"(r), [g]"r"(g), [b]"r"(b), [step]"r"(step),
  50. [loop_end]"r"(loop_end), [rest]"r"(rest)
  51. : "memory"
  52. );
  53. }
  54. static void PackRGB(const uint8_t* r, const uint8_t* g, const uint8_t* b,
  55. int len, int step, uint32_t* out) {
  56. int temp0, temp1, temp2, offset;
  57. const int rest = len & 1;
  58. const int a = 0xff;
  59. const uint32_t* const loop_end = out + len - rest;
  60. __asm__ volatile (
  61. "xor %[offset], %[offset], %[offset] \n\t"
  62. "beq %[loop_end], %[out], 0f \n\t"
  63. "2: \n\t"
  64. "lbux %[temp0], %[offset](%[r]) \n\t"
  65. "lbux %[temp1], %[offset](%[g]) \n\t"
  66. "lbux %[temp2], %[offset](%[b]) \n\t"
  67. "ins %[temp0], %[a], 16, 16 \n\t"
  68. "ins %[temp2], %[temp1], 16, 16 \n\t"
  69. "addiu %[out], %[out], 4 \n\t"
  70. "precr.qb.ph %[temp0], %[temp0], %[temp2] \n\t"
  71. "sw %[temp0], -4(%[out]) \n\t"
  72. "addu %[offset], %[offset], %[step] \n\t"
  73. "bne %[loop_end], %[out], 2b \n\t"
  74. "0: \n\t"
  75. "beq %[rest], $zero, 1f \n\t"
  76. "lbux %[temp0], %[offset](%[r]) \n\t"
  77. "lbux %[temp1], %[offset](%[g]) \n\t"
  78. "lbux %[temp2], %[offset](%[b]) \n\t"
  79. "ins %[temp0], %[a], 16, 16 \n\t"
  80. "ins %[temp2], %[temp1], 16, 16 \n\t"
  81. "precr.qb.ph %[temp0], %[temp0], %[temp2] \n\t"
  82. "sw %[temp0], 0(%[out]) \n\t"
  83. "1: \n\t"
  84. : [temp0]"=&r"(temp0), [temp1]"=&r"(temp1), [temp2]"=&r"(temp2),
  85. [offset]"=&r"(offset), [out]"+&r"(out)
  86. : [a]"r"(a), [r]"r"(r), [g]"r"(g), [b]"r"(b), [step]"r"(step),
  87. [loop_end]"r"(loop_end), [rest]"r"(rest)
  88. : "memory"
  89. );
  90. }
  91. //------------------------------------------------------------------------------
  92. // Entry point
  93. extern void VP8EncDspARGBInitMIPSdspR2(void);
  94. WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspARGBInitMIPSdspR2(void) {
  95. VP8PackARGB = PackARGB;
  96. VP8PackRGB = PackRGB;
  97. }
  98. #else // !WEBP_USE_MIPS_DSP_R2
  99. WEBP_DSP_INIT_STUB(VP8EncDspARGBInitMIPSdspR2)
  100. #endif // WEBP_USE_MIPS_DSP_R2