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.

111 lines
2.8KB

  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. #define MULH MULH
  28. #define MUL64 MUL64
  29. #if HAVE_ARMV6
  30. static inline av_const int MULH(int a, int b)
  31. {
  32. int r;
  33. __asm__ ("smmul %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
  34. return r;
  35. }
  36. static inline av_const int64_t MUL64(int a, int b)
  37. {
  38. int64_t x;
  39. __asm__ ("smull %Q0, %R0, %1, %2" : "=r"(x) : "r"(a), "r"(b));
  40. return x;
  41. }
  42. #else
  43. static inline av_const int MULH(int a, int b)
  44. {
  45. int lo, hi;
  46. __asm__ ("smull %0, %1, %2, %3" : "=&r"(lo), "=&r"(hi) : "r"(b), "r"(a));
  47. return hi;
  48. }
  49. static inline av_const int64_t MUL64(int a, int b)
  50. {
  51. int64_t x;
  52. __asm__ ("smull %Q0, %R0, %1, %2" : "=&r"(x) : "r"(a), "r"(b));
  53. return x;
  54. }
  55. #endif
  56. static inline av_const int64_t MAC64(int64_t d, int a, int b)
  57. {
  58. __asm__ ("smlal %Q0, %R0, %1, %2" : "+r"(d) : "r"(a), "r"(b));
  59. return d;
  60. }
  61. #define MAC64(d, a, b) ((d) = MAC64(d, a, b))
  62. #define MLS64(d, a, b) MAC64(d, -(a), b)
  63. #if HAVE_ARMV5TE
  64. /* signed 16x16 -> 32 multiply add accumulate */
  65. # define MAC16(rt, ra, rb) \
  66. __asm__ ("smlabb %0, %1, %2, %0" : "+r"(rt) : "r"(ra), "r"(rb));
  67. /* signed 16x16 -> 32 multiply */
  68. # define MUL16 MUL16
  69. static inline av_const int MUL16(int ra, int rb)
  70. {
  71. int rt;
  72. __asm__ ("smulbb %0, %1, %2" : "=r"(rt) : "r"(ra), "r"(rb));
  73. return rt;
  74. }
  75. #endif
  76. #define mid_pred mid_pred
  77. static inline av_const int mid_pred(int a, int b, int c)
  78. {
  79. int m;
  80. __asm__ (
  81. "mov %0, %2 \n\t"
  82. "cmp %1, %2 \n\t"
  83. "movgt %0, %1 \n\t"
  84. "movgt %1, %2 \n\t"
  85. "cmp %1, %3 \n\t"
  86. "movle %1, %3 \n\t"
  87. "cmp %0, %1 \n\t"
  88. "movgt %0, %1 \n\t"
  89. : "=&r"(m), "+r"(a)
  90. : "r"(b), "r"(c)
  91. : "cc");
  92. return m;
  93. }
  94. #endif /* HAVE_INLINE_ASM */
  95. #endif /* AVCODEC_ARM_MATHOPS_H */