mathu.inc 3.6 KB

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