sp_2008class.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * IEEE754 floating point arithmetic
  3. * single precision: CLASS.f
  4. * FPR[fd] = class(FPR[fs])
  5. *
  6. * MIPS floating point support
  7. * Copyright (C) 2015 Imagination Technologies, Ltd.
  8. * Author: Markos Chandras <markos.chandras@imgtec.com>
  9. *
  10. * This program is free software; you can distribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; version 2 of the License.
  13. */
  14. #include "ieee754sp.h"
  15. int ieee754sp_2008class(union ieee754sp x)
  16. {
  17. COMPXSP;
  18. EXPLODEXSP;
  19. /*
  20. * 10 bit mask as follows:
  21. *
  22. * bit0 = SNAN
  23. * bit1 = QNAN
  24. * bit2 = -INF
  25. * bit3 = -NORM
  26. * bit4 = -DNORM
  27. * bit5 = -ZERO
  28. * bit6 = INF
  29. * bit7 = NORM
  30. * bit8 = DNORM
  31. * bit9 = ZERO
  32. */
  33. switch(xc) {
  34. case IEEE754_CLASS_SNAN:
  35. return 0x01;
  36. case IEEE754_CLASS_QNAN:
  37. return 0x02;
  38. case IEEE754_CLASS_INF:
  39. return 0x04 << (xs ? 0 : 4);
  40. case IEEE754_CLASS_NORM:
  41. return 0x08 << (xs ? 0 : 4);
  42. case IEEE754_CLASS_DNORM:
  43. return 0x10 << (xs ? 0 : 4);
  44. case IEEE754_CLASS_ZERO:
  45. return 0x20 << (xs ? 0 : 4);
  46. default:
  47. pr_err("Unknown class: %d\n", xc);
  48. return 0;
  49. }
  50. }