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