basemath.inc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2024 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 att}
  12. function GetRoundMode: TFPURoundingMode;
  13. begin
  14. Result := TFPURoundingMode((Get8087CW shr 10) and 3);
  15. end;
  16. function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
  17. var
  18. CtlWord: Word;
  19. begin
  20. softfloat_rounding_mode:=RoundMode;
  21. CtlWord := Get8087CW;
  22. Set8087CW((CtlWord and $F3FF) or (Ord(RoundMode) shl 10));
  23. if has_sse_support then
  24. SetMXCSR((GetMXCSR and $ffff9fff) or (dword(RoundMode) shl 13));
  25. Result := TFPURoundingMode((CtlWord shr 10) and 3);
  26. end;
  27. function GetPrecisionMode: TFPUPrecisionMode;
  28. begin
  29. Result := TFPUPrecisionMode((Get8087CW shr 8) and 3);
  30. end;
  31. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  32. var
  33. CtlWord: Word;
  34. begin
  35. CtlWord := Get8087CW;
  36. Set8087CW((CtlWord and $FCFF) or (Ord(Precision) shl 8));
  37. Result := TFPUPrecisionMode((CtlWord shr 8) and 3);
  38. end;
  39. function GetExceptionMask: TFPUExceptionMask;
  40. begin
  41. Result := TFPUExceptionMask(Longint(Get8087CW and $3F));
  42. end;
  43. function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  44. var
  45. CtlWord: Word;
  46. begin
  47. CtlWord := Get8087CW;
  48. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  49. if has_sse_support then
  50. SetMXCSR((GetMXCSR and $ffffe07f) or (dword(Mask) shl 7));
  51. Result := TFPUExceptionMask(Longint(CtlWord and $3F));
  52. end;
  53. procedure ClearExceptions(RaisePending: Boolean);assembler;
  54. asm
  55. cmpb $0,RaisePending
  56. je .Lclear
  57. fwait
  58. .Lclear:
  59. fnclex
  60. end;