Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to probe a computer if it supports SSE2 in Delphi 32?

Tags:

delphi

sse

basm

The c++ way to do it is here (under Windows).

The same answer but under Linux using GCC.

Excerpt of the relevant asm code as I understand it:

mov     eax, 1
cpuid
mov     features, edx

I'm not very comfortable at BASM.

My Question:

I need to wrap the test as follows

function IsSSE2: Boolean;
begin
  try
    Result := False;
    //
    // Some BASM code here
    //
  except
    Result := False;
  end;
end;

Please help me.

like image 529
menjaraz Avatar asked Feb 18 '12 12:02

menjaraz


2 Answers

You can do that without assembler as well. Works with Windows XP and newer only though.

function IsProcessorFeaturePresent(ProcessorFeature: DWORD): BOOL; stdcall;
  external kernel32 name 'IsProcessorFeaturePresent';

const
  PF_XMMI64_INSTRUCTIONS_AVAILABLE = 10;

function HasSSE2: boolean;
begin
  result := IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE);
end;
like image 55
Giel Avatar answered Oct 20 '22 20:10

Giel


I think that this does it:

function SupportsSSE2: LongBool;
const
  CPUID_INTEL_SSE2 = $04000000;
asm
  push ebx
  mov eax, 1
  cpuid
  mov eax, FALSE
  test edx, CPUID_INTEL_SSE2
  jz @END
  mov eax, TRUE
@END:
  pop ebx
end;
like image 39
Andreas Rejbrand Avatar answered Oct 20 '22 22:10

Andreas Rejbrand