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.

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