mathu.inc 2.5 KB

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