mathops.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_X86
  26. #include "x86/mathops.h"
  27. #elif ARCH_ARM
  28. #include "arm/mathops.h"
  29. #elif ARCH_PPC
  30. #include "ppc/mathops.h"
  31. #elif ARCH_BFIN
  32. #include "bfin/mathops.h"
  33. #endif
  34. /* generic implementation */
  35. #ifndef MULL
  36. # define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s))
  37. #endif
  38. #ifndef MULH
  39. //gcc 3.4 creates an incredibly bloated mess out of this
  40. //# define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32)
  41. static av_always_inline int MULH(int a, int b){
  42. return ((int64_t)(a) * (int64_t)(b))>>32;
  43. }
  44. #endif
  45. #ifndef MUL64
  46. # define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
  47. #endif
  48. #ifndef MAC64
  49. # define MAC64(d, a, b) ((d) += MUL64(a, b))
  50. #endif
  51. #ifndef MLS64
  52. # define MLS64(d, a, b) ((d) -= MUL64(a, b))
  53. #endif
  54. /* signed 16x16 -> 32 multiply add accumulate */
  55. #ifndef MAC16
  56. # define MAC16(rt, ra, rb) rt += (ra) * (rb)
  57. #endif
  58. /* signed 16x16 -> 32 multiply */
  59. #ifndef MUL16
  60. # define MUL16(ra, rb) ((ra) * (rb))
  61. #endif
  62. #ifndef MLS16
  63. # define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
  64. #endif
  65. /* median of 3 */
  66. #ifndef mid_pred
  67. #define mid_pred mid_pred
  68. static inline av_const int mid_pred(int a, int b, int c)
  69. {
  70. #if 0
  71. int t= (a-b)&((a-b)>>31);
  72. a-=t;
  73. b+=t;
  74. b-= (b-c)&((b-c)>>31);
  75. b+= (a-b)&((a-b)>>31);
  76. return b;
  77. #else
  78. if(a>b){
  79. if(c>b){
  80. if(c>a) b=a;
  81. else b=c;
  82. }
  83. }else{
  84. if(b>c){
  85. if(c>a) b=c;
  86. else b=a;
  87. }
  88. }
  89. return b;
  90. #endif
  91. }
  92. #endif
  93. #endif /* AVCODEC_MATHOPS_H */