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.

119 lines
2.6KB

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