mathu.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. {$ASMMODE ATT}
  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. {$define FPC_MATH_HAS_SINCOS}
  21. procedure sincos(theta : float;out sinus,cosinus : float);assembler;
  22. asm
  23. fldt theta
  24. fsincos
  25. {$ifndef regcall}
  26. movl sinus, %eax
  27. movl cosinus, %edx
  28. {$endif}
  29. fstpt (%edx)
  30. fstpt (%eax)
  31. fwait
  32. end;
  33. {$define FPC_MATH_HAS_TAN}
  34. function tan(x : float) : float;assembler;
  35. asm
  36. fldt X
  37. fptan
  38. fstp %st
  39. fwait
  40. end;
  41. {$define FPC_MATH_HAS_COTAN}
  42. function cotan(x : float) : float;assembler;
  43. asm
  44. fldt X
  45. fptan
  46. fdivp %st,%st(1)
  47. fwait
  48. end;
  49. function GetRoundMode: TFPURoundingMode;
  50. begin
  51. Result := TFPURoundingMode((Get8087CW shr 10) and 3);
  52. end;
  53. function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
  54. var
  55. CtlWord: Word;
  56. begin
  57. CtlWord := Get8087CW;
  58. Set8087CW((CtlWord and $F3FF) or (Ord(RoundMode) shl 10));
  59. if has_sse_support then
  60. SetSSECSR((GetSSECSR and $ffff9fff) or (dword(RoundMode) shl 13));
  61. Result := TFPURoundingMode((CtlWord shr 10) and 3);
  62. end;
  63. function GetPrecisionMode: TFPUPrecisionMode;
  64. begin
  65. Result := TFPUPrecisionMode((Get8087CW shr 8) and 3);
  66. end;
  67. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  68. var
  69. CtlWord: Word;
  70. begin
  71. CtlWord := Get8087CW;
  72. Set8087CW((CtlWord and $FCFF) or (Ord(Precision) shl 8));
  73. Result := TFPUPrecisionMode((CtlWord shr 8) and 3);
  74. end;
  75. function GetExceptionMask: TFPUExceptionMask;
  76. begin
  77. Result := TFPUExceptionMask(Longint(Get8087CW and $3F));
  78. end;
  79. function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  80. var
  81. CtlWord: Word;
  82. begin
  83. CtlWord := Get8087CW;
  84. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  85. if has_sse_support then
  86. SetSSECSR((GetSSECSR and $ffffe07f) or (dword(Mask) shl 7));
  87. softfloat_exception_mask:=dword(Mask);
  88. Result := TFPUExceptionMask(Longint(CtlWord and $3F));
  89. end;
  90. procedure ClearExceptions(RaisePending: Boolean);assembler;
  91. asm
  92. cmpb $0,RaisePending
  93. je .Lclear
  94. fwait
  95. .Lclear:
  96. fnclex
  97. end;