mathu.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. {$define FPC_MATH_HAS_DIVMOD}
  50. procedure DivMod(Dividend: Integer; Divisor: Word; var Result, Remainder: Word);assembler;
  51. asm
  52. pushl %edi
  53. movzwl %dx,%edi
  54. cltd
  55. idiv %edi
  56. movw %ax,(%ecx)
  57. movl Remainder,%ecx
  58. movw %dx,(%ecx)
  59. popl %edi
  60. end;
  61. procedure DivMod(Dividend: Integer; Divisor: Word; var Result, Remainder: SmallInt);assembler;
  62. asm
  63. pushl %edi
  64. movzwl %dx,%edi
  65. cltd
  66. idiv %edi
  67. movw %ax,(%ecx)
  68. movl Remainder,%ecx
  69. movw %dx,(%ecx)
  70. popl %edi
  71. end;
  72. procedure DivMod(Dividend: DWord; Divisor: DWord; var Result, Remainder: DWord);assembler;
  73. asm
  74. pushl %edi
  75. movl %edx,%edi
  76. xorl %edx,%edx
  77. div %edi
  78. movl %eax,(%ecx)
  79. movl Remainder,%ecx
  80. movl %edx,(%ecx)
  81. popl %edi
  82. end;
  83. procedure DivMod(Dividend: Integer; Divisor: Integer; var Result, Remainder: Integer);assembler;
  84. asm
  85. pushl %edi
  86. movl %edx,%edi
  87. cltd
  88. idiv %edi
  89. movl %eax,(%ecx)
  90. movl Remainder,%ecx
  91. movl %edx,(%ecx)
  92. popl %edi
  93. end;
  94. function GetRoundMode: TFPURoundingMode;
  95. begin
  96. Result := TFPURoundingMode((Get8087CW shr 10) and 3);
  97. end;
  98. function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;
  99. var
  100. CtlWord: Word;
  101. begin
  102. CtlWord := Get8087CW;
  103. Set8087CW((CtlWord and $F3FF) or (Ord(RoundMode) shl 10));
  104. if has_sse_support then
  105. SetSSECSR((GetSSECSR and $ffff9fff) or (dword(RoundMode) shl 13));
  106. Result := TFPURoundingMode((CtlWord shr 10) and 3);
  107. end;
  108. function GetPrecisionMode: TFPUPrecisionMode;
  109. begin
  110. Result := TFPUPrecisionMode((Get8087CW shr 8) and 3);
  111. end;
  112. function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;
  113. var
  114. CtlWord: Word;
  115. begin
  116. CtlWord := Get8087CW;
  117. Set8087CW((CtlWord and $FCFF) or (Ord(Precision) shl 8));
  118. Result := TFPUPrecisionMode((CtlWord shr 8) and 3);
  119. end;
  120. function GetExceptionMask: TFPUExceptionMask;
  121. begin
  122. Result := TFPUExceptionMask(Longint(Get8087CW and $3F));
  123. end;
  124. function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  125. var
  126. CtlWord: Word;
  127. begin
  128. CtlWord := Get8087CW;
  129. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  130. if has_sse_support then
  131. SetSSECSR((GetSSECSR and $ffffe07f) or (dword(Mask) shl 7));
  132. softfloat_exception_mask:=dword(Mask);
  133. Result := TFPUExceptionMask(Longint(CtlWord and $3F));
  134. end;
  135. procedure ClearExceptions(RaisePending: Boolean);assembler;
  136. asm
  137. cmpb $0,RaisePending
  138. je .Lclear
  139. fwait
  140. .Lclear:
  141. fnclex
  142. end;