Lazarus

Free Pascal => General => Topic started by: MathMan on May 04, 2017, 01:54:15 pm

Title: [SOLVED] Unit (or similar) for CPU (x86-64) feature detection
Post by: MathMan on May 04, 2017, 01:54:15 pm
Hi all,

I have been searching here and the wider web (via Google) for a Pascal unit that can detect x86-64 CPU types and drill down the feature set - e.g. SSE, AVX, AVX2, BMI etc.

Kind regards,
MathMan
Title: Re: Unit (or similar) for CPU (x86-64) feature detection
Post by: molly on May 04, 2017, 02:29:53 pm
Perhaps the port of JCL made by blikblum (https://github.com/blikblum/jcl) can be of help with unit jclsysinfo function cpuid ?

Documentation on that function can be found here (http://wiki.delphi-jedi.org/wiki/JCL_Help:CPUID).
Title: Re: Unit (or similar) for CPU (x86-64) feature detection
Post by: Nitorami on May 04, 2017, 02:51:46 pm
Some are readily available in FPC without further ado

Code: Pascal  [Select][+][-]
  1. begin
  2. writeln (has_SSE_support);
  3. writeln (has_MMX_support)
  4. end.
  5.  

There may be more I don't know
Title: Re: Unit (or similar) for CPU (x86-64) feature detection
Post by: MathMan on May 05, 2017, 07:46:06 am
Perhaps the port of JCL made by blikblum (https://github.com/blikblum/jcl) can be of help with unit jclsysinfo function cpuid ?

Documentation on that function can be found here (http://wiki.delphi-jedi.org/wiki/JCL_Help:CPUID).

Thanks molly - I have it downloaded now and take a look at it over the weekend
Title: Re: Unit (or similar) for CPU (x86-64) feature detection
Post by: MathMan on May 05, 2017, 07:47:38 am
Some are readily available in FPC without further ado

Code: Pascal  [Select][+][-]
  1. begin
  2. writeln (has_SSE_support);
  3. writeln (has_MMX_support)
  4. end.
  5.  

There may be more I don't know

Good point Nitorami - I'll see if I can identify how these are generated and where ...
Title: Re: Unit (or similar) for CPU (x86-64) feature detection
Post by: Thaddy on May 05, 2017, 08:30:56 am
CPUInfo unit in the compiler directories....
Code: Pascal  [Select][+][-]
  1. type
  2.    tcpuflags =
  3.       (CPUX86_HAS_CMOV,
  4.        CPUX86_HAS_SSEUNIT,
  5.        CPUX86_HAS_BMI1,
  6.        CPUX86_HAS_BMI2,
  7.        CPUX86_HAS_POPCNT,
  8.        CPUX86_HAS_AVXUNIT,
  9.        CPUX86_HAS_LZCNT,
  10.        CPUX86_HAS_MOVBE,
  11.        CPUX86_HAS_FMA,
  12.        CPUX86_HAS_FMA4
  13.       );
  14.  
  15.  const
  16.    cpu_capabilities : array[tcputype] of set of tcpuflags = (
  17.      { cpu_none      } [],
  18.      { Athlon64      } [CPUX86_HAS_CMOV,CPUX86_HAS_SSEUNIT],
  19.      { cpu_core_i    } [CPUX86_HAS_CMOV,CPUX86_HAS_SSEUNIT,CPUX86_HAS_POPCNT],
  20.      { cpu_core_avx  } [CPUX86_HAS_CMOV,CPUX86_HAS_SSEUNIT,CPUX86_HAS_POPCNT,CPUX86_HAS_AVXUNIT],
  21.      { cpu_core_avx2 } [CPUX86_HAS_CMOV,CPUX86_HAS_SSEUNIT,CPUX86_HAS_POPCNT,CPUX86_HAS_AVXUNIT,CPUX86_HAS_BMI1,CPUX86_HAS_BMI2,CPUX86_HAS_LZCNT,CPUX86_HAS_MOVBE,CPUX86_HAS_FMA]
  22.    );
  23.  

Note every processor family has its own cpuinfo, e.g. 8086, i386, arm, avr etc.

Note that the compiler sources are not on the path. You have to add it by hand.
Title: Re: Unit (or similar) for CPU (x86-64) feature detection
Post by: Thaddy on May 05, 2017, 09:06:43 am
And the unit CPU in the rtl, of course:
Code: Pascal  [Select][+][-]
  1.     function AESSupport : boolean;inline;
  2.     function AVXSupport : boolean;inline;
  3.     function AVX2Support: boolean;inline;
  4.     function FMASupport: boolean;inline;
  5.  
  6.  
Title: Re: Unit (or similar) for CPU (x86-64) feature detection
Post by: MathMan on May 05, 2017, 11:46:30 am
And the unit CPU in the rtl, of course:
Code: Pascal  [Select][+][-]
  1.     function AESSupport : boolean;inline;
  2.     function AVXSupport : boolean;inline;
  3.     function AVX2Support: boolean;inline;
  4.     function FMASupport: boolean;inline;
  5.  
  6.  

Thaddy - many thanks, this (and your former answer) looks exactly like what I have been searching for.

Regards,
MathMan
TinyPortal © 2005-2018