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.

101 lines
2.8KB

  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 "libavutil/common.h"
  25. #if HAVE_INLINE_ASM
  26. #define MULL MULL
  27. static inline av_const int MULL(int a, int b, unsigned shift)
  28. {
  29. union { int64_t x; int hl[2]; } x;
  30. __asm__ ("muls.d %0, %1, %2 \n\t"
  31. "lsr %0, %3 \n\t"
  32. "or %0, %0, %m0<<%4 \n\t"
  33. : "=r"(x) : "r"(b), "r"(a), "i"(shift), "i"(32-shift));
  34. return x.hl[1];
  35. }
  36. #define MULH MULH
  37. static inline av_const int MULH(int a, int b)
  38. {
  39. union { int64_t x; int hl[2]; } x;
  40. __asm__ ("muls.d %0, %1, %2" : "=r"(x.x) : "r"(a), "r"(b));
  41. return x.hl[0];
  42. }
  43. #define MUL64 MUL64
  44. static inline av_const int64_t MUL64(int a, int b)
  45. {
  46. int64_t x;
  47. __asm__ ("muls.d %0, %1, %2" : "=r"(x) : "r"(a), "r"(b));
  48. return x;
  49. }
  50. static inline av_const int64_t MAC64(int64_t d, int a, int b)
  51. {
  52. __asm__ ("macs.d %0, %1, %2" : "+r"(d) : "r"(a), "r"(b));
  53. return d;
  54. }
  55. #define MAC64(d, a, b) ((d) = MAC64(d, a, b))
  56. #define MLS64(d, a, b) MAC64(d, -(a), b)
  57. static inline av_const int MAC16(int d, int a, int b)
  58. {
  59. __asm__ ("machh.w %0, %1:b, %2:b" : "+r"(d) : "r"(a), "r"(b));
  60. return d;
  61. }
  62. #define MAC16(d, a, b) ((d) = MAC16(d, a, b))
  63. #define MLS16(d, a, b) MAC16(d, -(a), b)
  64. #define MUL16 MUL16
  65. static inline av_const int MUL16(int a, int b)
  66. {
  67. int d;
  68. __asm__ ("mulhh.w %0, %1:b, %2:b" : "=r"(d) : "r"(a), "r"(b));
  69. return d;
  70. }
  71. #define mid_pred mid_pred
  72. static inline av_const int mid_pred(int a, int b, int c)
  73. {
  74. int m;
  75. __asm__ ("mov %0, %2 \n\t"
  76. "cp.w %1, %2 \n\t"
  77. "movgt %0, %1 \n\t"
  78. "movgt %1, %2 \n\t"
  79. "cp.w %1, %3 \n\t"
  80. "movle %1, %3 \n\t"
  81. "cp.w %0, %1 \n\t"
  82. "movgt %0, %1 \n\t"
  83. : "=&r"(m), "+r"(a)
  84. : "r"(b), "r"(c));
  85. return m;
  86. }
  87. #endif /* HAVE_INLINE_ASM */
  88. #endif /* AVCODEC_AVR32_MATHOPS_H */