mathops.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * simple math operations
  3. * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
  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_ARM_MATHOPS_H
  22. #define AVCODEC_ARM_MATHOPS_H
  23. #include <stdint.h>
  24. #include "config.h"
  25. #include "libavutil/common.h"
  26. #if HAVE_INLINE_ASM
  27. #if HAVE_ARMV6_INLINE
  28. #define MULH MULH
  29. static inline av_const int MULH(int a, int b)
  30. {
  31. int r;
  32. __asm__ ("smmul %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
  33. return r;
  34. }
  35. #define FASTDIV FASTDIV
  36. static av_always_inline av_const int FASTDIV(int a, int b)
  37. {
  38. int r;
  39. __asm__ ("cmp %2, #2 \n\t"
  40. "ldr %0, [%3, %2, lsl #2] \n\t"
  41. "ite le \n\t"
  42. "lsrle %0, %1, #1 \n\t"
  43. "smmulgt %0, %0, %1 \n\t"
  44. : "=&r"(r) : "r"(a), "r"(b), "r"(ff_inverse) : "cc");
  45. return r;
  46. }
  47. #else /* HAVE_ARMV6_INLINE */
  48. #define FASTDIV FASTDIV
  49. static av_always_inline av_const int FASTDIV(int a, int b)
  50. {
  51. int r, t;
  52. __asm__ ("umull %1, %0, %2, %3"
  53. : "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b]));
  54. return r;
  55. }
  56. #endif
  57. #define MLS64(d, a, b) MAC64(d, -(a), b)
  58. #if HAVE_ARMV5TE_INLINE
  59. /* signed 16x16 -> 32 multiply add accumulate */
  60. # define MAC16(rt, ra, rb) \
  61. __asm__ ("smlabb %0, %1, %2, %0" : "+r"(rt) : "r"(ra), "r"(rb));
  62. /* signed 16x16 -> 32 multiply */
  63. # define MUL16 MUL16
  64. static inline av_const int MUL16(int ra, int rb)
  65. {
  66. int rt;
  67. __asm__ ("smulbb %0, %1, %2" : "=r"(rt) : "r"(ra), "r"(rb));
  68. return rt;
  69. }
  70. #endif
  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__ (
  76. "mov %0, %2 \n\t"
  77. "cmp %1, %2 \n\t"
  78. "itt gt \n\t"
  79. "movgt %0, %1 \n\t"
  80. "movgt %1, %2 \n\t"
  81. "cmp %1, %3 \n\t"
  82. "it le \n\t"
  83. "movle %1, %3 \n\t"
  84. "cmp %0, %1 \n\t"
  85. "it gt \n\t"
  86. "movgt %0, %1 \n\t"
  87. : "=&r"(m), "+r"(a)
  88. : "r"(b), "r"(c)
  89. : "cc");
  90. return m;
  91. }
  92. #endif /* HAVE_INLINE_ASM */
  93. #endif /* AVCODEC_ARM_MATHOPS_H */