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.

121 lines
2.7KB

  1. /*
  2. * simple math operations
  3. * Copyright (c) 2001, 2002 Fabrice Bellard
  4. * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVCODEC_MATHOPS_H
  23. #define AVCODEC_MATHOPS_H
  24. #include "libavutil/common.h"
  25. #if ARCH_ARM
  26. # include "arm/mathops.h"
  27. #elif ARCH_AVR32
  28. # include "avr32/mathops.h"
  29. #elif ARCH_BFIN
  30. # include "bfin/mathops.h"
  31. #elif ARCH_MIPS
  32. # include "mips/mathops.h"
  33. #elif ARCH_PPC
  34. # include "ppc/mathops.h"
  35. #elif ARCH_X86
  36. # include "x86/mathops.h"
  37. #endif
  38. /* generic implementation */
  39. #ifndef MULL
  40. # define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s))
  41. #endif
  42. #ifndef MULH
  43. //gcc 3.4 creates an incredibly bloated mess out of this
  44. //# define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32)
  45. static av_always_inline int MULH(int a, int b){
  46. return ((int64_t)(a) * (int64_t)(b))>>32;
  47. }
  48. #endif
  49. #ifndef MUL64
  50. # define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
  51. #endif
  52. #ifndef MAC64
  53. # define MAC64(d, a, b) ((d) += MUL64(a, b))
  54. #endif
  55. #ifndef MLS64
  56. # define MLS64(d, a, b) ((d) -= MUL64(a, b))
  57. #endif
  58. /* signed 16x16 -> 32 multiply add accumulate */
  59. #ifndef MAC16
  60. # define MAC16(rt, ra, rb) rt += (ra) * (rb)
  61. #endif
  62. /* signed 16x16 -> 32 multiply */
  63. #ifndef MUL16
  64. # define MUL16(ra, rb) ((ra) * (rb))
  65. #endif
  66. #ifndef MLS16
  67. # define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
  68. #endif
  69. /* median of 3 */
  70. #ifndef mid_pred
  71. #define mid_pred mid_pred
  72. static inline av_const int mid_pred(int a, int b, int c)
  73. {
  74. #if 0
  75. int t= (a-b)&((a-b)>>31);
  76. a-=t;
  77. b+=t;
  78. b-= (b-c)&((b-c)>>31);
  79. b+= (a-b)&((a-b)>>31);
  80. return b;
  81. #else
  82. if(a>b){
  83. if(c>b){
  84. if(c>a) b=a;
  85. else b=c;
  86. }
  87. }else{
  88. if(b>c){
  89. if(c>a) b=c;
  90. else b=a;
  91. }
  92. }
  93. return b;
  94. #endif
  95. }
  96. #endif
  97. #ifndef sign_extend
  98. static inline av_const int sign_extend(int val, unsigned bits)
  99. {
  100. return (val << (INT_BIT - bits)) >> (INT_BIT - bits);
  101. }
  102. #endif
  103. #endif /* AVCODEC_MATHOPS_H */