mathu.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2003 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$ASMMODE ATT}
  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. procedure SetSSECSR(w : dword);
  22. var
  23. _w : dword;
  24. begin
  25. _w:=w;
  26. asm
  27. ldmxcsr _w
  28. end;
  29. end;
  30. function GetSSECSR : dword;
  31. var
  32. _w : dword;
  33. begin
  34. asm
  35. stmxcsr _w
  36. end;
  37. result:=_w;
  38. end;
  39. function GetRoundMode: TFPURoundingMode;
  40. begin
  41. Result := TFPURoundingMode((Get8087CW shr 10) and 3);
  42. end;
  43. function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
  44. var
  45. CtlWord: Word;
  46. begin
  47. CtlWord := Get8087CW;
  48. Set8087CW((CtlWord and $F3FF) or (Ord(RoundMode) shl 10));
  49. Result := TFPURoundingMode((CtlWord shr 10) and 3);
  50. end;
  51. function GetPrecisionMode: TFPUPrecisionMode;
  52. begin
  53. Result := TFPUPrecisionMode((Get8087CW shr 8) and 3);
  54. end;
  55. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  56. var
  57. CtlWord: Word;
  58. begin
  59. CtlWord := Get8087CW;
  60. Set8087CW((CtlWord and $FCFF) or (Ord(Precision) shl 8));
  61. Result := TFPUPrecisionMode((CtlWord shr 8) and 3);
  62. end;
  63. function GetExceptionMask: TFPUExceptionMask;
  64. begin
  65. Result := TFPUExceptionMask(Longint(Get8087CW and $3F));
  66. end;
  67. function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  68. var
  69. CtlWord: Word;
  70. begin
  71. CtlWord := Get8087CW;
  72. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  73. Result := TFPUExceptionMask(Longint(CtlWord and $3F));
  74. end;
  75. procedure ClearExceptions(RaisePending: Boolean);assembler;
  76. asm
  77. cmpb $0,RaisePending
  78. je .Lclear
  79. fwait
  80. .Lclear:
  81. fnclex
  82. end;
  83. {
  84. $Log$
  85. Revision 1.5 2004-11-02 15:26:21 florian
  86. * fixed sse exception handling
  87. Revision 1.4 2004/05/09 15:47:56 peter
  88. * fixed wrong typecasts
  89. Revision 1.3 2003/10/31 09:20:11 mazen
  90. + assembler mode forced to ATT style for x86 cpu
  91. Revision 1.2 2003/10/26 15:58:05 florian
  92. * fixed arctan2 to handle x=0 correctly as well
  93. Revision 1.1 2003/04/24 09:16:31 florian
  94. * initial implementation with code from math.pp
  95. }