* * *

Author Topic: [SOLVED] Unit (or similar) for CPU (x86-64) feature detection  (Read 788 times)

MathMan

  • Full Member
  • ***
  • Posts: 149
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
« Last Edit: May 05, 2017, 11:47:29 am by MathMan »

molly

  • Hero Member
  • *****
  • Posts: 1612
Re: Unit (or similar) for CPU (x86-64) feature detection
« Reply #1 on: May 04, 2017, 02:29:53 pm »
Perhaps the port of JCL made by blikblum can be of help with unit jclsysinfo function cpuid ?

Documentation on that function can be found here.

Nitorami

  • Full Member
  • ***
  • Posts: 197
Re: Unit (or similar) for CPU (x86-64) feature detection
« Reply #2 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

MathMan

  • Full Member
  • ***
  • Posts: 149
Re: Unit (or similar) for CPU (x86-64) feature detection
« Reply #3 on: May 05, 2017, 07:46:06 am »
Perhaps the port of JCL made by blikblum can be of help with unit jclsysinfo function cpuid ?

Documentation on that function can be found here.

Thanks molly - I have it downloaded now and take a look at it over the weekend

MathMan

  • Full Member
  • ***
  • Posts: 149
Re: Unit (or similar) for CPU (x86-64) feature detection
« Reply #4 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 ...

Thaddy

  • Hero Member
  • *****
  • Posts: 3640
Re: Unit (or similar) for CPU (x86-64) feature detection
« Reply #5 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.
« Last Edit: May 05, 2017, 08:38:55 am by Thaddy »
Why do the Danish always try to fuck up any programming language?

Thaddy

  • Hero Member
  • *****
  • Posts: 3640
Re: Unit (or similar) for CPU (x86-64) feature detection
« Reply #6 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.  
Why do the Danish always try to fuck up any programming language?

MathMan

  • Full Member
  • ***
  • Posts: 149
Re: Unit (or similar) for CPU (x86-64) feature detection
« Reply #7 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

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus