-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSimpleCPUID.pas
More file actions
2630 lines (2359 loc) · 111 KB
/
SimpleCPUID.pas
File metadata and controls
2630 lines (2359 loc) · 111 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-------------------------------------------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-------------------------------------------------------------------------------}
{===============================================================================
SimpleCPUID
Small library designed to provide some basic parsed information (mainly CPU
features) obtained by the CPUID instruction on x86(-64) processors.
Should be compatible with any Windows and Linux system running on x86(-64)
architecture.
NOTE - some provided information are valid only on processors of specific
type, model or manufacturer. Consult source code for mode details.
Version 1.4 (2025-11-01)
Last change 2025-11-01
©2016-2025 František Milt
Contacts:
František Milt: frantisek.milt@gmail.com
Support:
If you find this code useful, please consider supporting its author(s) by
making a small donation using the following link(s):
https://www.paypal.me/FMilt
Changelog:
For detailed changelog and history please refer to this git repository:
github.com/TheLazyTomcat/Lib.SimpleCPUID
Sources:
- en.wikipedia.org/wiki/CPUID
- sandpile.org/x86/cpuid.htm
- Intel® 64 and IA-32 Architectures Software Developer’s Manual (document
#325462-088US, June 2025)
- Intel® Advanced Performance Extensions (Intel® APX) Architecture
Specification (document #355828-007US, revision 7, July 2025)
- Intel® Architecture Instruction Set Extensions and Future Features
Programming Reference (document #319433-059, September 2025)
- AMD64 Architecture Programmer’s Manual Volume 3... (publication #24594,
revision 3.37, July 2025)
Dependencies:
* AuxExceptions - github.com/TheLazyTomcat/Lib.AuxExceptions
AuxTypes - github.com/TheLazyTomcat/Lib.AuxTypes
Library AuxExceptions is required only when rebasing local exception classes
(see symbol SimpleCPUID_UseAuxExceptions for details).
Indirect dependencies:
StrRect - github.com/TheLazyTomcat/Lib.StrRect
UInt64Utils - github.com/TheLazyTomcat/Lib.UInt64Utils
WinFileInfo - github.com/TheLazyTomcat/Lib.WinFileInfo
===============================================================================}
unit SimpleCPUID;
{
SimpleCPUID_PurePascal
If you want to compile this unit without ASM, don't want to or cannot define
PurePascal for the entire project and at the same time you don't want to or
cannot make changes to this unit, define this symbol for the entire project
and this unit will be compiled in PurePascal mode.
This unit cannot be compiled without asm, but meh...
}
{$IFDEF SimpleCPUID_PurePascal}
{$DEFINE PurePascal}
{$ENDIF}
{
SimpleCPUID_UseAuxExceptions
If you want library-specific exceptions to be based on more advanced classes
provided by AuxExceptions library instead of basic Exception class, and don't
want to or cannot change code in this unit, you can define global symbol
SimpleCPUID_UseAuxExceptions to achieve this.
}
{$IF Defined(SimpleCPUID_UseAuxExceptions)}
{$DEFINE UseAuxExceptions}
{$IFEND}
//------------------------------------------------------------------------------
{$IF Defined(CPUX86_64) or Defined(CPUX64)}
{$DEFINE x64}
{$ELSEIF Defined(CPU386)}
{$DEFINE x86}
{$ELSE}
{$MESSAGE FATAL 'Unsupported CPU.'}
{$IFEND}
{$IF Defined(WINDOWS) or Defined(MSWINDOWS)}
{$DEFINE Windows}
{$ELSEIF Defined(LINUX) and Defined(FPC)}
{$DEFINE Linux}
{$ELSE}
{$MESSAGE FATAL 'Unsupported operating system.'}
{$IFEND}
{$IFDEF FPC}
{$MODE ObjFPC}
{$MODESWITCH DuplicateLocals+}
{$INLINE ON}
{$DEFINE CanInline}
{$ASMMODE Intel}
{$ELSE}
{$IF CompilerVersion >= 17} // Delphi 2005+
{$DEFINE CanInline}
{$ELSE}
{$UNDEF CanInline}
{$IFEND}
{$ENDIF}
{$H+}
//------------------------------------------------------------------------------
{$IF Defined(PurePascal) and not Defined(CompTest)}
{$MESSAGE WARN 'This unit cannot be compiled without ASM.'}
{$IFEND}
interface
uses
SysUtils,
AuxTypes{$IFDEF UseAuxExceptions}, AuxExceptions{$ENDIF};
{===============================================================================
Library-specific exceptions
===============================================================================}
type
ESCIDException = class({$IFDEF UseAuxExceptions}EAEGeneralException{$ELSE}Exception{$ENDIF});
ESCIDSystemError = class(ESCIDException);
ESCIDIndexOutOfBounds = class(ESCIDException);
ESCIDInvalidProcessor = class(ESCIDException);
{===============================================================================
Main CPUID routines
===============================================================================}
type
TCPUIDLeafData = packed record
EAX,EBX,ECX,EDX: UInt32;
end;
PCPUIDLeafData = ^TCPUIDLeafData;
const
EmptyLeafData: TCPUIDLeafData = (EAX: 0; EBX: 0; ECX: 0; EDX: 0);
//------------------------------------------------------------------------------
Function CPUIDSupported: Boolean; register; assembler;
procedure CPUID(Leaf,SubLeaf: UInt32; Result: Pointer); register; overload; assembler;
procedure CPUID(Leaf: UInt32; Result: Pointer); overload;{$IFDEF CanInline} inline; {$ENDIF}
procedure CPUID(Leaf,SubLeaf: UInt32; out Info: TCPUIDLeafData); overload;{$IFDEF CanInline} inline; {$ENDIF}
procedure CPUID(Leaf: UInt32; out Info: TCPUIDLeafData); overload;{$IFDEF CanInline} inline; {$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
TSimpleCPUID
--------------------------------------------------------------------------------
===============================================================================}
type
TCPUIDLeaf = record
// leaf number/index (value in EAX before calling CPUID instruction)
ID: UInt32;
// main leaf data - obtained when CPUID is called with SubLeaf index 0
Data: TCPUIDLeafData;
{
If there is any subleaf (array is not empty), then the first subleaf
(index 0) is a mirror of field Data.
}
SubLeafs: array of TCPUIDLeafData;
end;
PCPUIDLeaf = ^TCPUIDLeaf;
//------------------------------------------------------------------------------
type
TCPUIDManufacturerID = (mnOthers,mnAMD,mnCentaur,mnCyrix,mnIntel,mnTransmeta,
mnNationalSemiconductor,mnNexGen,mnRise,mnSiS,mnUMC,
mnVIA,mnVortex);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TCPUIDInfo_AdditionalInfo = record
BrandID: Byte;
CacheLineFlushSize: Word; // in bytes (raw data is in qwords)
LogicalProcessorCount: Byte; // HTT (see features) must be on, otherwise 0
LocalAPICID: Byte;
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{
TCPUIDInfo_Features
TCPUIDInfo_ExtendedFeatures
Fields marked with asterisk in curly braces are preliminar. They identify
features that belong to future extensions which are not yet finalized,
meaning they can be changed or even removed. They are provided only for
testing, do not rely on them.
Number in square brackets is zero-based index of that particular bit in the
noted register.
Letters in brackets just behind the bit index in description mark whether
that particular bit flag is documented by Intel (i) or AMD (a) to be used
for described feature (at least in documents available while writing this
library - these might be outdated by now).
NOTE - some feature bits are supported only by processors from certain
manufacturers. They should not be relied upon on CPUs that do not
support them.
}
TCPUIDInfo_Features = packed record
{leaf 1, ECX register -------------------------------------------------------}
SSE3, // [00] (ia) SSE3 Extensions
PCLMULQDQ, // [01] (ia) Carryless Multiplication
DTES64, // [02] (i) 64-bit Debug Store Area
MONITOR, // [03] (ia) MONITOR and MWAIT Instructions
DS_CPL, // [04] (i) CPL Qualified Debug Store
VMX, // [05] (i) Virtual Machine Extensions
SMX, // [06] (i) Safer Mode Extensions
EIST, // [07] (i) Enhanced Intel SpeedStep Technology
TM2, // [08] (i) Thermal Monitor 2
SSSE3, // [09] (ia) SSSE3 Extensions
CNXT_ID, // [10] (i) L1 Context ID
SDBG, // [11] (i) Silicon Debug interface
FMA, // [12] (ia) Fused Multiply Add
CMPXCHG16B, // [13] (ia) CMPXCHG16B Instruction
xTPR, // [14] (i) Update Control (Can disable sending task priority messages)
PDCM, // [15] (i) Perform & Debug Capability MSR
PCID, // [17] (i) Process-context Identifiers
DCA, // [18] (i) Direct Cache Access
SSE4_1, // [19] (ia) SSE4.1 Instructions
SSE4_2, // [20] (ia) SSE4.2 Instructions
x2APIC, // [21] (ia) x2APIC Support
MOVBE, // [22] (ia) MOVBE Instruction
POPCNT, // [23] (ia) POPCNT Instruction
TSC_DEADLINE, // [24] (i) APIC supports one-shot operation using a TSC deadline value
AES, // [25] (ia) AES Instruction Set
XSAVE, // [26] (ia) XSAVE, XRESTOR, XSETBV, XGETBV Instructions
OSXSAVE, // [27] (ia) XSAVE enabled by OS
AVX, // [28] (ia) Advanced Vector Extensions
F16C, // [29] (ia) F16C (half-precision) FP Support
RDRAND: Boolean; // [30] (ia) RDRAND (on-chip random number generator) Support
case Integer of
0:(HYPERVISOR: // [31] (a) Running on a hypervisor (always 0 on a real CPU)
Boolean);
1:(RAZ, // Same as HYPERVISOR
{leaf 1, EDX register -------------------------------------------------------}
FPU, // [00] (ia) x87 FPU on Chip
VME, // [01] (ia) Virtual-8086 Mode Enhancement
DE, // [02] (ia) Debugging Extensions
PSE, // [03] (ia) Page Size Extensions
TSC, // [04] (ia) Time Stamp Counter
MSR, // [05] (ia) RDMSR and WRMSR Support
PAE, // [06] (ia) Physical Address Extensions
MCE, // [07] (ia) Machine Check Exception
CX8, // [08] (ia) CMPXCHG8B Instruction
APIC, // [09] (ia) APIC on Chip
SEP, // [11] (ia) SYSENTER and SYSEXIT Instructions
MTRR, // [12] (ia) Memory Type Range Registers
PGE, // [13] (ia) PTE Global Bit
MCA, // [14] (ia) Machine Check Architecture
CMOV, // [15] (ia) Conditional Move/Compare Instruction
PAT, // [16] (ia) Page Attribute Table
PSE_36, // [17] (ia) Page Size Extension
PSN, // [18] (i) Processor Serial Number
CLFSH, // [19] (ia) CLFLUSH Instruction
DS, // [21] (i) Debug Store
ACPI, // [22] (i) Thermal Monitor and Clock Control
MMX, // [23] (ia) MMX Technology
FXSR, // [24] (ia) FXSAVE/FXRSTOR Instructions
SSE, // [25] (ia) SSE Extensions
SSE2, // [26] (ia) SSE2 Extensions
SS, // [27] (i) Self Snoop
HTT, // [28] (ia) Multi-threading
TM, // [29] (i) Thermal Monitor
IA64, // [30] IA64 processor emulating x86
PBE, // [31] (i) Pending Break Enable
{leaf 7:0, EBX register -----------------------------------------------------}
FSGSBASE, // [00] (ia) RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE Support
TSC_ADJUST, // [01] (ia) IA32_TSC_ADJUST MSR Support
SGX, // [02] (i) Intel Software Guard Extensions (Intel SGX Extensions)
BMI1, // [03] (ia) Bit Manipulation Instruction Set 1
HLE, // [04] (i) Transactional Synchronization Extensions
AVX2, // [05] (ia) Advanced Vector Extensions 2
FPDP, // [06] (i) x87 FPU Data Pointer updated only on x87 exceptions
SMEP, // [07] (ia) Supervisor-Mode Execution Prevention
BMI2, // [08] (ia) Bit Manipulation Instruction Set 2
ERMS, // [09] (ia) Enhanced REP MOVSB/STOSB
INVPCID, // [10] (ia) INVPCID Instruction
RTM: Boolean; // [11] (i) Transactional Synchronization Extensions
case Integer of
0:(PQM: Boolean); // [12] (ia) Platform Quality of Service Monitoring
1:(RDT_M, // Resource Director Technology (RDT) Monitoring (PQM)
FPCSDS, // [13] (i) FPU CS and FPU DS deprecated
MPX: Boolean; // [14] (i) Intel MPX (Memory Protection Extensions)
case Integer of
0:(PQE: Boolean); // [15] (ia) Platform Quality of Service Enforcement
1:(RDT_A, // Resource Director Technology Allocation (PQE)
AVX512F, // [16] (ia) AVX-512 Foundation
AVX512DQ, // [17] (ia) AVX-512 Doubleword and Quadword Instructions
RDSEED, // [18] (ia) RDSEED instruction
ADX, // [19] (ia) Intel ADX (Multi-Precision Add-Carry Instruction Extensions)
SMAP, // [20] (ia) Supervisor Mode Access Prevention
AVX512_IFMA, // [21] (ia) AVX-512 Integer Fused Multiply-Add Instructions
PCOMMIT, // [22] PCOMMIT Instruction
CLFLUSHOPT, // [23] (ia) CLFLUSHOPT Instruction
CLWB, // [24] (ia) CLWB Instruction
PT, // [25] (i) Intel Processor Trace
AVX512PF, // [26] (i) AVX-512 Prefetch Instructions
AVX512ER, // [27] (i) AVX-512 Exponential and Reciprocal Instructions
AVX512CD, // [28] (ia) AVX-512 Conflict Detection Instructions
SHA, // [29] (ia) Intel SHA extensions
AVX512BW, // [30] (ia) AVX-512 Byte and Word Instructions
AVX512VL, // [31] (ia) AVX-512 Vector Length Extensions
{leaf 7:0, ECX register -----------------------------------------------------}
PREFETCHWT1, // [00] (i) PREFETCHWT1 Instruction
AVX512_VBMI, // [01] (ia) AVX-512 Vector Bit Manipulation Instructions
UMIP, // [02] (ia) User-mode Instruction Prevention
PKU, // [03] (ia) Memory Protection Keys for User-mode pages
OSPKE, // [04] (ia) PKU enabled by OS
WAITPKG, // [05] (i) TPAUSE, UMONITOR and UMWAIT instructions
AVX512_VBMI2: // [06] (ia) AVX-512 Vector Bit Manipulation Instrutions 2
Boolean;
case Integer of
0:(CET: Boolean); // [07] (ia) Support for CET shadow stack features
1:(CET_SS, //
GFNI, // [08] (ia) Galois Field calculations
VAES, // [09] (ia) (E)VEX-encoded AES instructions (256bit, 512bit)
VPCLMULQDQ, // [10] (ia) VPCLMULQDQ instrution
AVX512_VNNI, // [11] (ia) AVX-512 Vector Neural Network Instructions
AVX512_BITALG, // [12] (ia) AVX-512 Bit Algorithms (VPOPCNT, VPSHUFBITQMB)
TME_EN, // [13] (i) Support for TME model-specific registers (MSR)
AVX512_VPOPCNTDQ: // [14] (ia) AVX-512 VPOPCNTD and VPOPCNTQ instructions
Boolean;
case Integer of
0:(VA57: Boolean); // [16] (ia) 57-bit linear addresses and five-level paging (CR4.LA57),
1:(LA57: Boolean; // VA57 was probably naming mistake
MAWAU: Byte; // [17..21] The value of MAWAU (User MPX (Memory Protection Extensions) address-width adjust)
// (i) used by the BNDLDX and BNDSTX instructions in 64-bit mode.
RDPID, // [22] (ia) Read Processor ID
KL, // [23] (i) Key Locker
BUS_LOCK_DETECT, // [24] (ia) Support for OS bus-lock detection
CLDEMOTE, // [25] (i) Cache Line Demote
MOVDIRI, // [27] (ia) MOVDIRI (direct store) instruction
MOVDIR64B, // [28] (ia) MOVDIR64B (direct store) instruction
ENQCMD, // [29] (i) Enqueue stores support
SGX_LC, // [30] (i) SGX Launch Configuration
PKS, // [31] (i) Protection keys for supervisor-mode pages
{leaf 7:0, EDX register -----------------------------------------------------}
SGX_KEYS: // [01] (i) Attestation Services for SGX
Boolean;
case Integer of
0:(AVX512_QVNNIW, // [02] (i) AVX-512 4-iteration single-precision dot products
AVX512_QFMA: Boolean);// [03] (i) AVX-512 4-iteration single-precision fused multiply-add
1:(AVX512_4VNNIW,
AVX512_4FMAPS,
REPMOV_FS, // [04] (i) Fast Short REP MOV
UINTR, // [05] (i) User Interrups support
AVX512_VP2INTERSECT, // [08] (i) VP2INTERSECTD, VP2INTERSECTQ instructions
SRBDS_CTRL, // [09] (i) Support for IA32_MCU_OPT_CTRL model-specific register (MSR)
MD_CLEAR, // [10] (i) MD_CLEAR operations (fill buffer overwrite, VERW instruction)
RTM_ALWAYS_ABORT, // [11] (i) Execution of XBEGIN immediately aborts and transitions to the specified fallback address
RTM_FORCE_ABORT, // [13] (i) IA32_TSX_FORCE_ABORT MSR support
SERIALIZE, // [14] (i) SERIALIZE instruction
HYBRID, // [15] (i) Processor is identified as a hybrid part
TSXLDTRK, // [16] (i) TSX suspend/resume of load address tracking
PCONFIG, // [18] (i) PCONFIG instruction (platform configuration)
ARCHITECTURAL_LBRS, // [19] (i) Support for architectural LBRs (last branch record)
CET_IBT, // [20] (i) CET indirect branch tracking
AMX_BF16, // [22] (i) AMX tile computational operations on bfloat16
AVX512_FP16, // [23] (i) AVX-512 Half-precision floats (16bit) support
AMX_TILE, // [24] (i) Advanced Matrix Extensions (AMX) support
AMX_INT8, // [25] (i) AMX tile computational operations on 8-bit integers
IBRS_IBPB, // [26] (i) Support for indirect branch restricted speculation and indirect branch predictor barrier
STIBP, // [27] (i) Support for single thread indirect branch predictors
L1D_FLUSH, // [28] (i) IA32_FLUSH_CMD MSR support
ARCH_CAPABILITIES, // [29] (i) IA32_ARCH_CAPABILITIES MSR support
CORE_CAPABILITIES, // [30] (i) IA32_CORE_CAPABILITIES MSR support
SSBD, // [31] (i) Speculative Store Bypass Disable
{leaf 7:1, EAX register -----------------------------------------------------}
SHA512, // [00] (i) SHA512 instructions
SM3, // [01] (i) SM3 instructions
SM4, // [02] (i) SM4 instructions
{*} RAO_INT, // [03] (i) <--pre--> RAO-INT instructions support
AVX_VNNI, // [04] (ia) AVX (VEX-encoded) versions of the Vector Neural Network Instructions
AVX512_BF16, // [05] (ia) Vector Neural Network Instructions supporting bfloat16
LASS, // [06] (i) Linear Address Space Separation
CMPCCXADD, // [07] (i) CMPccXADD instruction
ARCH_PERFMON_EXT, // [08] (i) Architectural Performance Monitoring
REPMOV_FZ, // [10] (i) Fast zero-length REP MOVSB
REPSTOS_FS, // [11] (i) Fast short REP STOSB
REPCMPS_FS, // [12] (i) Fast short REP CMPSB and REP SCASB
{*} FRED, // [17] (i) <--pre--> Flexible Return and Event Delivery
{*} LKGS, // [18] (i) <--pre--> Load into IA32_KERNEL_GS_BASE support
WRMSRNS, // [19] (i) WRMSRNS instruction
{*} NMI_SRC, // [20] (i) <--pre--> NMI-source reporting support
AMX_FP16, // [21] (i) AMX Tile computational operations on FP16 numbers
HRESET, // [22] (i) History reset support
AVX_IFMA, // [23] (i) AVX versions of Integer Fused Multiply-Add
LAM, // [26] (i) Linear Address Masking
MSRLIST, // [27] (i) RDMSRLIST and WRMSRLIST instructions
INVD_DIS_POST_BIOS, // [30] (i) (INVD_DISABLE_POST_BIOS_DONE) INVD execution prevention after BIOS done
{*} MOVRS, // [31] (i) <--pre--> MOVRS support
{leaf 7:1, EBX register -----------------------------------------------------}
PPIN, // [00] (i) IA32_PPIN and IA32_PPIN_CTL MSR support
{*} PBNDKB, // [01] (i) <--pre--> PBNDKB instruction support
CPUIDMAXVAL_LIM_RMV, // [03] (i) IA32_MISC_ENABLE[22] cannot be set to 1
{leaf 7:1, ECX register -----------------------------------------------------}
{*} ASYM_RDTM, // [00] (i) <--pre--> At least one logical processor supports Asymmetrical Intel RDT Monitoring capability
{*} ASYM_RDTA, // [01] (i) <--pre--> at least one logical processor supports Asymmetrical Intel RDT Allocation capability
{*} MSR_IMM, // [05] (i) <--pre--> Immediate forms of the RDMSR and WRMSRNS instructions are supported
{leaf 7:1, EDX register -----------------------------------------------------}
AVX_VNNI_INT8, // [04] (i) AVX Vector Neural Network Instructions for 8bit integers
AVX_NE_CONVERT, // [05] (i) AVX Instruction for bf16 and fp16 conversions
{*} AMX_COMPLEX, // [08] (i) <--pre--> AMX-COMPLEX instructions support
AVX_VNNI_INT16, // [10] (i) AVX Vector Neural Network Instructions for 16bit integers
{*} UTMR, // [13] (i) <--pre--> User-timer events support
PREFETCHI, // [14] (i) PREFETCHIT0/1 instructions
{*} USER_MSR, // [15] (i) <--pre--> URDMSR and UWRMSR instructions support
UIRET_UIF, // [17] (i) UIRET sets UIF to the value of bit 1 of the RFLAGS image loaded from the stack
CET_SSS, // [18] (i) Operating system can enable supervisor shadow stacks
AVX10, // [19] (i) Advanced Vector Extensions 10
{*} APX_F, // [21] (i) <--pre--> Foundational support for Intel Advanced Performance Extensions
{*} MWAIT, // [23] (i) <--pre--> MWAIT support
SLSM, // [24] (i) IA32_INTEGRITY_STATUS MSR support
{leaf 7:2, EDX register -----------------------------------------------------}
PSFD, // [00] (i) Indicates bit 7 of the IA32_SPEC_CTRL MSR is supported (disables Fast
// Store Forwarding Predictor without disabling Speculative Store Bypass)
IPRED_CTRL, // [01] (i) Bits 3 and 4 of the IA32_SPEC_CTRL MSR are supported (#3 enables IPRED_DIS
// control for CPL3, #4 enables IPRED_DIS control for CPL0/1/2)
RRSBA_CTRL, // [02] (i) Bits 5 and 6 of the IA32_SPEC_CTRL MSR are supported (#5 disables RRSBA
// behavior for CPL3, #6 disables RRSBA behavior for CPL0/1/2.)
DDPD_U, // [03] (i) Bit 8 of the IA32_SPEC_CTRL MSR is supported (disables Data Dependent Prefetcher)
BHI_CTRL, // [04] (i) Bit 10 of the IA32_SPEC_CTRL MSR is supported (enables BHI_DIS_S behavior)
MCDT_NO, // [05] (i) Processor do not exhibit MXCSR Configuration Dependent Timing (MCDT)
UC_LOCK_DIS, // [06] (i) Support for UC-lock disable feature
MONITOR_MITG_NO, // [07] (i) Indicates that the MONITOR/UMONITOR instructions are not affected by performance
// or power issues due to exceeding the capacity of an internal monitor tracking table
{leaf $1E:1, EAX register - AMX TMUL Information leaf -----------------------}
(*
{*} AMX_INT8, // [00] (i) <--pre--> AMX tile computational operations on 8-bit integers (mirror of 7:0:EDX[25])
{*} AMX_BF16, // [01] (i) <--pre--> AMX tile computational operations on bfloat16 (mirror of 7:0:EDX[22])
{*} AMX_COMPLEX, // [02] (i) <--pre--> AMX-COMPLEX instructions support (mirror of 7:1:EDX[08])
{*} AMX_FP16, // [03] (i) <--pre--> AMX Tile computational operations on FP16 numbers (mirror of 7:1:ESX[21])
*)
{*} AMX_FP8, // [04] (i) <--pre--> Intel AMX computations for the FP8 data type
{*} AMX_TF32, // [06] (i) <--pre--> AMX-TF32 (FP19) instructions support
{*} AMX_AVX512, // [07] (i) <--pre--> AMX-AVX512 instructions support
{*} AMX_MOVRS: // [08] (i) <--pre--> AMX-MOVRS instructions support
Boolean))))));
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TCPUIDInfo_ExtendedFeatures = packed record
{leaf $80000001, ECX register -----------------------------------------------}
AHF64, // [00] (ia) LAHF/SAHF available in 64-bit mode
CMP, // [01] (a) Core multi-processing legacy mode
SVM, // [02] (a) Secure Virtual Machine
EAS, // [03] (a) Extended APIC space
CR8D: Boolean; // [04] (a) LOCK MOV CR0 means MOV CR8
case Integer of
0:(LZCNT: Boolean); // [05] (ia) Advanced bit manipulation / LZCNT instruction
1:(ABM,
SSE4A, // [06] (a) SSE4a Support (instructions EXTRQ, INSERTQ, MOVNTSS, and MOVNTSD)
MSSE: Boolean; // [07] (a) Misaligned SSE mode
case Integer of
0:(PREFETCHW: // [08] (i) PREFETCHW Instructions
Boolean);
1:(_3DNOWP: // [08] (a) PREFETCH and PREFETCHW Instructions
Boolean);
2:(_3DNOW_PREFETCH,
OSVW, // [09] (a) OS Visible Workaround
IBS, // [10] (a) Instruction Based Sampling
XOP, // [11] (a) Extended operation (XOP) instruction set
SKINIT, // [12] (a) SKINIT/STGI instructions
WDT, // [13] (a) Watchdog timer
LWP, // [15] (a) Light Weight Profiling
FMA4, // [16] (a) 4-operand fused multiply-add
TCE, // [17] (a) Translation Cache Extension
NODEID, // [19] Node ID MSR (C001_100C)
TBM, // [21] (a) Trailing Bit Manipulation
TOPX, // [22] (a) Topology Extensions
PCX_CORE, // [23] (a) Core performance counter extensions
PCX_NB, // [24] (a) NB performance counter extensions
DBX, // [26] (a) Data access breakpoint extensions
PERFTSC, // [27] (a) Performance time-stamp counter (TSC)
PCX_L2I: Boolean; // [28] (a) L2I/L3 performance counter MSR extensions
case Integer of
0:(MON: Boolean); // [29] (a) MONITORX/MWAITX Instructions
1:(MONX,
ADDRMASKEXT, // [30] (a) Breakpoint Addressing masking extended to bit 31
{leaf $80000001, EDX register -----------------------------------------------}
FPU, // [00] (a) Onboard x87 FPU (mirror of CPUID:1:EDX[FPU])
VME, // [01] (a) Virtual mode enhancements (mirror of CPUID:1:EDX[VME])
DE, // [02] (a) Debugging extensions (mirror of CPUID:1:EDX[DE])
PSE, // [03] (a) Page Size Extension (mirror of CPUID:1:EDX[PSE])
TSC, // [04] (a) Time Stamp Counter (mirror of CPUID:1:EDX[TSC])
MSR, // [05] (a) Model-specific registers (mirror of CPUID:1:EDX[MSR])
PAE, // [06] (a) Physical Address Extension (mirror of CPUID:1:EDX[PAE])
MCE, // [07] (a) Machine Check Exception (mirror of CPUID:1:EDX[MCE])
CX8, // [08] (a) CMPXCHG8 instruction (mirror of CPUID:1:EDX[CX8])
{
If the APIC has been disabled, then the APIC feature flag will read as 0.
}
APIC, // [09] (a) Onboard Advanced Programmable Interrupt Controller (mirror of CPUID:1:EDX[APIC])
{
The AMD K6 processor, model 6, uses bit 10 to indicate SEP. Beginning with
model 7, bit 11 is used instead.
Intel processors only report SEP when CPUID is executed in PM64.
}
SEP, // [11] (ia) SYSCALL and SYSRET Instructions (mirror of CPUID:1:EDX[SEP])
MTRR, // [12] (a) Memory-Type Range Registers (mirror of CPUID:1:EDX[MTRR])
PGE, // [13] (a) Page Global Extension (mirror of CPUID:1:EDX[PGE])
MCA, // [14] (a) Machine check architecture (mirror of CPUID:1:EDX[MCA])
CMOV: Boolean; // [15] (a) Conditional move instructions (mirror of CPUID:1:EDX[CMOV])
case Integer of
0:(PAT: Boolean); // [16] (a) Page Attribute Table (mirror of CPUID:1:EDX[PAT])
1:(FCMOV, // [16] ??? (http://sandpile.org/x86/cpuid.htm)
PSE36, // [17] (a) 36-bit page size extension (mirror of CPUID:1:EDX[PSE36])
{
AMD K7 processors prior to CPUID=0662h may report 0 even if they are MP-capable.
}
MP, // [19] Multiprocessor Capable
NX, // [20] (ia) Execute Disable Bit available
MMXEXT, // [22] (a) AMD extensions to MMX instructions
MMX: Boolean; // [23] (a) MMX Instructions (mirror of CPUID:1:EDX[MMX])
case Integer of
0:(FXSR: Boolean); // [24] (a) FXSAVE, FXRSTOR instructions (mirror of CPUID:1:EDX[FXSR])
1:(MMXEXT_CYRIX, // [24] Cyrix Extended MMX
FFXSR, // [25] (a) FXSAVE/FXRSTOR optimizations
PG1G, // [26] (ia) 1-GByte pages are available
TSCP, // [27] (ia) RDTSCP and IA32_TSC_AUX are available
LM, // [29] (ia) Long Mode - AMD64/EM64T/Intel 64 Architecture
_3DNOWEXT, // [30] (a) AMD extensions to 3DNow! instructions.
_3DNOW: Boolean; // [31] (a) 3DNow! instructions
{leaf $80000007, EDX register - Advanced Power Management Features ----------}
ITSC, // [08] (ia) Invariant TSC
{leaf $80000008, EBX register -----------------------------------------------}
CLZERO: Boolean; // [00] (a) CLZERO instruction
case Integer of
0:(INSTRSTCNTMSR, // [01] (a) Instruction Retired Counter MSR
RSTRFPERRPTRS: // [02] (a) FP Error Pointers Restored by XRSTOR
Boolean);
1:(IRPERF, // [01] Read-only IRPERF (MSR C000_00E9h)
ASRFPEP, // [02] (a) Always save/restore FP error pointers (same thing as RSTRFPERRPTRS, only different field name)
INVLPGB, // [03] (a) INVLPGB and TLBSYNC instructions
RDPRU, // [04] (a) RDPRU instruction
BE, // [06] (a) Bandwidth Enforcement Extension
MCOMMIT, // [08] (a) MCOMMIT instruction
WBNOINVD, // [09] (ia) WBNOINVD instruction
IBPB, // [12] (a) Indirect Branch Prediction Barrier
INT_WBINVD, // [13] (a) WBINVD/WBNOINVD are interruptible
IBRS, // [14] (a) Indirect Branch Restricted Speculation
STIBP, // [15] (a) Single Thread Indirect Branch Prediction mode
IBRS_ALL, // [16] (a) IBRS always on mode
STIBP_ALL, // [17] (a) STIBP always on mode
IBRS_PREF, // [18] (a) IBRS is preferred to software solution
IBRS_SAMEMODE, // [19] (a) IBRS provides same mode speculation limits
EFER_LMSLE_UNSUP, // [20] (a) EFER.LMSLE is unsupported
INVLPGB_NESTPGS, // [21] (a) INVLPGB support for invalidating guest nested translations
SSBD, // [24] (a) Speculative Store Bypass Disable
SSBD_VSC, // [25] (a) (SsbdVirtSpecCtrl) Use VIRT_SPEC_CTL MSR (C001_011Fh) for SSBD
SSBD_NR, // [26] (a) (SsbdNotRequired) SSBD not needed on this processor
CPPC, // [27] (a) Collaborative Processor Performance Control
PSFD, // [28] (a) Predictive Store Forward Disable
BTC_NO, // [29] (a) The processor is not affected by branch type confusion
IBPB_RET, // [30] (a) IBPB clears return address predictor
{leaf $80000021, EAX register -----------------------------------------------}
NONESTDATABP, // [00] (a) Processor ignores nested data breakpoints
FSGSBW_NSER, // [01] (a) WRMSR to FS.Base, GS.Base and KernelGSBase MSRs is not serializing
LFENCE_SER, // [02] (a) LFENCE is always dispatch serializing
SMMPGCFGLOCK, // [03] (a) SMM paging configuration lock supported
NULLSELCLRBASE, // [06] (a) Null segment selector loads also clear the destination segment register base and limit
UPADDRIGNORE, // [07] (a) Upper Address Ignore is supported
AUTOIBRS, // [08] (a) Automatic IBRS
NOSMMCTL, // [09] (a) SMM_CTL MSR (C001_0116h) is not supported
REPSTOS_FS, // [10] (a) Fast short REP STOSB supported
REPCMPS_FS, // [11] (a) Fast short REPE CMPSB supported
PMC2_PRECRET, // [12] (a) MSR PerfEvtSel2[PreciseRetire] is supported
PREFETCHCTLMSR, // [13] (a) Prefetch control MSR supported. See Core::X86::Msr::PrefetchControl in BKDG or PPR for details
L2TLBSIZEX32, // [14] (a) L2TLB sizes are encoded as multiples of 32
AMD_ERMSB, // [15] (a) AMD implementation of Enhanced REP MOVSB/STOSB is supported
OP0F017RECL, // [16] (a) 0F 01/7 opcode space is reserved for AMD use
CPUIDUSESDIS, // [17] (a) CPUID disable for non-privileged software
EPSF, // [18] (a) Enhanced Predictive Store Forwarding supported
REPSCASB_FS, // [19] (a) Fast short REP SCASB supported
PREFETCHI, // [20] (a) IC prefetch supported
FP512_DOWNGD, // [21] (a) FP512 is downgraded to FP256
ERAPS, // [24] (a) Enhanced Return Address Predictor Security supported
SBPB, // [27] (a) Selective Branch Predictor Barrier supported
IBPB_BRTYPE, // [28] (a) PRED_CMD[IBPB] clears all branch type predictions from the branch predictor
SRSO_NO, // [29] (a) The processor is not affected by Speculative Return Stack Overflow vulnerability
SRSO_USRKRNL_NO, // [30] (a) The processor is not affected by Speculative Return Stack Overflow vulnerability across user/kernel boundaries
SRSO_MSR_FIX: // [31] (a) Software may use MSR_BP_CFG[BpSpecReduce] to mitigate Speculative Return Stack Overflow vulnerability
Boolean))))));
end;
//------------------------------------------------------------------------------
type
TCPUIDInfo_SupportedExtensions = packed record
X87, // x87 FPU features.FPU
EmulatedX87, // x87 is emulated CR0[EM:2]=1
MMX, // MMX Technology features.MMX and CR0[EM:2]=0
SSE, // Streaming SIMD Extensions features.FXSR and features.SSE and (system support for SSE)
SSE2, // Streaming SIMD Extensions 2 features.SSE2 and SSE
SSE3, // Streaming SIMD Extensions 3 features.SSE3 and SSE2
SSSE3, // Supplemental Streaming SIMD Extensions 3 features.SSSE3 and SSE3
SSE4_1, // Streaming SIMD Extensions 4.1 features.SSE4_1 and SSSE3
SSE4_2, // Streaming SIMD Extensions 4.2 features.SSE4_2 and SSE4_1
CRC32, // CRC32 Instruction features.SSE4_2
POPCNT, // POPCNT Instruction features.POPCNT and features.SSE4_2
AES, // AES New Instructions features.AES and SSE2
PCLMULQDQ, // PCLMULQDQ Instruction features.PCLMULQDQ and SSE2
GFNI, // Galois Field Instructions features.GFNI and SSE2
AVX, // Advanced Vector Extensions features.OSXSAVE -> XCR0[1..2]=11b and features.AVX
F16C, // 16bit Float Conversion Instructions features.F16C and AVX
FMA, // Fused-Multiply-Add Instructions features.FMA and AVX
// VEX-encoded instructions supporting three-operand format
VAES128, // VEX-encoded 128bit AES Instructions features.AES and AVX
VPCLMULQDQ128, // VEX-encoded 128bit PCLMULQDQ Instruction features.PCLMULQDQ and AVX
VAES, // VEX-encoded 256bit AES Instructions features.VAES and AVX
VPCLMULQDQ, // VEX-encoded 256bit PCLMULQDQ Instruction features.VPCLMULQDQ and AVX
// VGFNI supports both 128bit and 256 vectors
VGFNI, // VEX-encoded Galois Field Instructions features.GFNI and AVX
AVX2: Boolean; // Advanced Vector Extensions 2 features.AVX2 and AVX
case Integer of
0: (AVX512F, // see AVX512.Supported
AVX512ER, // see AVX512.AVX512ER
AVX512PF, // see AVX512.AVX512PF
AVX512CD, // see AVX512.AVX512CD
AVX512DQ, // see AVX512.AVX512DQ
AVX512BW: // see AVX512.AVX512BW
Boolean);
1: (AVX512: record
// structured AVX512 extension report
Supported, // AVX-512 Foundation Instructions features.OSXSAVE -> XCR0[1..2]=11b and
// XCR0[5..7]=111b and features.AVX512F
{
Extensions AVX512ER, AVX512PF, AVX512_4VNNIW and AVX512_4FMAPS are
available only on Intel Xeon Phi processors.
WARNING - If any AVX512 instruction is to operate on 256bit or 128bit
vectors (not only on 512bit vector), it is necessary to also
check AVX512VL flag (vector length extension). But note that
some instructions cannot operate on 128bit vectors even when
vector length extension is supported.
}
AVX512ER, // AVX-512 Exponential and Reciprocal Instructions features.AVX512ER and AVX512F
AVX512PF, // AVX-512 Prefetch Instructions features.AVX512PF and AVX512F
AVX512CD, // AVX-512 Conflict Detection Instructions features.AVX512CD and AVX512F
AVX512DQ, // AVX-512 Doubleword and Quadword Instructions features.AVX512DQ and AVX512F
AVX512BW, // AVX-512 Byte and Word Instructions features.AVX512BW and AVX512F
AVX512VL, // AVX-512 Vector Length Extensions features.AVX512VL and AVX512F
AVX512_VBMI, // AVX-512 Vector Bit Manipulation Instructions features.AVX512_VBMI and AVX512F
AVX512_VBMI2, // AVX-512 Vector Bit Manipulation Instructions 2 features.AVX512_VBMI2 and AVX512F
AVX512_IFMA, // AVX-512 Integer Fused Multiply-Add Instructions features.AVX512_IFMA and AVX512F
AVX512_VNNI, // AVX-512 Vector Neural Network Instructions features.AVX512_VNNI and AVX512F
AVX512_BF16, // AVX-512 VNNI supporting bfloat16 features.AVX512_BF16 and AVX512F
AVX512_VPOPCNTDQ, // AVX-512 VPOPCNTD and VPOPCNTQ instructions features.AVX512_VPOPCNTDQ and AVX512F
AVX512_BITALG, // AVX-512 Bit Algorithms features.AVX512_BITALG and AVX512F
AVX512_FP16, // AVX-512 Half-precision floats (16bit) support features.AVX512_FP16 and AVX512F
AVX512_4VNNIW, // AVX-512 4-iteration single-precision dot products features.AVX512_4VNNIW and AVX512F
AVX512_4FMAPS, // AVX-512 4-iteration single-precision fused multiply-add features.AVX512_4FMAPS and AVX512F
AVX512_VP2INTERSECT, // AVX-512 Intersect instructions features.AVX512_VP2INTERSECT and AVX512F
VAES, // EVEX-encoded AES Instructions features.VAES and AVX512F
VPCLMULQDQ, // EVEX-encoded PCLMULQDQ Instruction features.VPCLMULQDQ and AVX512F
GFNI: // EVEX-encoded Galois Field Instructions features.GFNI and AVX512F
Boolean;
end;
{
Following three substructures (AVX10, AMX and APX) are all preliminar,
because afaik none of the corresponding extensions currently have final
specification (2025-11).
This means not only that new fields can be added, but also that any field
can be changed or even removed, be aware of that.
}
AVX10: record // Advanced Vector Extensions 10
Supported: Boolean; // AVX10 supported and usable features.AVX10
Version: Byte; // >= 1, 0 if AVX10 is not supported features.AVX10 -> CPUID:0x24.0:EBX[0..7]
{
If AVX10 is not supported in any version, then all three following flags
(VecXXX) are guaranteed to be false.
Note that these fields are superfluous, because current specification of
AVX10 states that support for all vector lengths is mandatory for all
implementations. Also, the corresponding bits are, in current documents,
marked as reserved and always read as 1.
These fields are kept for backward compatibility and their values can
be relied upon.
}
Vec128, // 128bit vectors supported features.AVX10 -> CPUID:0x24.0:EBX[16]
Vec256, // 256bit vectors supported features.AVX10 -> CPUID:0x24.0:EBX[17]
Vec512: Boolean; // 512bit vectors supported features.AVX10 -> CPUID:0x24.0:EBX[18]
end;
AMX: record // Advanced Matrix Extensions
Supported, // Tile architecture supported features.AMX_TILE
AMX_INT8, // AMX operations on 8-bit integers features.AMX_INT8
AMX_BF16, // AMX operations on bfloat16 features.AMX_BF16
AMX_COMPLEX, // AMX-COMPLEX instructions features.AMX_COMPLEX
AMX_FP16, // AMX operations on FP16 numbers features.AMX_FP16
AMX_FP8, // AMX computations for the FP8 data type features.AMX_FP8
AMX_TF32, // AMX-TF32 (FP19) instructions features.AMX_TF32
AMX_AVX512, // AMX_AVX512 instructions features.AMX_AVX512
AMX_MOVRS: Boolean; // AMX-MOVRS instructions features.AMX_MOVRS
end;
APX: record
Supported: Boolean; // Advanced Performance Extensions features.APX_F
// expecting some future extensions or flags
end);
end;
//------------------------------------------------------------------------------
type
TCPUIDInfo = record
// leaf 0x00000000
ManufacturerIDString: String;
ManufacturerID: TCPUIDManufacturerID; // discerned from ManufacturerIDString
// leaf 0x00000001
ProcessorType: Byte;
ProcessorFamily: Byte;
ProcessorModel: Byte;
ProcessorStepping: Byte;
AdditionalInfo: TCPUIDInfo_AdditionalInfo;
// leafs 0x00000001+ (basic leafs)
ProcessorFeatures: TCPUIDInfo_Features;
// leafs 0x80000001+ (extended leafs)
ExtendedProcessorFeatures: TCPUIDInfo_ExtendedFeatures;
// leaf 0x80000002 - 0x80000004
BrandString: String;
// some processor extensions whose full support cannot (or should not)
// be determined directly from processor features...
SupportedExtensions: TCPUIDInfo_SupportedExtensions;
end;
{===============================================================================
TSimpleCPUID - class declaration
===============================================================================}
type
TSimpleCPUID = class(TObject)
protected
fSupported: Boolean;
fLoaded: Boolean;
fLeafs: array of TCPUIDLeaf;
fInfo: TCPUIDInfo;
fHiStdLeaf: Integer; // index of highest standard leaf
Function GetLeaf(Index: Integer): TCPUIDLeaf; virtual;
Function GetLeafCount: Integer; virtual;
// leading and processing of CPUID leafs
procedure LoadLeafGroup(GroupMask: UInt32); virtual;
procedure LoadStdLeafs; virtual; // standard leafs
procedure ProcessLeaf_0000_0000; virtual;
procedure ProcessLeaf_0000_0001; virtual;
procedure ProcessLeaf_0000_0002; virtual;
procedure ProcessLeaf_0000_0004; virtual;
procedure ProcessLeaf_0000_0007; virtual;
procedure ProcessLeaf_0000_000B; virtual;
procedure ProcessLeaf_0000_000D; virtual;
procedure ProcessLeaf_0000_000F; virtual;
procedure ProcessLeaf_0000_0010; virtual;
procedure ProcessLeaf_0000_0012; virtual;
procedure ProcessLeaf_0000_0014; virtual;
procedure ProcessLeaf_0000_0017; virtual;
procedure ProcessLeaf_0000_0018; virtual;
procedure ProcessLeaf_0000_001A; virtual;
procedure ProcessLeaf_0000_001B; virtual;
procedure ProcessLeaf_0000_001D; virtual;
procedure ProcessLeaf_0000_001E; virtual;
procedure ProcessLeaf_0000_001F; virtual;
procedure ProcessLeaf_0000_0020; virtual;
procedure ProcessLeaf_0000_0023; virtual;
procedure ProcessLeaf_0000_0024; virtual;
procedure ProcessLeaf_0000_0027; virtual;
procedure ProcessLeaf_0000_0028; virtual;
procedure LoadPhiLeafs; virtual; // Intel Xeon Phi leafs
procedure LoadHypLeafs; virtual; // hypervisor leafs
procedure LoadExtLeafs; virtual; // extended leafs
procedure ProcessLeaf_8000_0001; virtual;
procedure ProcessLeaf_8000_0002_to_8000_0004; virtual;
procedure ProcessLeaf_8000_0007; virtual;
procedure ProcessLeaf_8000_0008; virtual;
procedure ProcessLeaf_8000_001D; virtual;
procedure ProcessLeaf_8000_0021; virtual;
procedure LoadTNMLeafs; virtual; // Transmeta leafs
procedure LoadCNTLeafs; virtual; // Centaur leafs
procedure LoadAllLeafs; virtual;
// information parsing
procedure InitSupportedExtensions; virtual;
procedure ClearInfo; virtual;
// object init/final
procedure Initialize(LoadInfo: Boolean); virtual;
procedure Finalize; virtual;
// leaf utilities
class Function SameLeafData(A,B: TCPUIDLeafData): Boolean; virtual;
Function EqualsToHighestStdLeafData(LeafData: TCPUIDLeafData): Boolean; virtual;
public
constructor Create(LoadInfo: Boolean = True);
destructor Destroy; override;
procedure LoadInfo; virtual;
Function LowIndex: Integer; virtual;
Function HighIndex: Integer; virtual;
Function CheckIndex(Index: Integer): Boolean; virtual;
Function IndexOf(LeafID: UInt32): Integer; virtual;
Function Find(LeafID: UInt32; out Index: Integer): Boolean; virtual;
property Supported: Boolean read fSupported;
property Loaded: Boolean read fLoaded;
property Leafs[Index: Integer]: TCPUIDLeaf read GetLeaf; default;
property Count: Integer read GetLeafCount;
property Info: TCPUIDInfo read fInfo;
end;
{===============================================================================
--------------------------------------------------------------------------------
TSimpleCPUIDEx
--------------------------------------------------------------------------------
===============================================================================}
type
TCPUSet = {$IFNDEF Windows}array[0..Pred(128 div SizeOf(PtrUInt))] of{$ENDIF} PtrUInt;
PCPUSet = ^TCPUSet;
{===============================================================================
TSimpleCPUIDEx - class declaration
===============================================================================}
type
TSimpleCPUIDEx = class(TSimpleCPUID)
protected
fProcessorID: Integer;
class procedure SetThreadAffinity(var ProcessorMask: TCPUSet); virtual;
public
class Function ProcessorAvailable(ProcessorID: Integer): Boolean; virtual;
constructor Create(ProcessorID: Integer = 0; LoadInfo: Boolean = True);
procedure LoadInfo; override;
property ProcessorID: Integer read fProcessorID write fProcessorID;
end;
implementation
uses
{$IFDEF Windows}Windows{$ELSE}BaseUnix{$ENDIF}
{$IF not Defined(FPC) and (CompilerVersion >= 20)} // Delphi 2009+
, AnsiStrings
{$IFEND};
{$IFNDEF Windows}
{$LINKLIB C}
{$ENDIF}
{===============================================================================
External and system functions
===============================================================================}
{$IFDEF Windows}
Function GetProcessAffinityMask(hProcess: THandle; lpProcessAffinityMask,lpSystemAffinityMask: PPtrUInt): BOOL; stdcall; external kernel32;
{$ELSE}
//------------------------------------------------------------------------------
Function getpid: pid_t; cdecl; external;
Function errno_ptr: pcInt; cdecl; external name '__errno_location';
Function sched_getaffinity(pid: pid_t; cpusetsize: size_t; mask: PCPUSet): cint; cdecl; external;
Function sched_setaffinity(pid: pid_t; cpusetsize: size_t; mask: PCPUSet): cint; cdecl; external;
//------------------------------------------------------------------------------
threadvar
ThrErrorCode: cInt;
Function CheckErr(ReturnedValue: cInt): Boolean;
begin
Result := ReturnedValue = 0;
If Result then
ThrErrorCode := 0
else
ThrErrorCode := errno_ptr^;
end;
//------------------------------------------------------------------------------
Function GetLastError: cInt;
begin
Result := ThrErrorCode;
end;
{$ENDIF}
{===============================================================================
Auxiliary routines
===============================================================================}
{$IF not(Defined(Windows) and Defined(x86))}
Function GetBit(Value: UInt32; Bit: Integer): Boolean; overload;{$IFDEF CanInline} inline; {$ENDIF}
begin
Result := ((Value shr Bit) and 1) <> 0;
end;
{$IFEND}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function GetBit(const Value: TCPUSet; Bit: Integer): Boolean; overload;{$IF Defined(Windows) and Defined(CanInline)} inline; {$IFEND}
begin
{$IFDEF Windows}
Result := ((Value shr Bit) and 1) <> 0;
{$ELSE}
{$IFDEF x64}
Result := Value[Bit shr 6] and PtrUInt(PtrUInt(1) shl (Bit and 63)) <> 0;
{$ELSE}
Result := Value[Bit shr 5] and PtrUInt(PtrUInt(1) shl (Bit and 31)) <> 0;
{$ENDIF}
{$ENDIF}
end;
//------------------------------------------------------------------------------
procedure SetBit(var Value: TCPUSet; Bit: Integer);{$IF Defined(Windows) and Defined(CanInline)} inline; {$IFEND}
begin
{$IFDEF Windows}
Value := Value or PtrUInt(PtrUInt(1) shl Bit);
{$ELSE}
{$IFDEF x64}
Value[Bit shr 6] := Value[Bit shr 6] or PtrUInt(PtrUInt(1) shl (Bit and 63));
{$ELSE}
Value[Bit shr 5] := Value[Bit shr 5] or PtrUInt(PtrUInt(1) shl (Bit and 31));
{$ENDIF}
{$ENDIF}
end;
//------------------------------------------------------------------------------
Function GetBits(Value: UInt32; FromBit, ToBit: Integer): UInt32;{$IFDEF CanInline} inline; {$ENDIF}
begin
Result := (Value and ($FFFFFFFF shr (31 - ToBit))) shr FromBit;
end;
//------------------------------------------------------------------------------
Function GetMSW: UInt16 assembler; register;
asm
{
Replacement for GetCR0 (now removed), which cannot be used in user mode.
It returns only lower 16 bits of CR0 (a Machine Status Word), but that should
suffice.
}
SMSW AX
end;
//------------------------------------------------------------------------------
Function GetXCR0L: UInt32; assembler; register;
asm
XOR ECX, ECX
// note - support for XGETBV (OSXSAVE) IS checked before calling this routine
DB $0F, $01, $D0 // XGETBV (XCR0.Low -> EAX (result), XCR0.Hi -> EDX)
end;
//------------------------------------------------------------------------------
procedure TestSSE; register; assembler;
asm
// following should preserve content of XMM0
ORPS XMM0, XMM0
end;
//------------------------------------------------------------------------------
Function CanExecuteSSE: Boolean;
begin
try
TestSSE;
Result := True;
except
// eat all exceptions
Result := False;
end;
end;
{===============================================================================
Main CPUID routines (ASM)
===============================================================================}
Function CPUIDSupported: Boolean;
const