basic_op.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef __BASIC_OP_H__
  2. #define __BASIC_OP_H__
  3. #include "config.h"
  4. /*___________________________________________________________________________
  5. | |
  6. | Constants and Globals |
  7. |___________________________________________________________________________|
  8. */
  9. #define MAX_32 (Word32)0x7fffffffL
  10. #define MIN_32 (Word32)0x80000000L
  11. #define MAX_16 (Word16)0x7fff
  12. #define MIN_16 (Word16)(pj_uint16_t)0x8000
  13. #define UMAX_32 (UWord32)0xffffffffL
  14. #define UMIN_32 (UWord32)0x00000000L
  15. /*___________________________________________________________________________
  16. | |
  17. | Prototypes for basic arithmetic operators |
  18. |___________________________________________________________________________|
  19. */
  20. PJ_INLINE(Word16) add (Word16 var1, Word16 var2); /* Short add, 1 */
  21. PJ_INLINE(Word16) sub (Word16 var1, Word16 var2); /* Short sub, 1 */
  22. PJ_INLINE(Word16) abs_s (Word16 var1); /* Short abs, 1 */
  23. LIBG7221_DECL(Word16) shl (Word16 var1, Word16 var2); /* Short shift left, 1 */
  24. PJ_INLINE(Word16) shl_nocheck(Word16 var1, Word16 var2);
  25. LIBG7221_DECL(Word16) shr (Word16 var1, Word16 var2); /* Short shift right, 1 */
  26. PJ_INLINE(Word16) shr_nocheck(Word16 var1, Word16 var2);
  27. LIBG7221_DECL(Word16) mult (Word16 var1, Word16 var2); /* Short mult, 1 */
  28. PJ_INLINE(Word32) L_mult (Word16 var1, Word16 var2); /* Long mult, 1 */
  29. PJ_INLINE(Word16) negate (Word16 var1); /* Short negate, 1 */
  30. PJ_INLINE(Word16) extract_h (Word32 L_var1); /* Extract high, 1 */
  31. PJ_INLINE(Word16) extract_l (Word32 L_var1); /* Extract low, 1 */
  32. PJ_INLINE(Word16) itu_round (Word32 L_var1); /* Round, 1 */
  33. PJ_INLINE(Word32) L_mac (Word32 L_var3, Word16 var1, Word16 var2); /* Mac, 1 */
  34. LIBG7221_DECL(Word32) L_msu (Word32 L_var3, Word16 var1, Word16 var2); /* Msu, 1 */
  35. LIBG7221_DECL(Word32) L_macNs (Word32 L_var3, Word16 var1, Word16 var2); /* Mac without
  36. sat, 1 */
  37. LIBG7221_DECL(Word32) L_msuNs (Word32 L_var3, Word16 var1, Word16 var2); /* Msu without
  38. sat, 1 */
  39. //PJ_INLINE(Word32) L_add (Word32 L_var1, Word32 L_var2); /* Long add, 2 */
  40. PJ_INLINE(Word32) L_sub (Word32 L_var1, Word32 L_var2); /* Long sub, 2 */
  41. LIBG7221_DECL(Word32) L_add_c (Word32 L_var1, Word32 L_var2); /* Long add with c, 2 */
  42. LIBG7221_DECL(Word32) L_sub_c (Word32 L_var1, Word32 L_var2); /* Long sub with c, 2 */
  43. LIBG7221_DECL(Word32) L_negate (Word32 L_var1); /* Long negate, 2 */
  44. LIBG7221_DECL(Word16) mult_r (Word16 var1, Word16 var2); /* Mult with round, 2 */
  45. PJ_INLINE(Word32) L_shl (Word32 L_var1, Word16 var2); /* Long shift left, 2 */
  46. PJ_INLINE(Word32) L_shr (Word32 L_var1, Word16 var2); /* Long shift right, 2*/
  47. LIBG7221_DECL(Word16) shr_r (Word16 var1, Word16 var2); /* Shift right with
  48. round, 2 */
  49. LIBG7221_DECL(Word16) mac_r (Word32 L_var3, Word16 var1, Word16 var2); /* Mac with
  50. rounding,2 */
  51. LIBG7221_DECL(Word16) msu_r (Word32 L_var3, Word16 var1, Word16 var2); /* Msu with
  52. rounding,2 */
  53. LIBG7221_DECL(Word32) L_deposit_h (Word16 var1); /* 16 bit var1 -> MSB, 2 */
  54. LIBG7221_DECL(Word32) L_deposit_l (Word16 var1); /* 16 bit var1 -> LSB, 2 */
  55. LIBG7221_DECL(Word32) L_shr_r (Word32 L_var1, Word16 var2); /* Long shift right with
  56. round, 3 */
  57. LIBG7221_DECL(Word32) L_abs (Word32 L_var1); /* Long abs, 3 */
  58. LIBG7221_DECL(Word32) L_sat (Word32 L_var1); /* Long saturation, 4 */
  59. LIBG7221_DECL(Word16) norm_s (Word16 var1); /* Short norm, 15 */
  60. LIBG7221_DECL(Word16) div_s (Word16 var1, Word16 var2); /* Short division, 18 */
  61. LIBG7221_DECL(Word16) norm_l (Word32 L_var1); /* Long norm, 30 */
  62. /*
  63. Additional G.723.1 operators
  64. */
  65. LIBG7221_DECL(Word32) L_mls( Word32, Word16 ) ; /* Weight FFS; currently assigned 1 */
  66. LIBG7221_DECL(Word16) div_l( Word32, Word16 ) ; /* Weight FFS; currently assigned 1 */
  67. LIBG7221_DECL(Word16) i_mult(Word16 a, Word16 b); /* Weight FFS; currently assigned 1 */
  68. /*
  69. New shiftless operators, not used in G.729/G.723.1
  70. */
  71. LIBG7221_DECL(Word32) L_mult0(Word16 v1, Word16 v2); /* 32-bit Multiply w/o shift 1 */
  72. LIBG7221_DECL(Word32) L_mac0(Word32 L_v3, Word16 v1, Word16 v2); /* 32-bit Mac w/o shift 1 */
  73. LIBG7221_DECL(Word32) L_msu0(Word32 L_v3, Word16 v1, Word16 v2); /* 32-bit Msu w/o shift 1 */
  74. /*
  75. Additional G.722.1 operators
  76. */
  77. LIBG7221_DECL(UWord32) LU_shl (UWord32 L_var1, Word16 var2);
  78. LIBG7221_DECL(UWord32) LU_shr (UWord32 L_var1, Word16 var2);
  79. #define INCLUDE_UNSAFE 0
  80. /* Local */
  81. PJ_INLINE(Word16) saturate (Word32 L_var1);
  82. #if INCLUDE_UNSAFE
  83. extern Flag g7221_Overflow;
  84. extern Flag g7221_Carry;
  85. # define SET_OVERFLOW(n) g7221_Overflow = n
  86. # define SET_CARRY(n) g7221_Carry = n
  87. #else
  88. # define SET_OVERFLOW(n)
  89. # define SET_CARRY(n)
  90. # define GET_OVERFLOW() 0
  91. # define GET_CARRY() 0
  92. #endif
  93. #include "basic_op_i.h"
  94. #if PJMEDIA_LIBG7221_FUNCS_INLINED
  95. # include "basic_op.c"
  96. #endif
  97. #endif /* __BASIC_OP_H__ */