c2p_core.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Fast C2P (Chunky-to-Planar) Conversion
  3. *
  4. * Copyright (C) 2003-2008 Geert Uytterhoeven
  5. *
  6. * NOTES:
  7. * - This code was inspired by Scout's C2P tutorial
  8. * - It assumes to run on a big endian system
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file COPYING in the main directory of this archive
  12. * for more details.
  13. */
  14. /*
  15. * Basic transpose step
  16. */
  17. static inline void _transp(u32 d[], unsigned int i1, unsigned int i2,
  18. unsigned int shift, u32 mask)
  19. {
  20. u32 t = (d[i1] ^ (d[i2] >> shift)) & mask;
  21. d[i1] ^= t;
  22. d[i2] ^= t << shift;
  23. }
  24. extern void c2p_unsupported(void);
  25. static inline u32 get_mask(unsigned int n)
  26. {
  27. switch (n) {
  28. case 1:
  29. return 0x55555555;
  30. case 2:
  31. return 0x33333333;
  32. case 4:
  33. return 0x0f0f0f0f;
  34. case 8:
  35. return 0x00ff00ff;
  36. case 16:
  37. return 0x0000ffff;
  38. }
  39. c2p_unsupported();
  40. return 0;
  41. }
  42. /*
  43. * Transpose operations on 8 32-bit words
  44. */
  45. static inline void transp8(u32 d[], unsigned int n, unsigned int m)
  46. {
  47. u32 mask = get_mask(n);
  48. switch (m) {
  49. case 1:
  50. /* First n x 1 block */
  51. _transp(d, 0, 1, n, mask);
  52. /* Second n x 1 block */
  53. _transp(d, 2, 3, n, mask);
  54. /* Third n x 1 block */
  55. _transp(d, 4, 5, n, mask);
  56. /* Fourth n x 1 block */
  57. _transp(d, 6, 7, n, mask);
  58. return;
  59. case 2:
  60. /* First n x 2 block */
  61. _transp(d, 0, 2, n, mask);
  62. _transp(d, 1, 3, n, mask);
  63. /* Second n x 2 block */
  64. _transp(d, 4, 6, n, mask);
  65. _transp(d, 5, 7, n, mask);
  66. return;
  67. case 4:
  68. /* Single n x 4 block */
  69. _transp(d, 0, 4, n, mask);
  70. _transp(d, 1, 5, n, mask);
  71. _transp(d, 2, 6, n, mask);
  72. _transp(d, 3, 7, n, mask);
  73. return;
  74. }
  75. c2p_unsupported();
  76. }
  77. /*
  78. * Transpose operations on 4 32-bit words
  79. */
  80. static inline void transp4(u32 d[], unsigned int n, unsigned int m)
  81. {
  82. u32 mask = get_mask(n);
  83. switch (m) {
  84. case 1:
  85. /* First n x 1 block */
  86. _transp(d, 0, 1, n, mask);
  87. /* Second n x 1 block */
  88. _transp(d, 2, 3, n, mask);
  89. return;
  90. case 2:
  91. /* Single n x 2 block */
  92. _transp(d, 0, 2, n, mask);
  93. _transp(d, 1, 3, n, mask);
  94. return;
  95. }
  96. c2p_unsupported();
  97. }
  98. /*
  99. * Transpose operations on 4 32-bit words (reverse order)
  100. */
  101. static inline void transp4x(u32 d[], unsigned int n, unsigned int m)
  102. {
  103. u32 mask = get_mask(n);
  104. switch (m) {
  105. case 2:
  106. /* Single n x 2 block */
  107. _transp(d, 2, 0, n, mask);
  108. _transp(d, 3, 1, n, mask);
  109. return;
  110. }
  111. c2p_unsupported();
  112. }
  113. /*
  114. * Compose two values, using a bitmask as decision value
  115. * This is equivalent to (a & mask) | (b & ~mask)
  116. */
  117. static inline u32 comp(u32 a, u32 b, u32 mask)
  118. {
  119. return ((a ^ b) & mask) ^ b;
  120. }