mathu.inc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2004 by Florian Klaempfl
  4. member of the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$ifndef WIN64}
  12. {$define FPC_MATH_HAS_ARCTAN2}
  13. function arctan2(y,x : float) : float;assembler;
  14. asm
  15. fldt y
  16. fldt x
  17. fpatan
  18. fwait
  19. end;
  20. {$endif WIN64}
  21. procedure SetSSECSR(w : dword);
  22. var
  23. _w : dword;
  24. begin
  25. _w:=w;
  26. asm
  27. ldmxcsr _w
  28. end;
  29. end;
  30. function GetSSECSR : dword;
  31. var
  32. _w : dword;
  33. begin
  34. asm
  35. stmxcsr _w
  36. end;
  37. result:=_w;
  38. end;
  39. function GetRoundMode: TFPURoundingMode;
  40. begin
  41. Result := TFPURoundingMode((Get8087CW shr 10) and 3);
  42. end;
  43. function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
  44. var
  45. CtlWord: Word;
  46. begin
  47. CtlWord := Get8087CW;
  48. Set8087CW((CtlWord and $F3FF) or (Ord(RoundMode) shl 10));
  49. Result := TFPURoundingMode((CtlWord shr 10) and 3);
  50. end;
  51. function GetPrecisionMode: TFPUPrecisionMode;
  52. begin
  53. Result := TFPUPrecisionMode((Get8087CW shr 8) and 3);
  54. end;
  55. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  56. var
  57. CtlWord: Word;
  58. begin
  59. CtlWord := Get8087CW;
  60. Set8087CW((CtlWord and $FCFF) or (Ord(Precision) shl 8));
  61. Result := TFPUPrecisionMode((CtlWord shr 8) and 3);
  62. end;
  63. function GetExceptionMask: TFPUExceptionMask;
  64. begin
  65. Result := TFPUExceptionMask(dword(Get8087CW and $3F));
  66. end;
  67. function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  68. var
  69. CtlWord: Word;
  70. begin
  71. CtlWord := Get8087CW;
  72. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  73. Result := TFPUExceptionMask(dword(CtlWord and $3F));
  74. end;
  75. procedure ClearExceptions(RaisePending: Boolean);assembler;
  76. asm
  77. cmpb $0,RaisePending
  78. je .Lclear
  79. fwait
  80. .Lclear:
  81. fnclex
  82. end;