Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
2.2 KiB

  1. /***
  2. *fpctrl.c - fp low level control and status routines
  3. *
  4. * Copyright (c) 1985-2000, Microsoft Corporation
  5. *
  6. *Purpose:
  7. * IEEE control and status routines for internal use.
  8. * These routines use machine specific constants while _controlfp,
  9. * _statusfp, and _clearfp use an abstracted control/status word
  10. *
  11. *Revision History:
  12. *
  13. * 03-31-92 GDP written
  14. * 05-12-92 GJF Rewrote fdivr as fdivrp st(1),st to work around C8-32
  15. * assertions.
  16. *
  17. */
  18. #include <trans.h>
  19. extern unsigned int _get_fpsr(void);
  20. extern void _set_fpsr(unsigned int);
  21. extern void _fclrf(void);
  22. /*** _statfp
  23. *() -
  24. *
  25. *Purpose:
  26. * return user status word
  27. *
  28. *Entry:
  29. *
  30. *Exit:
  31. *
  32. *Exceptions:
  33. *
  34. *******************************************************************************/
  35. uintptr_t _statfp()
  36. {
  37. unsigned int status;
  38. status = _get_fpsr();
  39. status &= 0x3f;
  40. return (uintptr_t)status;
  41. }
  42. /*** _clrfp
  43. *() -
  44. *
  45. *Purpose:
  46. * return user status word and clear status
  47. *
  48. *Entry:
  49. *
  50. *Exit:
  51. *
  52. *Exceptions:
  53. *
  54. *******************************************************************************/
  55. uintptr_t _clrfp()
  56. {
  57. unsigned int status;
  58. status = _get_fpsr();
  59. status &= 0x3f;
  60. _fclrf();
  61. return (uintptr_t)status;
  62. }
  63. /*** _ctrlfp
  64. *() -
  65. *
  66. *Purpose:
  67. * return and set user control word
  68. *
  69. *Entry:
  70. *
  71. *Exit:
  72. *
  73. *Exceptions:
  74. *
  75. *******************************************************************************/
  76. uintptr_t _ctrlfp(uintptr_t newctrl, uintptr_t _mask)
  77. {
  78. unsigned int oldCw;
  79. unsigned int newCw;
  80. unsigned int tmp;
  81. oldCw = _get_fpsr();
  82. tmp = oldCw;
  83. oldCw >>=7;
  84. oldCw = (oldCw & 0x3f) | ((oldCw & 0xc0) << 4) | 0x300;
  85. newCw = ((unsigned int)(newctrl & _mask) | (oldCw & (unsigned int)~_mask));
  86. newCw |= (oldCw & ~(unsigned int)0x0001f3f);
  87. newCw = ((((newCw & 0x3f) <<7) | ((newCw & 0xc00) << 3)) & 0x7f80) | (tmp & (~0x7f80));
  88. _set_fpsr(newCw);
  89. return (uintptr_t)oldCw;
  90. }
  91. /*** _set_statfp
  92. *() -
  93. *
  94. *Purpose:
  95. * force selected exception flags to 1
  96. *
  97. *Entry:
  98. *
  99. *Exit:
  100. *
  101. *Exceptions:
  102. *
  103. *******************************************************************************/
  104. void _set_statfp(uintptr_t sw)
  105. {
  106. unsigned int status;
  107. status = _get_fpsr();
  108. status |= (sw&0x3f);
  109. _set_fpsr(status);
  110. }