mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-02 22:30:23 +02:00
* moved *SSECSR to system unit
* exposed cpu feature detection on i386 from system unit + SafeLoadLibrary git-svn-id: trunk@3481 -
This commit is contained in:
parent
a1b2701e5f
commit
47fac4ee6e
@ -18,7 +18,7 @@
|
|||||||
Primitives
|
Primitives
|
||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
var
|
var
|
||||||
has_sse_support,has_mmx_support,os_supports_sse : boolean;
|
os_supports_sse : boolean;
|
||||||
|
|
||||||
{$asmmode intel}
|
{$asmmode intel}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
fldcw default8087cw
|
fldcw default8087cw
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function Get8087CW:word;assembler;
|
function Get8087CW:word;assembler;
|
||||||
asm
|
asm
|
||||||
pushl $0
|
pushl $0
|
||||||
@ -34,6 +35,28 @@
|
|||||||
popl %eax
|
popl %eax
|
||||||
end;
|
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;
|
||||||
|
|
||||||
{****************************************************************************
|
{****************************************************************************
|
||||||
EXTENDED data type routines
|
EXTENDED data type routines
|
||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
|
@ -22,29 +22,6 @@ function arctan2(y,x : float) : float;assembler;
|
|||||||
fwait
|
fwait
|
||||||
end;
|
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;
|
function GetRoundMode: TFPURoundingMode;
|
||||||
begin
|
begin
|
||||||
Result := TFPURoundingMode((Get8087CW shr 10) and 3);
|
Result := TFPURoundingMode((Get8087CW shr 10) and 3);
|
||||||
|
@ -27,8 +27,3 @@ function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode
|
|||||||
function GetExceptionMask: TFPUExceptionMask;
|
function GetExceptionMask: TFPUExceptionMask;
|
||||||
function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
|
function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
|
||||||
procedure ClearExceptions(RaisePending: Boolean =true);
|
procedure ClearExceptions(RaisePending: Boolean =true);
|
||||||
|
|
||||||
procedure SetSSECSR(w : dword);
|
|
||||||
function GetSSECSR : dword;
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,21 +14,15 @@
|
|||||||
|
|
||||||
{ i386 FPU Controlword }
|
{ i386 FPU Controlword }
|
||||||
|
|
||||||
{$ifdef cpui386}
|
{$if defined(cpui386) or defined(cpux86_64)}
|
||||||
const
|
const
|
||||||
Default8087CW : word = $1332;
|
Default8087CW : word = $1332;
|
||||||
|
|
||||||
procedure Set8087CW(cw:word);
|
procedure Set8087CW(cw:word);
|
||||||
function Get8087CW:word;
|
function Get8087CW:word;
|
||||||
{$endif cpui386}
|
procedure SetSSECSR(w : dword);
|
||||||
|
function GetSSECSR : dword;
|
||||||
{$ifdef cpux86_64}
|
{$endif}
|
||||||
const
|
|
||||||
Default8087CW : word = $1332;
|
|
||||||
|
|
||||||
procedure Set8087CW(cw:word);
|
|
||||||
function Get8087CW:word;
|
|
||||||
{$endif cpux86_64}
|
|
||||||
|
|
||||||
{ declarations of the math routines }
|
{ declarations of the math routines }
|
||||||
|
|
||||||
|
@ -294,8 +294,13 @@ type
|
|||||||
|
|
||||||
const
|
const
|
||||||
{$ifdef cpui386}
|
{$ifdef cpui386}
|
||||||
Test8086 : byte = 2; { Always i386 or newer }
|
{ Always i386 or newer }
|
||||||
Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
|
Test8086 : byte = 2;
|
||||||
|
{ Always 387 or newer. Emulated if needed. }
|
||||||
|
Test8087 : byte = 3;
|
||||||
|
{ will be detected at startup }
|
||||||
|
has_sse_support : boolean = false;
|
||||||
|
has_mmx_support : boolean = false;
|
||||||
{$endif cpui386}
|
{$endif cpui386}
|
||||||
{$ifdef cpum68k}
|
{$ifdef cpum68k}
|
||||||
Test68000 : byte = 0; { Must be determined at startup for both }
|
Test68000 : byte = 0; { Must be determined at startup for both }
|
||||||
|
@ -180,13 +180,10 @@ Var
|
|||||||
type
|
type
|
||||||
TTerminateProc = Function: Boolean;
|
TTerminateProc = Function: Boolean;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
procedure AddTerminateProc(TermProc: TTerminateProc);
|
procedure AddTerminateProc(TermProc: TTerminateProc);
|
||||||
function CallTerminateProcs: Boolean;
|
function CallTerminateProcs: Boolean;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Var
|
Var
|
||||||
OnShowException : Procedure (Msg : ShortString);
|
OnShowException : Procedure (Msg : ShortString);
|
||||||
|
|
||||||
@ -237,3 +234,5 @@ Type
|
|||||||
{ interface handling }
|
{ interface handling }
|
||||||
{$i intfh.inc}
|
{$i intfh.inc}
|
||||||
|
|
||||||
|
function SafeLoadLibrary(const FileName: AnsiString;
|
||||||
|
ErrorMode: DWord = {$ifdef windows}SEM_NOOPENFILEERRORBOX{$else windows}0{$endif windows}): HMODULE;
|
||||||
|
@ -576,3 +576,34 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function SafeLoadLibrary(const FileName: AnsiString;
|
||||||
|
ErrorMode: DWord = {$ifdef windows}SEM_NOOPENFILEERRORBOX{$else windows}0{$endif windows}): HMODULE;
|
||||||
|
var
|
||||||
|
mode : DWord;
|
||||||
|
{$if defined(cpui386) or defined(cpux86_64)}
|
||||||
|
fpucw : Word;
|
||||||
|
ssecw : DWord;
|
||||||
|
{$endif}
|
||||||
|
begin
|
||||||
|
mode:=SetErrorMode(ErrorMode);
|
||||||
|
try
|
||||||
|
{$if defined(cpui386) or defined(cpux86_64)}
|
||||||
|
fpucw:=Get8087CW;
|
||||||
|
{$ifdef cpui386}
|
||||||
|
if has_sse_support then
|
||||||
|
{$endif cpui386}
|
||||||
|
ssecw:=GetSSECSR;
|
||||||
|
{$endif}
|
||||||
|
Result:=LoadLibrary(PChar(Filename));
|
||||||
|
finally
|
||||||
|
{$if defined(cpui386) or defined(cpux86_64)}
|
||||||
|
Set8087CW(fpucw);
|
||||||
|
{$ifdef cpui386}
|
||||||
|
if has_sse_support then
|
||||||
|
{$endif cpui386}
|
||||||
|
SetSSECSR(ssecw);
|
||||||
|
{$endif}
|
||||||
|
SetErrorMode(mode);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
@ -51,6 +51,7 @@ FPC_ABSMASK_DOUBLE:
|
|||||||
{$endif FPC_PIC}
|
{$endif FPC_PIC}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function Get8087CW:word;assembler;
|
function Get8087CW:word;assembler;
|
||||||
asm
|
asm
|
||||||
pushq $0
|
pushq $0
|
||||||
@ -58,6 +59,28 @@ FPC_ABSMASK_DOUBLE:
|
|||||||
popq %rax
|
popq %rax
|
||||||
end;
|
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;
|
||||||
|
|
||||||
{****************************************************************************
|
{****************************************************************************
|
||||||
EXTENDED data type routines
|
EXTENDED data type routines
|
||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
|
Loading…
Reference in New Issue
Block a user