You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.0KB

  1. /*
  2. * gcc fixes for altivec.
  3. * Used to workaround broken gcc (FSF gcc-3 pre gcc-3.3)
  4. * and to stay somewhat compatible with Darwin.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef _GCC_FIXES_
  21. #define _GCC_FIXES_
  22. #ifdef HAVE_ALTIVEC_H
  23. #include <altivec.h>
  24. #endif
  25. #ifdef CONFIG_DARWIN
  26. # ifndef __MWERKS__
  27. # define AVV(x...) (x)
  28. # else
  29. # define AVV
  30. # endif
  31. #define REG_v(a) asm ( #a )
  32. #else
  33. #define AVV(x...) {x}
  34. #if (__GNUC__ < 4)
  35. # define REG_v(a)
  36. #else
  37. # define REG_v(a) asm ( #a )
  38. #endif
  39. #if (__GNUC__ * 100 + __GNUC_MINOR__ < 303)
  40. /* This code was provided to me by Bartosch Pixa
  41. * as a separate header file (broken_mergel.h).
  42. * thanks to lu_zero for the workaround.
  43. *
  44. * See this mail for more information:
  45. * http://gcc.gnu.org/ml/gcc/2003-04/msg00967.html
  46. */
  47. static inline vector signed char ff_vmrglb (vector signed char const A,
  48. vector signed char const B)
  49. {
  50. static const vector unsigned char lowbyte = {
  51. 0x08, 0x18, 0x09, 0x19, 0x0a, 0x1a, 0x0b, 0x1b,
  52. 0x0c, 0x1c, 0x0d, 0x1d, 0x0e, 0x1e, 0x0f, 0x1f
  53. };
  54. return vec_perm (A, B, lowbyte);
  55. }
  56. static inline vector signed short ff_vmrglh (vector signed short const A,
  57. vector signed short const B)
  58. {
  59. static const vector unsigned char lowhalf = {
  60. 0x08, 0x09, 0x18, 0x19, 0x0a, 0x0b, 0x1a, 0x1b,
  61. 0x0c, 0x0d, 0x1c, 0x1d, 0x0e, 0x0f, 0x1e, 0x1f
  62. };
  63. return vec_perm (A, B, lowhalf);
  64. }
  65. static inline vector signed int ff_vmrglw (vector signed int const A,
  66. vector signed int const B)
  67. {
  68. static const vector unsigned char lowword = {
  69. 0x08, 0x09, 0x0a, 0x0b, 0x18, 0x19, 0x1a, 0x1b,
  70. 0x0c, 0x0d, 0x0e, 0x0f, 0x1c, 0x1d, 0x1e, 0x1f
  71. };
  72. return vec_perm (A, B, lowword);
  73. }
  74. /*#define ff_vmrglb ff_vmrglb
  75. #define ff_vmrglh ff_vmrglh
  76. #define ff_vmrglw ff_vmrglw
  77. */
  78. #undef vec_mergel
  79. #define vec_mergel(a1, a2) \
  80. __ch (__bin_args_eq (vector signed char, (a1), vector signed char, (a2)), \
  81. ((vector signed char) ff_vmrglb ((vector signed char) (a1), (vector signed char) (a2))), \
  82. __ch (__bin_args_eq (vector unsigned char, (a1), vector unsigned char, (a2)), \
  83. ((vector unsigned char) ff_vmrglb ((vector signed char) (a1), (vector signed char) (a2))), \
  84. __ch (__bin_args_eq (vector signed short, (a1), vector signed short, (a2)), \
  85. ((vector signed short) ff_vmrglh ((vector signed short) (a1), (vector signed short) (a2))), \
  86. __ch (__bin_args_eq (vector unsigned short, (a1), vector unsigned short, (a2)), \
  87. ((vector unsigned short) ff_vmrglh ((vector signed short) (a1), (vector signed short) (a2))), \
  88. __ch (__bin_args_eq (vector float, (a1), vector float, (a2)), \
  89. ((vector float) ff_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
  90. __ch (__bin_args_eq (vector signed int, (a1), vector signed int, (a2)), \
  91. ((vector signed int) ff_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
  92. __ch (__bin_args_eq (vector unsigned int, (a1), vector unsigned int, (a2)), \
  93. ((vector unsigned int) ff_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \
  94. __altivec_link_error_invalid_argument ())))))))
  95. #endif
  96. #endif /* CONFIG_DARWIN */
  97. #ifndef __MWERKS__
  98. #define const_vector const vector
  99. #else
  100. #define const_vector vector
  101. #endif
  102. #endif /* _GCC_FIXES_ */