mathu.inc 2.2 KB

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