basemath.inc 1.9 KB

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