fpu_control.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* FPU control word bits. i387 version.
  2. Copyright (C) 1993,1995-1998,2000,2001,2003 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Olaf Flebbe.
  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 1
  18. /* Here is the dirty part. Set up your 387 through the control word
  19. * (cw) register.
  20. *
  21. * 15-13 12 11-10 9-8 7-6 5 4 3 2 1 0
  22. * | reserved | IC | RC | PC | reserved | PM | UM | OM | ZM | DM | IM
  23. *
  24. * IM: Invalid operation mask
  25. * DM: Denormalized operand mask
  26. * ZM: Zero-divide mask
  27. * OM: Overflow mask
  28. * UM: Underflow mask
  29. * PM: Precision (inexact result) mask
  30. *
  31. * Mask bit is 1 means no interrupt.
  32. *
  33. * PC: Precision control
  34. * 11 - round to extended precision
  35. * 10 - round to double precision
  36. * 00 - round to single precision
  37. *
  38. * RC: Rounding control
  39. * 00 - rounding to nearest
  40. * 01 - rounding down (toward - infinity)
  41. * 10 - rounding up (toward + infinity)
  42. * 11 - rounding toward zero
  43. *
  44. * IC: Infinity control
  45. * That is for 8087 and 80287 only.
  46. *
  47. * The hardware default is 0x037f which we use.
  48. */
  49. #include <features.h>
  50. /* masking of interrupts */
  51. #define _FPU_MASK_IM 0x01
  52. #define _FPU_MASK_DM 0x02
  53. #define _FPU_MASK_ZM 0x04
  54. #define _FPU_MASK_OM 0x08
  55. #define _FPU_MASK_UM 0x10
  56. #define _FPU_MASK_PM 0x20
  57. /* precision control */
  58. #define _FPU_EXTENDED 0x300 /* libm requires double extended precision. */
  59. #define _FPU_DOUBLE 0x200
  60. #define _FPU_SINGLE 0x0
  61. /* rounding control */
  62. #define _FPU_RC_NEAREST 0x0 /* RECOMMENDED */
  63. #define _FPU_RC_DOWN 0x400
  64. #define _FPU_RC_UP 0x800
  65. #define _FPU_RC_ZERO 0xC00
  66. #define _FPU_RESERVED 0xF0C0 /* Reserved bits in cw */
  67. /* The fdlibm code requires strict IEEE double precision arithmetic,
  68. and no interrupts for exceptions, rounding to nearest. */
  69. #define _FPU_DEFAULT 0x037f
  70. /* IEEE: same as above. */
  71. #define _FPU_IEEE 0x037f
  72. /* Type of the control word. */
  73. typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__)));
  74. /* Macros for accessing the hardware control word.
  75. Note that the use of these macros is no sufficient anymore with
  76. recent hardware. Some floating point operations are executed in
  77. the SSE/SSE2 engines which have their own control and status register. */
  78. #define _FPU_GETCW(cw) __asm__ __volatile__ ("fnstcw %0" : "=m" (*&cw))
  79. #define _FPU_SETCW(cw) __asm__ __volatile__ ("fldcw %0" : : "m" (*&cw))
  80. #if 0
  81. /* Default control word set at startup. */
  82. extern fpu_control_t __fpu_control;
  83. #endif
  84. #endif /* fpu_control.h */