00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef FIXED_ARM_H
00036 #define FIXED_ARM_H
00037
00038 #define SHR(a,shift) ((a) >> (shift))
00039 #define SHL(a,shift) ((a) << (shift))
00040
00041 #define SATURATE(x,a) ((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))
00042
00043
00044 #define ADD16(a,b) ((short)((short)(a)+(short)(b)))
00045 #define SUB16(a,b) ((a)-(b))
00046 #define ADD32(a,b) ((a)+(b))
00047 #define SUB32(a,b) ((a)-(b))
00048 #define ADD64(a,b) ((a)+(b))
00049
00050 #define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift))
00051
00052
00053 #define MULT16_16_16(a,b) (((short)(a))*((short)(b)))
00054
00055 static inline spx_word32_t MULT16_16(spx_word16_t x, spx_word16_t y) {
00056 int res;
00057 asm ("smulbb %0,%1,%2;\n"
00058 : "=&r"(res)
00059 : "%r"(x),"r"(y));
00060 return(res);
00061 }
00062
00063 static inline spx_word32_t MAC16_16(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
00064 int res;
00065 asm ("smlabb %0,%1,%2,%3;\n"
00066 : "=&r"(res)
00067 : "%r"(x),"r"(y),"r"(a));
00068 return(res);
00069 }
00070
00071 #define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12))
00072 #define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))
00073 #define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14))
00074
00075 static inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) {
00076 int res;
00077 asm ("smulwb %0,%1,%2;\n"
00078 : "=&r"(res)
00079 : "%r"(y<<1),"r"(x));
00080 return(res);
00081 }
00082 static inline spx_word32_t MAC16_32_Q15(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
00083 int res;
00084 asm ("smlawb %0,%1,%2,%3;\n"
00085 : "=&r"(res)
00086 : "%r"(y<<1),"r"(x),"r"(a));
00087 return(res);
00088 }
00089 static inline spx_word32_t MULT16_32_Q11(spx_word16_t x, spx_word32_t y) {
00090 int res;
00091 asm ("smulwb %0,%1,%2;\n"
00092 : "=&r"(res)
00093 : "%r"(y<<5),"r"(x));
00094 return(res);
00095 }
00096 static inline spx_word32_t MAC16_32_Q11(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
00097 int res;
00098 asm ("smlawb %0,%1,%2,%3;\n"
00099 : "=&r"(res)
00100 : "%r"(y<<5),"r"(x),"r"(a));
00101 return(res);
00102 }
00103
00104 #define MAC16_16_Q11(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),11)))
00105
00106 #define MULT16_16_Q11(a,b) (SHR(MULT16_16((a),(b)),11))
00107 #define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13))
00108 #define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14))
00109 #define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15))
00110
00111 #define MULT16_16_P13(a,b) (SHR(ADD32(4096,MULT16_16((a),(b))),13))
00112 #define MULT16_16_P14(a,b) (SHR(ADD32(8192,MULT16_16((a),(b))),14))
00113 #define MULT16_16_P15(a,b) (SHR(ADD32(16384,MULT16_16((a),(b))),15))
00114
00115 #define MUL_16_32_R15(a,bh,bl) ADD32(MULT16_16((a),(bh)), SHR(MULT16_16((a),(bl)),15))
00116
00117
00118
00119 #define DIV32_16(a,b) ((short)(((signed int)(a))/((short)(b))))
00120 #define DIV32(a,b) (((signed int)(a))/((signed int)(b)))
00121
00122
00123
00124 #endif