Browse Source

* fixed sse exception handling

florian 21 years ago
parent
commit
07c28067aa
6 changed files with 91 additions and 18 deletions
  1. 27 2
      rtl/i386/mathu.inc
  2. 9 2
      rtl/i386/mathuh.inc
  3. 5 4
      rtl/linux/x86_64/prt0.as
  4. 27 2
      rtl/x86_64/mathu.inc
  5. 9 2
      rtl/x86_64/mathuh.inc
  6. 14 6
      rtl/x86_64/x86_64.inc

+ 27 - 2
rtl/i386/mathu.inc

@@ -24,6 +24,28 @@ function arctan2(y,x : float) : float;assembler;
   end;
 
 
+procedure SetSSECSR(w : dword);
+  var
+    _w : dword;
+  begin
+    _w:=w;
+    asm
+      ldmxcsr _w
+    end;    
+  end;
+
+
+function GetSSECSR : dword;
+  var
+    _w : dword;
+  begin
+    asm
+      stmxcsr _w
+    end;
+    result:=_w;
+  end;
+
+
 function GetRoundMode: TFPURoundingMode;
 begin
   Result := TFPURoundingMode((Get8087CW shr 10) and 3);
@@ -77,7 +99,10 @@ end;
 
 {
   $Log$
-  Revision 1.4  2004-05-09 15:47:56  peter
+  Revision 1.5  2004-11-02 15:26:21  florian
+    * fixed sse exception handling
+
+  Revision 1.4  2004/05/09 15:47:56  peter
     * fixed wrong typecasts
 
   Revision 1.3  2003/10/31 09:20:11  mazen
@@ -88,4 +113,4 @@ end;
 
   Revision 1.1  2003/04/24 09:16:31  florian
     * initial implementation with code from math.pp
-}
+}

+ 9 - 2
rtl/i386/mathuh.inc

@@ -29,8 +29,15 @@ function GetExceptionMask: TFPUExceptionMask;
 function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
 procedure ClearExceptions(RaisePending: Boolean {$ifndef VER1_0}=true{$endif});
 
+procedure SetSSECSR(w : dword);
+function GetSSECSR : dword;
+
+
 {
   $Log$
-  Revision 1.1  2003-04-24 09:16:31  florian
+  Revision 1.2  2004-11-02 15:26:21  florian
+    * fixed sse exception handling
+
+  Revision 1.1  2003/04/24 09:16:31  florian
     * initial implementation with code from math.pp
-}
+}

+ 5 - 4
rtl/linux/x86_64/prt0.as

@@ -49,8 +49,6 @@ _start:
         movq     %rax,operatingsystem_parameter_envp
         andq     $~15,%rsp            /* Align the stack to a 16 byte boundary to follow the ABI.  */
 
-/* !!!! CPU initialization? */
-
         xorq    %rbp, %rbp
         call    PASCALMAIN
 	jmp	_haltproc
@@ -95,7 +93,10 @@ __data_start:
 
 #
 # $Log$
-# Revision 1.8  2004-07-03 21:50:31  daniel
+# Revision 1.9  2004-11-02 15:26:21  florian
+#   * fixed sse exception handling
+#
+# Revision 1.8  2004/07/03 21:50:31  daniel
 #   * Modified bootstrap code so separate prt0.as/prt0_10.as files are no
 #     longer necessary
 #
@@ -122,4 +123,4 @@ __data_start:
 # Revision 1.1  2003/01/06 19:33:10  florian
 #   + initial revision
 #
-#
+#

+ 27 - 2
rtl/x86_64/mathu.inc

@@ -23,6 +23,28 @@ function arctan2(y,x : float) : float;assembler;
   end;
 
 
+procedure SetSSECSR(w : dword);
+  var
+    _w : dword;
+  begin
+    _w:=w;
+    asm
+      ldmxcsr _w
+    end;    
+  end;
+
+
+function GetSSECSR : dword;
+  var
+    _w : dword;
+  begin
+    asm
+      stmxcsr _w
+    end;
+    result:=_w;
+  end;
+  
+  
 function GetRoundMode: TFPURoundingMode;
 begin
   Result := TFPURoundingMode((Get8087CW shr 10) and 3);
@@ -76,6 +98,9 @@ end;
 
 {
   $Log$
-  Revision 1.1  2004-02-21 22:53:50  florian
+  Revision 1.2  2004-11-02 15:26:21  florian
+    * fixed sse exception handling
+
+  Revision 1.1  2004/02/21 22:53:50  florian
     * several 64 bit/x86-64 fixes
-}
+}

+ 9 - 2
rtl/x86_64/mathuh.inc

@@ -29,8 +29,15 @@ function GetExceptionMask: TFPUExceptionMask;
 function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
 procedure ClearExceptions(RaisePending: Boolean {$ifndef VER1_0}=true{$endif});
 
+
+procedure SetSSECSR(w : dword);
+function GetSSECSR : dword;
+
 {
   $Log$
-  Revision 1.1  2004-02-21 22:53:50  florian
+  Revision 1.2  2004-11-02 15:26:21  florian
+    * fixed sse exception handling
+
+  Revision 1.1  2004/02/21 22:53:50  florian
     * several 64 bit/x86-64 fixes
-}
+}

+ 14 - 6
rtl/x86_64/x86_64.inc

@@ -26,9 +26,9 @@
 ****************************************************************************}
 
 procedure fpc_cpuinit;
-begin
-end;
-
+  begin
+    SysResetFPU;
+  end;
 
 {$define FPC_SYSTEM_HAS_SPTR}
 Function Sptr : Pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
@@ -329,6 +329,7 @@ procedure inclocked(var l : int64);assembler;
 
 const
   fpucw : word = $1332;
+  mxcsr : dword = %0001100000000000;
   { Internal constants for use in system unit }
   FPU_Invalid = 1;
   FPU_Denormal = 2;
@@ -342,13 +343,20 @@ const
 {$define FPC_SYSTEM_HAS_SYSRESETFPU}
 Procedure SysResetFPU;assembler;{$ifdef SYSTEMINLINE}inline;{$endif}
 asm
-    fninit
-    fldcw   fpucw
+  { initialize fpu }
+  fninit                          
+  fwait
+  fldcw fpucw
+  { set sse exceptions }
+  ldmxcsr mxcsr
 end;
 
 {
   $Log$
-  Revision 1.14  2004-11-01 20:31:35  florian
+  Revision 1.15  2004-11-02 15:26:21  florian
+    * fixed sse exception handling
+
+  Revision 1.14  2004/11/01 20:31:35  florian
     * another fix for locked reference counting
 
   Revision 1.13  2004/06/05 07:55:22  peter