mathu.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. {$define FPC_MATH_HAS_SINCOS}
  23. {$ifdef FPC_HAS_TYPE_EXTENDED}
  24. procedure sincos(theta : extended;out sinus,cosinus : extended);assembler;
  25. asm
  26. fldt theta
  27. fsincos
  28. {$ifdef WIN64}
  29. fstpl (%r8)
  30. fstpl (%rdx)
  31. {$else WIN64}
  32. fstpt (%rsi)
  33. fstpt (%rdi)
  34. {$endif WIN64}
  35. fwait
  36. end;
  37. {$endif FPC_HAS_TYPE_EXTENDED}
  38. {$asmmode intel}
  39. procedure sincos(theta : double;out sinus,cosinus : double);assembler;
  40. var
  41. t : double;
  42. asm
  43. movsd qword ptr t,xmm0
  44. fld qword ptr t
  45. fsincos
  46. fstp qword ptr [cosinus]
  47. fstp qword ptr [sinus]
  48. fwait
  49. end;
  50. procedure sincos(theta : single;out sinus,cosinus : single);assembler;
  51. var
  52. t : single;
  53. asm
  54. movss dword ptr t,xmm0
  55. fld dword ptr t
  56. fsincos
  57. fstp dword ptr [cosinus]
  58. fstp dword ptr [sinus]
  59. fwait
  60. end;
  61. {$asmmode gas}
  62. function GetRoundMode: TFPURoundingMode;
  63. begin
  64. {$ifndef FPC_HAS_TYPE_EXTENDED}
  65. Result:=TFPURoundingMode((GetSSECSR shr 13) and $3);
  66. {$else win64}
  67. Result:=TFPURoundingMode((Get8087CW shr 10) and $3);
  68. {$endif win64}
  69. end;
  70. function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
  71. var
  72. CtlWord: Word;
  73. begin
  74. CtlWord:=Get8087CW;
  75. Set8087CW((CtlWord and $F3FF) or (Ord(RoundMode) shl 10));
  76. SetSSECSR((GetSSECSR and $ffff9fff) or (dword(RoundMode) shl 13));
  77. Result:=GetRoundMode;
  78. end;
  79. function GetPrecisionMode: TFPUPrecisionMode;
  80. begin
  81. Result:=TFPUPrecisionMode((Get8087CW shr 8) and 3);
  82. end;
  83. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  84. var
  85. CtlWord: Word;
  86. begin
  87. CtlWord:=Get8087CW;
  88. Set8087CW((CtlWord and $FCFF) or (Ord(Precision) shl 8));
  89. Result:=TFPUPrecisionMode((CtlWord shr 8) and 3);
  90. end;
  91. function GetExceptionMask: TFPUExceptionMask;
  92. begin
  93. {$ifndef FPC_HAS_TYPE_EXTENDED}
  94. Result:=TFPUExceptionMask((GetSSECSR shr 7) and $3f);
  95. {$else win64}
  96. Result:=TFPUExceptionMask(dword(Get8087CW and $3F));
  97. {$endif win64}
  98. end;
  99. function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  100. var
  101. CtlWord: Word;
  102. begin
  103. CtlWord:=Get8087CW;
  104. Set8087CW((CtlWord and $FFC0) or Byte(Longint(Mask)));
  105. SetSSECSR((GetSSECSR and $ffffe07f) or (dword(Mask) shl 7));
  106. softfloat_exception_mask:=dword(Mask);
  107. Result:=GetExceptionMask;
  108. end;
  109. procedure ClearExceptions(RaisePending: Boolean);assembler;
  110. asm
  111. cmpb $0,RaisePending
  112. je .Lclear
  113. fwait
  114. .Lclear:
  115. fnclex
  116. end;