common_sse41.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright 2016 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. // SSE4 code common to several files.
  11. //
  12. // Author: Vincent Rabaud (vrabaud@google.com)
  13. #ifndef WEBP_DSP_COMMON_SSE41_H_
  14. #define WEBP_DSP_COMMON_SSE41_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #if defined(WEBP_USE_SSE41)
  19. #include <smmintrin.h>
  20. //------------------------------------------------------------------------------
  21. // Channel mixing.
  22. // Shuffles the input buffer as A0 0 0 A1 0 0 A2 ...
  23. #define WEBP_SSE41_SHUFF(OUT, IN0, IN1) \
  24. OUT##0 = _mm_shuffle_epi8(*IN0, shuff0); \
  25. OUT##1 = _mm_shuffle_epi8(*IN0, shuff1); \
  26. OUT##2 = _mm_shuffle_epi8(*IN0, shuff2); \
  27. OUT##3 = _mm_shuffle_epi8(*IN1, shuff0); \
  28. OUT##4 = _mm_shuffle_epi8(*IN1, shuff1); \
  29. OUT##5 = _mm_shuffle_epi8(*IN1, shuff2);
  30. // Pack the planar buffers
  31. // rrrr... rrrr... gggg... gggg... bbbb... bbbb....
  32. // triplet by triplet in the output buffer rgb as rgbrgbrgbrgb ...
  33. static WEBP_INLINE void VP8PlanarTo24b_SSE41(
  34. __m128i* const in0, __m128i* const in1, __m128i* const in2,
  35. __m128i* const in3, __m128i* const in4, __m128i* const in5) {
  36. __m128i R0, R1, R2, R3, R4, R5;
  37. __m128i G0, G1, G2, G3, G4, G5;
  38. __m128i B0, B1, B2, B3, B4, B5;
  39. // Process R.
  40. {
  41. const __m128i shuff0 = _mm_set_epi8(
  42. 5, -1, -1, 4, -1, -1, 3, -1, -1, 2, -1, -1, 1, -1, -1, 0);
  43. const __m128i shuff1 = _mm_set_epi8(
  44. -1, 10, -1, -1, 9, -1, -1, 8, -1, -1, 7, -1, -1, 6, -1, -1);
  45. const __m128i shuff2 = _mm_set_epi8(
  46. -1, -1, 15, -1, -1, 14, -1, -1, 13, -1, -1, 12, -1, -1, 11, -1);
  47. WEBP_SSE41_SHUFF(R, in0, in1)
  48. }
  49. // Process G.
  50. {
  51. // Same as before, just shifted to the left by one and including the right
  52. // padding.
  53. const __m128i shuff0 = _mm_set_epi8(
  54. -1, -1, 4, -1, -1, 3, -1, -1, 2, -1, -1, 1, -1, -1, 0, -1);
  55. const __m128i shuff1 = _mm_set_epi8(
  56. 10, -1, -1, 9, -1, -1, 8, -1, -1, 7, -1, -1, 6, -1, -1, 5);
  57. const __m128i shuff2 = _mm_set_epi8(
  58. -1, 15, -1, -1, 14, -1, -1, 13, -1, -1, 12, -1, -1, 11, -1, -1);
  59. WEBP_SSE41_SHUFF(G, in2, in3)
  60. }
  61. // Process B.
  62. {
  63. const __m128i shuff0 = _mm_set_epi8(
  64. -1, 4, -1, -1, 3, -1, -1, 2, -1, -1, 1, -1, -1, 0, -1, -1);
  65. const __m128i shuff1 = _mm_set_epi8(
  66. -1, -1, 9, -1, -1, 8, -1, -1, 7, -1, -1, 6, -1, -1, 5, -1);
  67. const __m128i shuff2 = _mm_set_epi8(
  68. 15, -1, -1, 14, -1, -1, 13, -1, -1, 12, -1, -1, 11, -1, -1, 10);
  69. WEBP_SSE41_SHUFF(B, in4, in5)
  70. }
  71. // OR the different channels.
  72. {
  73. const __m128i RG0 = _mm_or_si128(R0, G0);
  74. const __m128i RG1 = _mm_or_si128(R1, G1);
  75. const __m128i RG2 = _mm_or_si128(R2, G2);
  76. const __m128i RG3 = _mm_or_si128(R3, G3);
  77. const __m128i RG4 = _mm_or_si128(R4, G4);
  78. const __m128i RG5 = _mm_or_si128(R5, G5);
  79. *in0 = _mm_or_si128(RG0, B0);
  80. *in1 = _mm_or_si128(RG1, B1);
  81. *in2 = _mm_or_si128(RG2, B2);
  82. *in3 = _mm_or_si128(RG3, B3);
  83. *in4 = _mm_or_si128(RG4, B4);
  84. *in5 = _mm_or_si128(RG5, B5);
  85. }
  86. }
  87. #undef WEBP_SSE41_SHUFF
  88. // Convert four packed four-channel buffers like argbargbargbargb... into the
  89. // split channels aaaaa ... rrrr ... gggg .... bbbbb ......
  90. static WEBP_INLINE void VP8L32bToPlanar_SSE41(__m128i* const in0,
  91. __m128i* const in1,
  92. __m128i* const in2,
  93. __m128i* const in3) {
  94. // aaaarrrrggggbbbb
  95. const __m128i shuff0 =
  96. _mm_set_epi8(15, 11, 7, 3, 14, 10, 6, 2, 13, 9, 5, 1, 12, 8, 4, 0);
  97. const __m128i A0 = _mm_shuffle_epi8(*in0, shuff0);
  98. const __m128i A1 = _mm_shuffle_epi8(*in1, shuff0);
  99. const __m128i A2 = _mm_shuffle_epi8(*in2, shuff0);
  100. const __m128i A3 = _mm_shuffle_epi8(*in3, shuff0);
  101. // A0A1R0R1
  102. // G0G1B0B1
  103. // A2A3R2R3
  104. // G0G1B0B1
  105. const __m128i B0 = _mm_unpacklo_epi32(A0, A1);
  106. const __m128i B1 = _mm_unpackhi_epi32(A0, A1);
  107. const __m128i B2 = _mm_unpacklo_epi32(A2, A3);
  108. const __m128i B3 = _mm_unpackhi_epi32(A2, A3);
  109. *in3 = _mm_unpacklo_epi64(B0, B2);
  110. *in2 = _mm_unpackhi_epi64(B0, B2);
  111. *in1 = _mm_unpacklo_epi64(B1, B3);
  112. *in0 = _mm_unpackhi_epi64(B1, B3);
  113. }
  114. #endif // WEBP_USE_SSE41
  115. #ifdef __cplusplus
  116. } // extern "C"
  117. #endif
  118. #endif // WEBP_DSP_COMMON_SSE41_H_