basemath.inc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. {$asmmode gas}
  12. function GetRoundMode: TFPURoundingMode;
  13. begin
  14. {$ifndef FPC_HAS_TYPE_EXTENDED}
  15. Result:=TFPURoundingMode((GetMXCSR shr 13) and $3);
  16. {$else win64}
  17. Result:=TFPURoundingMode((Get8087CW shr 10) and $3);
  18. {$endif win64}
  19. end;
  20. function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
  21. var
  22. CtlWord: Word;
  23. SSECSR: dword;
  24. begin
  25. CtlWord:=Get8087CW;
  26. SSECSR:=GetMXCSR;
  27. softfloat_rounding_mode:=RoundMode;
  28. Set8087CW((CtlWord and $F3FF) or (Ord(RoundMode) shl 10));
  29. SetMXCSR((SSECSR and $ffff9fff) or (dword(RoundMode) shl 13));
  30. {$ifdef FPC_HAS_TYPE_EXTENDED}
  31. Result:=TFPURoundingMode((CtlWord shr 10) and 3);
  32. {$else}
  33. Result:=TFPURoundingMode((SSECSR shr 13) and 3);
  34. {$endif FPC_HAS_TYPE_EXTENDED}
  35. end;
  36. function GetPrecisionMode: TFPUPrecisionMode;
  37. begin
  38. Result:=TFPUPrecisionMode((Get8087CW shr 8) and 3);
  39. end;
  40. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  41. var
  42. CtlWord: Word;
  43. begin
  44. CtlWord:=Get8087CW;
  45. Set8087CW((CtlWord and $FCFF) or (Ord(Precision) shl 8));
  46. Result:=TFPUPrecisionMode((CtlWord shr 8) and 3);
  47. end;
  48. function GetExceptionMask: TFPUExceptionMask;
  49. begin
  50. {$ifndef FPC_HAS_TYPE_EXTENDED}
  51. Result:=TFPUExceptionMask(dword((GetMXCSR shr 7) and $3f));
  52. {$else win64}
  53. Result:=TFPUExceptionMask(dword(Get8087CW and $3F));
  54. {$endif win64}
  55. end;
  56. function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  57. var
  58. CtlWord: Word;
  59. SSECSR: dword;
  60. begin
  61. CtlWord:=Get8087CW;
  62. SSECSR:=GetMXCSR;
  63. Set8087CW((CtlWord and $FFC0) or Byte(Longint(Mask)));
  64. SetMXCSR((SSECSR and $ffffe07f) or (dword(Mask) shl 7));
  65. {$ifdef FPC_HAS_TYPE_EXTENDED}
  66. Result:=TFPUExceptionMask(dword(CtlWord and $3F));
  67. {$else}
  68. Result:=TFPUExceptionMask((SSECSR shr 7) and $3F);
  69. {$endif FPC_HAS_TYPE_EXTENDED}
  70. end;
  71. procedure ClearExceptions(RaisePending: Boolean);assembler;
  72. asm
  73. cmpb $0,RaisePending
  74. je .Lclear
  75. fwait
  76. .Lclear:
  77. fnclex
  78. end;