neon.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. // NEON common code.
  11. #ifndef WEBP_DSP_NEON_H_
  12. #define WEBP_DSP_NEON_H_
  13. #include "./dsp.h"
  14. #if defined(WEBP_USE_NEON)
  15. #include <arm_neon.h>
  16. // Right now, some intrinsics functions seem slower, so we disable them
  17. // everywhere except newer clang/gcc or aarch64 where the inline assembly is
  18. // incompatible.
  19. #if LOCAL_CLANG_PREREQ(3,8) || LOCAL_GCC_PREREQ(4,9) || defined(__aarch64__)
  20. #define WEBP_USE_INTRINSICS // use intrinsics when possible
  21. #endif
  22. #define INIT_VECTOR2(v, a, b) do { \
  23. v.val[0] = a; \
  24. v.val[1] = b; \
  25. } while (0)
  26. #define INIT_VECTOR3(v, a, b, c) do { \
  27. v.val[0] = a; \
  28. v.val[1] = b; \
  29. v.val[2] = c; \
  30. } while (0)
  31. #define INIT_VECTOR4(v, a, b, c, d) do { \
  32. v.val[0] = a; \
  33. v.val[1] = b; \
  34. v.val[2] = c; \
  35. v.val[3] = d; \
  36. } while (0)
  37. // if using intrinsics, this flag avoids some functions that make gcc-4.6.3
  38. // crash ("internal compiler error: in immed_double_const, at emit-rtl.").
  39. // (probably similar to gcc.gnu.org/bugzilla/show_bug.cgi?id=48183)
  40. #if !(LOCAL_CLANG_PREREQ(3,8) || LOCAL_GCC_PREREQ(4,8) || defined(__aarch64__))
  41. #define WORK_AROUND_GCC
  42. #endif
  43. static WEBP_INLINE int32x4x4_t Transpose4x4_NEON(const int32x4x4_t rows) {
  44. uint64x2x2_t row01, row23;
  45. row01.val[0] = vreinterpretq_u64_s32(rows.val[0]);
  46. row01.val[1] = vreinterpretq_u64_s32(rows.val[1]);
  47. row23.val[0] = vreinterpretq_u64_s32(rows.val[2]);
  48. row23.val[1] = vreinterpretq_u64_s32(rows.val[3]);
  49. // Transpose 64-bit values (there's no vswp equivalent)
  50. {
  51. const uint64x1_t row0h = vget_high_u64(row01.val[0]);
  52. const uint64x1_t row2l = vget_low_u64(row23.val[0]);
  53. const uint64x1_t row1h = vget_high_u64(row01.val[1]);
  54. const uint64x1_t row3l = vget_low_u64(row23.val[1]);
  55. row01.val[0] = vcombine_u64(vget_low_u64(row01.val[0]), row2l);
  56. row23.val[0] = vcombine_u64(row0h, vget_high_u64(row23.val[0]));
  57. row01.val[1] = vcombine_u64(vget_low_u64(row01.val[1]), row3l);
  58. row23.val[1] = vcombine_u64(row1h, vget_high_u64(row23.val[1]));
  59. }
  60. {
  61. const int32x4x2_t out01 = vtrnq_s32(vreinterpretq_s32_u64(row01.val[0]),
  62. vreinterpretq_s32_u64(row01.val[1]));
  63. const int32x4x2_t out23 = vtrnq_s32(vreinterpretq_s32_u64(row23.val[0]),
  64. vreinterpretq_s32_u64(row23.val[1]));
  65. int32x4x4_t out;
  66. out.val[0] = out01.val[0];
  67. out.val[1] = out01.val[1];
  68. out.val[2] = out23.val[0];
  69. out.val[3] = out23.val[1];
  70. return out;
  71. }
  72. }
  73. #if 0 // Useful debug macro.
  74. #include <stdio.h>
  75. #define PRINT_REG(REG, SIZE) do { \
  76. int i; \
  77. printf("%s \t[%d]: 0x", #REG, SIZE); \
  78. if (SIZE == 8) { \
  79. uint8_t _tmp[8]; \
  80. vst1_u8(_tmp, (REG)); \
  81. for (i = 0; i < 8; ++i) printf("%.2x ", _tmp[i]); \
  82. } else if (SIZE == 16) { \
  83. uint16_t _tmp[4]; \
  84. vst1_u16(_tmp, (REG)); \
  85. for (i = 0; i < 4; ++i) printf("%.4x ", _tmp[i]); \
  86. } \
  87. printf("\n"); \
  88. } while (0)
  89. #endif
  90. #endif // WEBP_USE_NEON
  91. #endif // WEBP_DSP_NEON_H_