mathops.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Simple math operations
  3. * Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef AVCODEC_AVR32_MATHOPS_H
  22. #define AVCODEC_AVR32_MATHOPS_H
  23. #include <stdint.h>
  24. #include "config.h"
  25. #include "libavutil/common.h"
  26. #if HAVE_INLINE_ASM
  27. #define MULL MULL
  28. static inline av_const int MULL(int a, int b, unsigned shift)
  29. {
  30. union { int64_t x; int hl[2]; } x;
  31. __asm__ ("muls.d %0, %1, %2 \n\t"
  32. "lsr %0, %3 \n\t"
  33. "or %0, %0, %m0<<%4 \n\t"
  34. : "=r"(x) : "r"(b), "r"(a), "i"(shift), "i"(32-shift));
  35. return x.hl[1];
  36. }
  37. #define MULH MULH
  38. static inline av_const int MULH(int a, int b)
  39. {
  40. union { int64_t x; int hl[2]; } x;
  41. __asm__ ("muls.d %0, %1, %2" : "=r"(x.x) : "r"(a), "r"(b));
  42. return x.hl[0];
  43. }
  44. #define MUL64 MUL64
  45. static inline av_const int64_t MUL64(int a, int b)
  46. {
  47. int64_t x;
  48. __asm__ ("muls.d %0, %1, %2" : "=r"(x) : "r"(a), "r"(b));
  49. return x;
  50. }
  51. static inline av_const int64_t MAC64(int64_t d, int a, int b)
  52. {
  53. __asm__ ("macs.d %0, %1, %2" : "+r"(d) : "r"(a), "r"(b));
  54. return d;
  55. }
  56. #define MAC64(d, a, b) ((d) = MAC64(d, a, b))
  57. #define MLS64(d, a, b) MAC64(d, -(a), b)
  58. static inline av_const int MAC16(int d, int a, int b)
  59. {
  60. __asm__ ("machh.w %0, %1:b, %2:b" : "+r"(d) : "r"(a), "r"(b));
  61. return d;
  62. }
  63. #define MAC16(d, a, b) ((d) = MAC16(d, a, b))
  64. #define MLS16(d, a, b) MAC16(d, -(a), b)
  65. #define MUL16 MUL16
  66. static inline av_const int MUL16(int a, int b)
  67. {
  68. int d;
  69. __asm__ ("mulhh.w %0, %1:b, %2:b" : "=r"(d) : "r"(a), "r"(b));
  70. return d;
  71. }
  72. #define mid_pred mid_pred
  73. static inline av_const int mid_pred(int a, int b, int c)
  74. {
  75. int m;
  76. __asm__ ("mov %0, %2 \n\t"
  77. "cp.w %1, %2 \n\t"
  78. "movgt %0, %1 \n\t"
  79. "movgt %1, %2 \n\t"
  80. "cp.w %1, %3 \n\t"
  81. "movle %1, %3 \n\t"
  82. "cp.w %0, %1 \n\t"
  83. "movgt %0, %1 \n\t"
  84. : "=&r"(m), "+r"(a)
  85. : "r"(b), "r"(c));
  86. return m;
  87. }
  88. #endif /* HAVE_INLINE_ASM */
  89. #endif /* AVCODEC_AVR32_MATHOPS_H */