fpu_control.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* FPU control word bits. Mips version.
  2. Copyright (C) 1996-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Olaf Flebbe and Ralf Baechle.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library. If not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef _FPU_CONTROL_H
  17. #define _FPU_CONTROL_H
  18. /* MIPS FPU floating point control register bits.
  19. *
  20. * 31-25 -> floating point conditions code bits 7-1. These bits are only
  21. * available in MIPS IV.
  22. * 24 -> flush denormalized results to zero instead of
  23. * causing unimplemented operation exception. This bit is only
  24. * available for MIPS III and newer.
  25. * 23 -> Condition bit
  26. * 22-21 -> reserved for architecture implementers
  27. * 20 -> reserved (read as 0, write with 0)
  28. * 19 -> IEEE 754-2008 non-arithmetic ABS.fmt and NEG.fmt enable
  29. * 18 -> IEEE 754-2008 recommended NaN encoding enable
  30. * 17 -> cause bit for unimplemented operation
  31. * 16 -> cause bit for invalid exception
  32. * 15 -> cause bit for division by zero exception
  33. * 14 -> cause bit for overflow exception
  34. * 13 -> cause bit for underflow exception
  35. * 12 -> cause bit for inexact exception
  36. * 11 -> enable exception for invalid exception
  37. * 10 -> enable exception for division by zero exception
  38. * 9 -> enable exception for overflow exception
  39. * 8 -> enable exception for underflow exception
  40. * 7 -> enable exception for inexact exception
  41. * 6 -> flag invalid exception
  42. * 5 -> flag division by zero exception
  43. * 4 -> flag overflow exception
  44. * 3 -> flag underflow exception
  45. * 2 -> flag inexact exception
  46. * 1-0 -> rounding control
  47. *
  48. *
  49. * Rounding Control:
  50. * 00 - rounding to nearest (RN)
  51. * 01 - rounding toward zero (RZ)
  52. * 10 - rounding (up) toward plus infinity (RP)
  53. * 11 - rounding (down)toward minus infinity (RM)
  54. */
  55. #include <features.h>
  56. #ifdef __mips_soft_float
  57. #define _FPU_RESERVED 0xffffffff
  58. #define _FPU_DEFAULT 0x00000000
  59. typedef unsigned int fpu_control_t;
  60. #define _FPU_GETCW(cw) (cw) = 0
  61. #define _FPU_SETCW(cw) (void) (cw)
  62. extern fpu_control_t __fpu_control;
  63. #else /* __mips_soft_float */
  64. /* Masks for interrupts. */
  65. #define _FPU_MASK_V 0x0800 /* Invalid operation */
  66. #define _FPU_MASK_Z 0x0400 /* Division by zero */
  67. #define _FPU_MASK_O 0x0200 /* Overflow */
  68. #define _FPU_MASK_U 0x0100 /* Underflow */
  69. #define _FPU_MASK_I 0x0080 /* Inexact operation */
  70. /* Flush denormalized numbers to zero. */
  71. #define _FPU_FLUSH_TZ 0x1000000
  72. /* IEEE 754-2008 compliance control. */
  73. #define _FPU_ABS2008 0x80000
  74. #define _FPU_NAN2008 0x40000
  75. /* Rounding control. */
  76. #define _FPU_RC_NEAREST 0x0 /* RECOMMENDED */
  77. #define _FPU_RC_ZERO 0x1
  78. #define _FPU_RC_UP 0x2
  79. #define _FPU_RC_DOWN 0x3
  80. /* Mask for rounding control. */
  81. #define _FPU_RC_MASK 0x3
  82. #define _FPU_RESERVED 0xfe8c0000 /* Reserved bits in cw, incl ABS/NAN2008. */
  83. /* The fdlibm code requires strict IEEE double precision arithmetic,
  84. and no interrupts for exceptions, rounding to nearest. */
  85. #ifdef __mips_nan2008
  86. # define _FPU_DEFAULT 0x000C0000
  87. #else
  88. # define _FPU_DEFAULT 0x00000000
  89. #endif
  90. /* IEEE: same as above, but exceptions. */
  91. #ifdef __mips_nan2008
  92. # define _FPU_IEEE 0x000C0F80
  93. #else
  94. # define _FPU_IEEE 0x00000F80
  95. #endif
  96. /* Type of the control word. */
  97. typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__SI__)));
  98. /* Macros for accessing the hardware control word. */
  99. extern fpu_control_t __mips_fpu_getcw (void) __THROW;
  100. extern void __mips_fpu_setcw (fpu_control_t) __THROW;
  101. #ifdef __mips16
  102. # define _FPU_GETCW(cw) do { (cw) = __mips_fpu_getcw (); } while (0)
  103. # define _FPU_SETCW(cw) __mips_fpu_setcw (cw)
  104. #else
  105. # define _FPU_GETCW(cw) __asm__ volatile ("cfc1 %0,$31" : "=r" (cw))
  106. # define _FPU_SETCW(cw) __asm__ volatile ("ctc1 %0,$31" : : "r" (cw))
  107. #endif
  108. /* Default control word set at startup. */
  109. extern fpu_control_t __fpu_control;
  110. #endif /* __mips_soft_float */
  111. #endif /* fpu_control.h */