gcc_fixes.h 3.8 KB

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