unit CacheDesc;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TfrmCache = class(TForm)
    meCache: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

uses cpuinfo;

{$R *.DFM}

procedure TfrmCache.Button1Click(Sender: TObject);
begin
 ModalResult:=mrOK;
end;

procedure TfrmCache.FormCreate(Sender: TObject);
var
 I: Integer;
 B: Byte;
 S: String;
begin
 for I:=low(CPUID.CPUID.CacheDescriptors) to High(CPUID.CPUID.CacheDescriptors) do begin
  B:=CPUID.CPUID.CacheDescriptors[I];
  case B of
   $01: S:='Instruction TLB, 4K pages, 4-way set associative, 32 entries';
   $02: S:='Instruction TLB, 4M pages, fully associative, 2 entries';
   $03: S:='Data TLB, 4K pages, 4-way set associative, 64 entries';
   $04: S:='Data TLB, 4M pages, 4-way set associative, 8 entries';
   $06: S:='Instruction cache, 8K, 4-way set associative, 32 byte line size';
   $08: S:='Instruction cache, 16K, 4-way set associative, 32 byte line size';
   $0a: S:='Data cache, 8K, 2-way set associative, 32 byte line size';
   $0c: S:='Data cache, 16K, 2-way set associative, 32 byte line size';
   $40: S:='No L2 (P6 family) or L3 (P4) Cache';
   $41: S:='Unified cache, 32 byte cache line, 4-way set associative, 128K';
   $42: S:='Unified cache, 32 byte cache line, 4-way set associative, 256K';
   $43: S:='Unified cache, 32 byte cache line, 4-way set associative, 512K';
   $44: S:='Unified cache, 32 byte cache line, 4-way set associative, 1M';
   $45: S:='Unified cache, 32 byte cache line, 4-way set associative, 2M';
   $50: S:='Instruction TLB, 4K, 2M or 4M pages, fully associative, 64 entries';
   $51: S:='Instruction TLB, 4K, 2M or 4M pages, fully associative, 128 entries';
   $52: S:='Instruction TLB, 4K, 2M or 4M pages, fully associative, 256 entries';
   $5b: S:='Data TLB, 4K or 4M pages, fully associative, 64 entries';
   $5c: S:='Data TLB, 4K or 4M pages, fully associative, 128 entries';
   $5d: S:='Data TLB, 4K or 4M pages, fully associative, 256 entries';
   $66: S:='Data cache, sectored, 64 byte cache line, 4 way set associative, 8K';
   $67: S:='Data cache, sectored, 64 byte cache line, 4 way set associative, 16K';
   $68: S:='Data cache, sectored, 64 byte cache line, 4 way set associative, 32K';
   $70: S:='Instruction Trace cache, 8 way set associative, 12K uOps';
   $71: S:='Instruction Trace cache, 8 way set associative, 16K uOps';
   $72: S:='Instruction Trace cache, 8 way set associative, 32K uOps';
   $79: S:='Unified cache, sectored, 64 byte cache line, 8 way set associative, 128K';
   $7a: S:='Unified cache, sectored, 64 byte cache line, 8 way set associative, 256K';
   $7b: S:='Unified cache, sectored, 64 byte cache line, 8 way set associative, 512K';
   $7c: S:='Unified cache, sectored, 64 byte cache line, 8 way set associative, 1M';
   $82: S:='Unified cache, 32 byte cache line, 8 way set associative, 256K';
   $84: S:='Unified cache, 32 byte cache line, 8 way set associative, 1M';
   $85: S:='Unified cache, 32 byte cache line, 8 way set associative, 2M';
  else
   S:='Unknown';
  end;
  if B>0 then begin
   S:='['+IntToHex(B,2)+'] '+S;
   meCache.Lines.Add(S);
  end;
 end;
 if meCache.Lines.Count=0 then meCache.Lines.Add('[No cache descriptors]');
end;

end.
