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.

116 lines
3.1KB

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