// File: j-faria[P]kima/eigen/Eigen/src/Core/util/Memory.h
// Function: Eigen::internal::queryCacheSizes_intel_codes(int&, int&, int&)
inline void queryCacheSizes_intel_codes(int& l1, int& l2, int& l3)
{
  int abcd[4];
  abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
  l1 = l2 = l3 = 0;
  EIGEN_CPUID(abcd,0x00000002,0);
  unsigned char * bytes = reinterpret_cast<unsigned char *>(abcd)+2;
  bool check_for_p2_core2 = false;
  for(int i=0; i<14; ++i)
  {
    switch(bytes[i])
    {
      case 0x0A: l1 = 8; break;   // 0Ah   data L1 cache, 8 KB, 2 ways, 32 byte lines
      case 0x0C: l1 = 16; break;  // 0Ch   data L1 cache, 16 KB, 4 ways, 32 byte lines
      case 0x0E: l1 = 24; break;  // 0Eh   data L1 cache, 24 KB, 6 ways, 64 byte lines
      case 0x10: l1 = 16; break;  // 10h   data L1 cache, 16 KB, 4 ways, 32 byte lines (IA-64)
      case 0x15: l1 = 16; break;  // 15h   code L1 cache, 16 KB, 4 ways, 32 byte lines (IA-64)
      case 0x2C: l1 = 32; break;  // 2Ch   data L1 cache, 32 KB, 8 ways, 64 byte lines
      case 0x30: l1 = 32; break;  // 30h   code L1 cache, 32 KB, 8 ways, 64 byte lines
      case 0x60: l1 = 16; break;  // 60h   data L1 cache, 16 KB, 8 ways, 64 byte lines, sectored
      case 0x66: l1 = 8; break;   // 66h   data L1 cache, 8 KB, 4 ways, 64 byte lines, sectored
      case 0x67: l1 = 16; break;  // 67h   data L1 cache, 16 KB, 4 ways, 64 byte lines, sectored
      case 0x68: l1 = 32; break;  // 68h   data L1 cache, 32 KB, 4 ways, 64 byte lines, sectored
      case 0x1A: l2 = 96; break;   // code and data L2 cache, 96 KB, 6 ways, 64 byte lines (IA-64)
      case 0x22: l3 = 512; break;   // code and data L3 cache, 512 KB, 4 ways (!), 64 byte lines, dual-sectored
      case 0x23: l3 = 1024; break;   // code and data L3 cache, 1024 KB, 8 ways, 64 byte lines, dual-sectored
      case 0x25: l3 = 2048; break;   // code and data L3 cache, 2048 KB, 8 ways, 64 byte lines, dual-sectored
      case 0x29: l3 = 4096; break;   // code and data L3 cache, 4096 KB, 8 ways, 64 byte lines, dual-sectored
      case 0x39: l2 = 128; break;   // code and data L2 cache, 128 KB, 4 ways, 64 byte lines, sectored
      case 0x3A: l2 = 192; break;   // code and data L2 cache, 192 KB, 6 ways, 64 byte lines, sectored
      case 0x3B: l2 = 128; break;   // code and data L2 cache, 128 KB, 2 ways, 64 byte lines, sectored
      case 0x3C: l2 = 256; break;   // code and data L2 cache, 256 KB, 4 ways, 64 byte lines, sectored
      case 0x3D: l2 = 384; break;   // code and data L2 cache, 384 KB, 6 ways, 64 byte lines, sectored
      case 0x3E: l2 = 512; break;   // code and data L2 cache, 512 KB, 4 ways, 64 byte lines, sectored
      case 0x40: l2 = 0; break;   // no integrated L2 cache (P6 core) or L3 cache (P4 core)
      case 0x41: l2 = 128; break;   // code and data L2 cache, 128 KB, 4 ways, 32 byte lines
      case 0x42: l2 = 256; break;   // code and data L2 cache, 256 KB, 4 ways, 32 byte lines
      case 0x43: l2 = 512; break;   // code and data L2 cache, 512 KB, 4 ways, 32 byte lines
      case 0x44: l2 = 1024; break;   // code and data L2 cache, 1024 KB, 4 ways, 32 byte lines
      case 0x45: l2 = 2048; break;   // code and data L2 cache, 2048 KB, 4 ways, 32 byte lines
      case 0x46: l3 = 4096; break;   // code and data L3 cache, 4096 KB, 4 ways, 64 byte lines
      case 0x47: l3 = 8192; break;   // code and data L3 cache, 8192 KB, 8 ways, 64 byte lines
      case 0x48: l2 = 3072; break;   // code and data L2 cache, 3072 KB, 12 ways, 64 byte lines
      case 0x49: if(l2!=0) l3 = 4096; else {check_for_p2_core2=true; l3 = l2 = 4096;} break;// code and data L3 cache, 4096 KB, 16 ways, 64 byte lines (P4) or L2 for core2
      case 0x4A: l3 = 6144; break;   // code and data L3 cache, 6144 KB, 12 ways, 64 byte lines
      case 0x4B: l3 = 8192; break;   // code and data L3 cache, 8192 KB, 16 ways, 64 byte lines
      case 0x4C: l3 = 12288; break;   // code and data L3 cache, 12288 KB, 12 ways, 64 byte lines
      case 0x4D: l3 = 16384; break;   // code and data L3 cache, 16384 KB, 16 ways, 64 byte lines
      case 0x4E: l2 = 6144; break;   // code and data L2 cache, 6144 KB, 24 ways, 64 byte lines
      case 0x78: l2 = 1024; break;   // code and data L2 cache, 1024 KB, 4 ways, 64 byte lines
      case 0x79: l2 = 128; break;   // code and data L2 cache, 128 KB, 8 ways, 64 byte lines, dual-sectored
      case 0x7A: l2 = 256; break;   // code and data L2 cache, 256 KB, 8 ways, 64 byte lines, dual-sectored
      case 0x7B: l2 = 512; break;   // code and data L2 cache, 512 KB, 8 ways, 64 byte lines, dual-sectored
      case 0x7C: l2 = 1024; break;   // code and data L2 cache, 1024 KB, 8 ways, 64 byte lines, dual-sectored
      case 0x7D: l2 = 2048; break;   // code and data L2 cache, 2048 KB, 8 ways, 64 byte lines
      case 0x7E: l2 = 256; break;   // code and data L2 cache, 256 KB, 8 ways, 128 byte lines, sect. (IA-64)
      case 0x7F: l2 = 512; break;   // code and data L2 cache, 512 KB, 2 ways, 64 byte lines
      case 0x80: l2 = 512; break;   // code and data L2 cache, 512 KB, 8 ways, 64 byte lines
      case 0x81: l2 = 128; break;   // code and data L2 cache, 128 KB, 8 ways, 32 byte lines
      case 0x82: l2 = 256; break;   // code and data L2 cache, 256 KB, 8 ways, 32 byte lines
      case 0x83: l2 = 512; break;   // code and data L2 cache, 512 KB, 8 ways, 32 byte lines
      case 0x84: l2 = 1024; break;   // code and data L2 cache, 1024 KB, 8 ways, 32 byte lines
      case 0x85: l2 = 2048; break;   // code and data L2 cache, 2048 KB, 8 ways, 32 byte lines
      case 0x86: l2 = 512; break;   // code and data L2 cache, 512 KB, 4 ways, 64 byte lines
      case 0x87: l2 = 1024; break;   // code and data L2 cache, 1024 KB, 8 ways, 64 byte lines
      case 0x88: l3 = 2048; break;   // code and data L3 cache, 2048 KB, 4 ways, 64 byte lines (IA-64)
      case 0x89: l3 = 4096; break;   // code and data L3 cache, 4096 KB, 4 ways, 64 byte lines (IA-64)
      case 0x8A: l3 = 8192; break;   // code and data L3 cache, 8192 KB, 4 ways, 64 byte lines (IA-64)
      case 0x8D: l3 = 3072; break;   // code and data L3 cache, 3072 KB, 12 ways, 128 byte lines (IA-64)

      default: break;
    }
  }
  if(check_for_p2_core2 && l2 == l3)
    l3 = 0;
  l1 *= 1024;
  l2 *= 1024;
  l3 *= 1024;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rax
movl $0x0, (%rax)
movl $0x2, %eax
xorl %ecx, %ecx
xchgq %rbx, %rsi
cpuid
xchgq %rbx, %rsi
movl %esi, -0x44(%rbp)
movl %eax, %esi
movl -0x44(%rbp), %eax
movl %esi, -0x30(%rbp)
movl %eax, -0x2c(%rbp)
movl %ecx, -0x28(%rbp)
movl %edx, -0x24(%rbp)
leaq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movb $0x0, -0x39(%rbp)
movl $0x0, -0x40(%rbp)
cmpl $0xe, -0x40(%rbp)
jge 0x4250d
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
addl $-0xa, %eax
movl %eax, %ecx
movq %rcx, -0x50(%rbp)
subl $0x83, %eax
ja 0x424fb
movq -0x50(%rbp), %rax
leaq 0x755fb(%rip), %rcx     # 0xb7794
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movl $0x8, (%rax)
jmp 0x424fd
movq -0x8(%rbp), %rax
movl $0x10, (%rax)
jmp 0x424fd
movq -0x8(%rbp), %rax
movl $0x18, (%rax)
jmp 0x424fd
movq -0x8(%rbp), %rax
movl $0x10, (%rax)
jmp 0x424fd
movq -0x8(%rbp), %rax
movl $0x10, (%rax)
jmp 0x424fd
movq -0x8(%rbp), %rax
movl $0x20, (%rax)
jmp 0x424fd
movq -0x8(%rbp), %rax
movl $0x20, (%rax)
jmp 0x424fd
movq -0x8(%rbp), %rax
movl $0x10, (%rax)
jmp 0x424fd
movq -0x8(%rbp), %rax
movl $0x8, (%rax)
jmp 0x424fd
movq -0x8(%rbp), %rax
movl $0x10, (%rax)
jmp 0x424fd
movq -0x8(%rbp), %rax
movl $0x20, (%rax)
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x60, (%rax)
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x200, (%rax)          # imm = 0x200
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x400, (%rax)          # imm = 0x400
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x800, (%rax)          # imm = 0x800
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x1000, (%rax)         # imm = 0x1000
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x80, (%rax)
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0xc0, (%rax)
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x80, (%rax)
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x100, (%rax)          # imm = 0x100
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x180, (%rax)          # imm = 0x180
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x200, (%rax)          # imm = 0x200
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x80, (%rax)
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x100, (%rax)          # imm = 0x100
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x200, (%rax)          # imm = 0x200
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x400, (%rax)          # imm = 0x400
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x800, (%rax)          # imm = 0x800
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x1000, (%rax)         # imm = 0x1000
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x2000, (%rax)         # imm = 0x2000
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0xc00, (%rax)          # imm = 0xC00
jmp 0x424fd
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x42388
movq -0x18(%rbp), %rax
movl $0x1000, (%rax)         # imm = 0x1000
jmp 0x423a0
movb $0x1, -0x39(%rbp)
movq -0x10(%rbp), %rax
movl $0x1000, (%rax)         # imm = 0x1000
movq -0x18(%rbp), %rax
movl $0x1000, (%rax)         # imm = 0x1000
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x1800, (%rax)         # imm = 0x1800
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x2000, (%rax)         # imm = 0x2000
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x3000, (%rax)         # imm = 0x3000
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x4000, (%rax)         # imm = 0x4000
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x1800, (%rax)         # imm = 0x1800
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x400, (%rax)          # imm = 0x400
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x80, (%rax)
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x100, (%rax)          # imm = 0x100
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x200, (%rax)          # imm = 0x200
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x400, (%rax)          # imm = 0x400
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x800, (%rax)          # imm = 0x800
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x100, (%rax)          # imm = 0x100
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x200, (%rax)          # imm = 0x200
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x200, (%rax)          # imm = 0x200
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x80, (%rax)
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x100, (%rax)          # imm = 0x100
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x200, (%rax)          # imm = 0x200
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x400, (%rax)          # imm = 0x400
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x800, (%rax)          # imm = 0x800
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x200, (%rax)          # imm = 0x200
jmp 0x424fd
movq -0x10(%rbp), %rax
movl $0x400, (%rax)          # imm = 0x400
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x800, (%rax)          # imm = 0x800
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x1000, (%rax)         # imm = 0x1000
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0x2000, (%rax)         # imm = 0x2000
jmp 0x424fd
movq -0x18(%rbp), %rax
movl $0xc00, (%rax)          # imm = 0xC00
jmp 0x424fd
jmp 0x424fd
jmp 0x424ff
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x42164
testb $0x1, -0x39(%rbp)
je 0x4252b
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x4252b
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
shll $0xa, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
shll $0xa, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
shll $0xa, %ecx
movl %ecx, (%rax)
popq %rbp
retq
nop