- Timestamp:
- Nov 23, 2006 10:19:46 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-codec/speex/pseudofloat.h
r628 r823 37 37 38 38 #include "misc.h" 39 #include "math_approx.h" 39 40 #include <math.h> 40 41 … … 65 66 return r; 66 67 } 67 while (x>32767) 68 { 69 x >>= 1; 70 /*x *= .5;*/ 71 e++; 72 } 73 while (x<16383) 74 { 75 x <<= 1; 76 /*x *= 2;*/ 77 e--; 78 } 68 e = spx_ilog2(ABS32(x))-14; 69 x = VSHR32(x, e); 79 70 if (sign) 80 71 { … … 167 158 { 168 159 if (a.m==0) 169 return b.m <0;160 return b.m>0; 170 161 else if (b.m==0) 171 return a.m >0;162 return a.m<0; 172 163 if ((a).e > (b).e) 173 164 return ((a).m>>1) < ((b).m>>MIN(15,(a).e-(b).e+1)); … … 205 196 } 206 197 198 static inline spx_float_t FLOAT_AMULT(spx_float_t a, spx_float_t b) 199 { 200 spx_float_t r; 201 r.m = (spx_int16_t)((spx_int32_t)(a).m*(b).m>>15); 202 r.e = (a).e+(b).e+15; 203 return r; 204 } 205 207 206 208 207 static inline spx_float_t FLOAT_SHL(spx_float_t a, int b) … … 217 216 { 218 217 if (a.e<0) 219 return EXTRACT16((EXTEND32(a.m)+( 1<<(-a.e-1)))>>-a.e);218 return EXTRACT16((EXTEND32(a.m)+(EXTEND32(1)<<(-a.e-1)))>>-a.e); 220 219 else 221 220 return a.m<<a.e; 222 221 } 223 222 223 static inline spx_int32_t FLOAT_EXTRACT32(spx_float_t a) 224 { 225 if (a.e<0) 226 return (EXTEND32(a.m)+(EXTEND32(1)<<(-a.e-1)))>>-a.e; 227 else 228 return EXTEND32(a.m)<<a.e; 229 } 230 224 231 static inline spx_int32_t FLOAT_MUL32(spx_float_t a, spx_word32_t b) 225 232 { 226 if (a.e<-15) 227 return SHR32(MULT16_32_Q15(a.m, b),-a.e-15); 228 else 229 return SHL32(MULT16_32_Q15(a.m, b),15+a.e); 233 return VSHR32(MULT16_32_Q15(a.m, b),-a.e-15); 230 234 } 231 235 232 236 static inline spx_float_t FLOAT_MUL32U(spx_word32_t a, spx_word32_t b) 233 237 { 238 int e1, e2; 239 spx_float_t r; 240 if (a==0 || b==0) 241 { 242 return FLOAT_ZERO; 243 } 244 e1 = spx_ilog2(ABS32(a)); 245 a = VSHR32(a, e1-14); 246 e2 = spx_ilog2(ABS32(b)); 247 b = VSHR32(b, e2-14); 248 r.m = MULT16_16_Q15(a,b); 249 r.e = e1+e2-13; 250 return r; 251 } 252 253 /* Do NOT attempt to divide by a negative number */ 254 static inline spx_float_t FLOAT_DIV32_FLOAT(spx_word32_t a, spx_float_t b) 255 { 234 256 int e=0; 235 257 spx_float_t r; 236 /* FIXME: Handle the sign */237 258 if (a==0) 238 259 { 239 260 return FLOAT_ZERO; 240 261 } 241 while (a>32767) 262 e = spx_ilog2(ABS32(a))-spx_ilog2(b.m-1)-15; 263 a = VSHR32(a, e); 264 if (ABS32(a)>=SHL32(EXTEND32(b.m-1),15)) 242 265 { 243 266 a >>= 1; 244 267 e++; 245 268 } 246 while (a<16384) 247 { 248 a <<= 1; 249 e--; 250 } 251 while (b>32767) 252 { 253 b >>= 1; 254 e++; 255 } 256 while (b<16384) 257 { 258 b <<= 1; 259 e--; 260 } 261 r.m = MULT16_16_Q15(a,b); 262 r.e = e+15; 263 return r; 264 } 265 266 static inline spx_float_t FLOAT_DIV32_FLOAT(spx_word32_t a, spx_float_t b) 267 { 268 int e=0; 269 spx_float_t r; 270 /* FIXME: Handle the sign */ 269 r.m = DIV32_16(a,b.m); 270 r.e = e-b.e; 271 return r; 272 } 273 274 275 /* Do NOT attempt to divide by a negative number */ 276 static inline spx_float_t FLOAT_DIV32(spx_word32_t a, spx_word32_t b) 277 { 278 int e0=0,e=0; 279 spx_float_t r; 271 280 if (a==0) 272 281 { 273 282 return FLOAT_ZERO; 274 283 } 275 while (a<SHL32(EXTEND32(b.m),14)) 276 { 277 a <<= 1; 278 e--; 279 } 280 while (a>=SHL32(EXTEND32(b.m-1),15)) 284 if (b>32767) 285 { 286 e0 = spx_ilog2(b)-14; 287 b = VSHR32(b, e0); 288 e0 = -e0; 289 } 290 e = spx_ilog2(ABS32(a))-spx_ilog2(b-1)-15; 291 a = VSHR32(a, e); 292 if (ABS32(a)>=SHL32(EXTEND32(b-1),15)) 281 293 { 282 294 a >>= 1; 283 295 e++; 284 296 } 285 r.m = DIV32_16(a,b.m); 286 r.e = e-b.e; 287 return r; 288 } 289 290 291 static inline spx_float_t FLOAT_DIV32(spx_word32_t a, spx_word32_t b) 292 { 293 int e=0; 294 spx_float_t r; 295 /* FIXME: Handle the sign */ 296 if (a==0) 297 { 298 return FLOAT_ZERO; 299 } 300 while (b>32767) 301 { 302 b >>= 1; 303 e--; 304 } 305 while (a<SHL32(b,14)) 306 { 307 a <<= 1; 308 e--; 309 } 310 while (a>=SHL32(b-1,15)) 311 { 312 a >>= 1; 313 e++; 314 } 297 e += e0; 315 298 r.m = DIV32_16(a,b); 316 299 r.e = e; … … 318 301 } 319 302 303 /* Do NOT attempt to divide by a negative number */ 320 304 static inline spx_float_t FLOAT_DIVU(spx_float_t a, spx_float_t b) 321 305 { … … 323 307 spx_int32_t num; 324 308 spx_float_t r; 309 if (b.m<=0) 310 { 311 speex_warning_int("Attempted to divide by", b.m); 312 return FLOAT_ONE; 313 } 325 314 num = a.m; 315 a.m = ABS16(a.m); 326 316 while (a.m >= b.m) 327 317 { … … 332 322 r.m = DIV32_16(num,b.m); 333 323 r.e = a.e-b.e-15+e; 324 return r; 325 } 326 327 static inline spx_float_t FLOAT_SQRT(spx_float_t a) 328 { 329 spx_float_t r; 330 spx_int32_t m; 331 m = SHL32(EXTEND32(a.m), 14); 332 r.e = a.e - 14; 333 if (r.e & 1) 334 { 335 r.e -= 1; 336 m <<= 1; 337 } 338 r.e >>= 1; 339 r.m = spx_sqrt(m); 334 340 return r; 335 341 } … … 343 349 #define PSEUDOFLOAT(x) (x) 344 350 #define FLOAT_MULT(a,b) ((a)*(b)) 351 #define FLOAT_AMULT(a,b) ((a)*(b)) 345 352 #define FLOAT_MUL32(a,b) ((a)*(b)) 346 353 #define FLOAT_DIV32(a,b) ((a)/(b)) 347 354 #define FLOAT_EXTRACT16(a) (a) 355 #define FLOAT_EXTRACT32(a) (a) 348 356 #define FLOAT_ADD(a,b) ((a)+(b)) 349 357 #define FLOAT_SUB(a,b) ((a)-(b)) … … 355 363 #define FLOAT_GT(a,b) ((a)>(b)) 356 364 #define FLOAT_DIVU(a,b) ((a)/(b)) 365 #define FLOAT_SQRT(a) (spx_sqrt(a)) 357 366 358 367 #endif
Note: See TracChangeset
for help on using the changeset viewer.