Commit c52ab6f585f7cbda2d436be8b0490000c1cef16e
1 parent
1b2ad2ec
fp: add floatXX_is_infinity(), floatXX_is_neg(), floatXX_is_zero()
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6050 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
105 additions
and
0 deletions
fpu/softfloat-native.h
... | ... | @@ -258,6 +258,21 @@ INLINE float32 float32_chs(float32 a) |
258 | 258 | return -a; |
259 | 259 | } |
260 | 260 | |
261 | +INLINE float32 float32_is_infinity(float32 a) | |
262 | +{ | |
263 | + return fpclassify(a) == FP_INFINITE; | |
264 | +} | |
265 | + | |
266 | +INLINE float32 float32_is_neg(float32 a) | |
267 | +{ | |
268 | + return a < 0.0; | |
269 | +} | |
270 | + | |
271 | +INLINE float32 float32_is_zero(float32 a) | |
272 | +{ | |
273 | + return fpclassify(a) == FP_ZERO; | |
274 | +} | |
275 | + | |
261 | 276 | INLINE float32 float32_scalbn(float32 a, int n) |
262 | 277 | { |
263 | 278 | return scalbnf(a, n); |
... | ... | @@ -350,6 +365,21 @@ INLINE float64 float64_chs(float64 a) |
350 | 365 | return -a; |
351 | 366 | } |
352 | 367 | |
368 | +INLINE float64 float64_is_infinity(float64 a) | |
369 | +{ | |
370 | + return fpclassify(a) == FP_INFINITE; | |
371 | +} | |
372 | + | |
373 | +INLINE float64 float64_is_neg(float64 a) | |
374 | +{ | |
375 | + return a < 0.0; | |
376 | +} | |
377 | + | |
378 | +INLINE float64 float64_is_zero(float64 a) | |
379 | +{ | |
380 | + return fpclassify(a) == FP_ZERO; | |
381 | +} | |
382 | + | |
353 | 383 | INLINE float64 float64_scalbn(float64 a, int n) |
354 | 384 | { |
355 | 385 | return scalbn(a, n); |
... | ... | @@ -437,6 +467,21 @@ INLINE floatx80 floatx80_chs(floatx80 a) |
437 | 467 | return -a; |
438 | 468 | } |
439 | 469 | |
470 | +INLINE floatx80 floatx80_is_infinity(floatx80 a) | |
471 | +{ | |
472 | + return fpclassify(a) == FP_INFINITE; | |
473 | +} | |
474 | + | |
475 | +INLINE floatx80 floatx80_is_neg(floatx80 a) | |
476 | +{ | |
477 | + return a < 0.0; | |
478 | +} | |
479 | + | |
480 | +INLINE floatx80 floatx80_is_zero(floatx80 a) | |
481 | +{ | |
482 | + return fpclassify(a) == FP_ZERO; | |
483 | +} | |
484 | + | |
440 | 485 | INLINE floatx80 floatx80_scalbn(floatx80 a, int n) |
441 | 486 | { |
442 | 487 | return scalbnl(a, n); | ... | ... |
fpu/softfloat.h
... | ... | @@ -281,6 +281,21 @@ INLINE float32 float32_chs(float32 a) |
281 | 281 | return make_float32(float32_val(a) ^ 0x80000000); |
282 | 282 | } |
283 | 283 | |
284 | +INLINE int float32_is_infinity(float32 a) | |
285 | +{ | |
286 | + return (float32_val(a) & 0x7fffffff) == 0x7ff80000; | |
287 | +} | |
288 | + | |
289 | +INLINE int float32_is_neg(float32 a) | |
290 | +{ | |
291 | + return float32_val(a) >> 31; | |
292 | +} | |
293 | + | |
294 | +INLINE int float32_is_zero(float32 a) | |
295 | +{ | |
296 | + return (float32_val(a) & 0x7fffffff) == 0; | |
297 | +} | |
298 | + | |
284 | 299 | #define float32_zero make_float32(0) |
285 | 300 | |
286 | 301 | /*---------------------------------------------------------------------------- |
... | ... | @@ -335,6 +350,21 @@ INLINE float64 float64_chs(float64 a) |
335 | 350 | return make_float64(float64_val(a) ^ 0x8000000000000000LL); |
336 | 351 | } |
337 | 352 | |
353 | +INLINE int float64_is_infinity(float64 a) | |
354 | +{ | |
355 | + return (float64_val(a) & 0x7fffffffffffffffLL ) == 0x7ff0000000000000LL; | |
356 | +} | |
357 | + | |
358 | +INLINE int float64_is_neg(float64 a) | |
359 | +{ | |
360 | + return float64_val(a) >> 63; | |
361 | +} | |
362 | + | |
363 | +INLINE int float64_is_zero(float64 a) | |
364 | +{ | |
365 | + return (float64_val(a) & 0x7fffffffffffffffLL) == 0; | |
366 | +} | |
367 | + | |
338 | 368 | #define float64_zero make_float64(0) |
339 | 369 | |
340 | 370 | #ifdef FLOATX80 |
... | ... | @@ -384,6 +414,21 @@ INLINE floatx80 floatx80_chs(floatx80 a) |
384 | 414 | return a; |
385 | 415 | } |
386 | 416 | |
417 | +INLINE int floatx80_is_infinity(floatx80 a) | |
418 | +{ | |
419 | + return (a.high & 0x7fff) == 0x7fff && a.low == 0; | |
420 | +} | |
421 | + | |
422 | +INLINE int floatx80_is_neg(floatx80 a) | |
423 | +{ | |
424 | + return a.high >> 15; | |
425 | +} | |
426 | + | |
427 | +INLINE int floatx80_is_zero(floatx80 a) | |
428 | +{ | |
429 | + return (a.high & 0x7fff) == 0 && a.low == 0; | |
430 | +} | |
431 | + | |
387 | 432 | #endif |
388 | 433 | |
389 | 434 | #ifdef FLOAT128 |
... | ... | @@ -435,6 +480,21 @@ INLINE float128 float128_chs(float128 a) |
435 | 480 | return a; |
436 | 481 | } |
437 | 482 | |
483 | +INLINE int float128_is_infinity(float128 a) | |
484 | +{ | |
485 | + return (a.high & 0x7fffffffffffffffLL) == 0x7fff000000000000LL && a.low == 0; | |
486 | +} | |
487 | + | |
488 | +INLINE int float128_is_neg(float128 a) | |
489 | +{ | |
490 | + return a.high >> 63; | |
491 | +} | |
492 | + | |
493 | +INLINE int float128_is_zero(float128 a) | |
494 | +{ | |
495 | + return (a.high & 0x7fffffffffffffffLL) == 0 && a.low == 0; | |
496 | +} | |
497 | + | |
438 | 498 | #endif |
439 | 499 | |
440 | 500 | #else /* CONFIG_SOFTFLOAT */ | ... | ... |