Skip to content

CPU feature detection ​

Different processors provide different features and since Graphics32 should aways perform as fast as possible on any given processor, it tries to use the processor optimizations that best fit the CPU of the host system. In order to do this it uses CPU feature detection; When the application starts, Graphics32 queries the CPU about what features it support and based on this selects among its available optimizations.

MMX is no longer supported

Support for the MMX SIMD instruction was deprecated in Graphics32 version 3 and has been removed from version 4.

Not all documentation has been updated to reflect this, so please ignore all references to MMX code.

For example, all low-level blend functions have been implemented in at least 4 variants:

  • A PUREPASCAL variant written entirely in Pascal with no use of assembler.
  • An ASM variant written in regular x86 assembler.
  • A MMX assembler variant optimized for the MMX SIMD instruction set.
  • A SSE, SSE2 or SSE4.1 assembler variants optimized for the SSE* SIMD instruction sets.

In addition, most of the assembler variants exists in both a 32-bit and a 64-bit version.

Generally you do not need to concern yourself about the CPU feature selection; It is completely automatic and transparent to the use of Graphics32. If you do need to control what CPU level features your application uses, you can do so with the following conditional symbols:

SymbolMeaning
PUREPASCALDisable all assembler implementations; Only regular Delphi Pascal code will be used.
Can be used if the target platform doesn’t support x86 assembler (e.g. Android).
OMIT_MMXDisable the MMX assembler optimizations.
OMIT_SSE2Disable the SSE2 assembler optimizations.
Note that this also includes SSE, SSE4.1 and later version of SSE.
OMIT_MMX and OMIT_SSE2Use the x86 assembler optimizations.

The chart below illustrates the effect of the various optimization levels. The data was generated by the Benchmark example.

Relative performance of different optimization levels Relative performance of different optimization levels

CPU features ​

There are too many different CPU features to list here but the most common ones are declared in the GR32_System unit (via aliases):

  • MMX
  • ExMMX
  • SSE
  • SSE2
  • SSE3
  • SSSE3
  • SSE41
  • SSE42
  • AVX
  • AVX2
  • AVX512

The complete list is defined in the GR32.CPUID unit.

To test for support of a certain CPU feature, use the InstructionSupport member of the global CPU variable (it’s a record):

pas
uses
  GR32.CPUID;
...
begin
  // Test for SSE4.1 support
  if (isSSE41 in CPU.InstructionSupport) then
  begin
    ... SSE4.1 specific code here ...
  end;
end;