cpuinfo.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. {
  2. Copyright (c) 1998-2000 by Florian Klaempfl
  3. Basic Processor information
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. Unit cpuinfo;
  18. {$i fpcdefs.inc}
  19. Interface
  20. uses
  21. globtype;
  22. Type
  23. bestreal = extended;
  24. {$ifdef FPC_HAS_TYPE_EXTENDED}
  25. bestrealrec = TExtended80Rec;
  26. {$else}
  27. bestrealrec = TDoubleRec;
  28. {$endif}
  29. ts32real = single;
  30. ts64real = double;
  31. ts80real = extended;
  32. ts128real = type extended;
  33. ts64comp = type extended;
  34. pbestreal=^bestreal;
  35. tcputype =
  36. (cpu_none,
  37. cpu_x86_64,
  38. cpu_x86_64_v1,
  39. cpu_athlon64,
  40. cpu_x86_64_v2,
  41. cpu_core_i,
  42. cpu_bobcat,
  43. cpu_core_avx,
  44. cpu_jaguar,
  45. cpu_piledriver,
  46. cpu_excavator,
  47. cpu_core_avx2,
  48. cpu_x86_64_v3,
  49. cpu_zen,
  50. cpu_zen2,
  51. cpu_x86_64_v4,
  52. cpu_icelake,
  53. cpu_icelake_client,
  54. cpu_icelake_server,
  55. cpu_zen3,
  56. cpu_zen4
  57. );
  58. tfputype =
  59. (fpu_none,
  60. // fpu_soft, { generic }
  61. fpu_sse64,
  62. fpu_x86_64_v1,
  63. fpu_sse3,
  64. fpu_ssse3,
  65. fpu_sse41,
  66. fpu_sse42,
  67. fpu_x86_64_v2,
  68. fpu_avx,
  69. fpu_fma,
  70. fpu_avx2,
  71. fpu_x86_64_v3,
  72. fpu_avx512f,
  73. fpu_x86_64_v4
  74. );
  75. tcontrollertype =
  76. (ct_none
  77. );
  78. tcontrollerdatatype = record
  79. controllertypestr, controllerunitstr: string[20];
  80. cputype: tcputype; fputype: tfputype;
  81. flashbase, flashsize, srambase, sramsize, eeprombase, eepromsize, bootbase, bootsize: dword;
  82. end;
  83. Const
  84. { Is there support for dealing with multiple microcontrollers available }
  85. { for this platform? }
  86. ControllerSupport = false;
  87. { Size of native extended type }
  88. extended_size = 10;
  89. { target cpu string (used by compiler options) }
  90. target_cpu_string = 'x86_64';
  91. { We know that there are fields after sramsize
  92. but we don't care about this warning }
  93. {$PUSH}
  94. {$WARN 3177 OFF}
  95. embedded_controllers : array [tcontrollertype] of tcontrollerdatatype =
  96. (
  97. (controllertypestr:''; controllerunitstr:''; cputype:cpu_none; fputype:fpu_none; flashbase:0; flashsize:0; srambase:0; sramsize:0));
  98. {$POP}
  99. { calling conventions supported by the code generator }
  100. supported_calling_conventions : tproccalloptions = [
  101. pocall_internproc,
  102. { pocall_compilerproc,
  103. pocall_inline,}
  104. pocall_register,
  105. pocall_safecall,
  106. pocall_stdcall,
  107. pocall_cdecl,
  108. pocall_cppdecl,
  109. pocall_mwpascal,
  110. pocall_sysv_abi_default,
  111. pocall_sysv_abi_cdecl,
  112. pocall_ms_abi_default,
  113. pocall_ms_abi_cdecl,
  114. pocall_vectorcall
  115. ];
  116. cputypestr : array[tcputype] of string[16] = ('',
  117. 'ATHLON64',
  118. 'X86-64',
  119. 'X86-64-V1',
  120. 'COREI',
  121. 'X86-64-V2',
  122. 'BOBCAT',
  123. 'COREAVX',
  124. 'JAGUAR',
  125. 'PILEDRIVER',
  126. 'EXCAVATOR',
  127. 'COREAVX2',
  128. 'X86-64-V3',
  129. 'ZEN',
  130. 'ZEN2',
  131. 'X86-64-V4',
  132. 'ICELAKE',
  133. 'ICELAKE-CLIENT',
  134. 'ICELAKE-SERVER',
  135. 'ZEN3',
  136. 'ZEN4'
  137. );
  138. fputypestr : array[tfputype] of string[9] = (
  139. 'NONE',
  140. // 'SOFT',
  141. 'SSE64',
  142. 'X86-64-V1',
  143. 'SSE3',
  144. 'SSSE3',
  145. 'SSE41',
  146. 'SSE42',
  147. 'X86-64-V2',
  148. 'AVX',
  149. 'FMA',
  150. 'AVX2',
  151. 'X86-64-V3',
  152. 'AVX512F',
  153. 'X86-64-V4'
  154. );
  155. fputypestrllvm : array[tfputype] of string[9] = ('',
  156. // 'SOFT',
  157. '',
  158. 'x86-64-v1',
  159. 'sse3',
  160. 'ssse3',
  161. 'sse4.1',
  162. 'sse4.2',
  163. 'x86-64-v2',
  164. 'avx',
  165. 'fma',
  166. 'avx2',
  167. 'x86-64-v3',
  168. 'avx512f',
  169. 'x86-64-v4'
  170. );
  171. sse_singlescalar = [fpu_sse64..fpu_avx512f];
  172. sse_doublescalar = [fpu_sse64..fpu_avx512f];
  173. fpu_avx_instructionsets = [fpu_avx,fpu_fma,fpu_avx2,fpu_avx512f];
  174. { Supported optimizations, only used for information }
  175. supported_optimizerswitches = genericlevel1optimizerswitches+
  176. genericlevel2optimizerswitches+
  177. genericlevel3optimizerswitches-
  178. { no need to write info about those }
  179. [cs_opt_level1,cs_opt_level2,cs_opt_level3]+
  180. [{$ifndef llvm}cs_opt_regvar,{$endif}cs_opt_loopunroll,cs_opt_stackframe,cs_userbp,
  181. cs_opt_tailrecursion,cs_opt_nodecse,cs_opt_reorder_fields,cs_opt_fastmath];
  182. level1optimizerswitches = genericlevel1optimizerswitches;
  183. level2optimizerswitches = genericlevel2optimizerswitches + level1optimizerswitches +
  184. [{$ifndef llvm}cs_opt_regvar,{$endif}cs_opt_stackframe,cs_opt_tailrecursion,cs_opt_nodecse,cs_opt_consts];
  185. level3optimizerswitches = genericlevel3optimizerswitches + level2optimizerswitches;
  186. level4optimizerswitches = genericlevel4optimizerswitches + level3optimizerswitches + [cs_userbp];
  187. type
  188. tcpuflags =
  189. (CPUX86_HAS_BTX, { Bit-test instructions (BT, BTC, BTR and BTS) are available }
  190. CPUX86_HAS_CMOV, { CMOVcc instructions are available }
  191. CPUX86_HAS_SSEUNIT, { SSE instructions are available }
  192. CPUX86_HAS_SSE2, { SSE2 instructions are available }
  193. CPUX86_HAS_BMI1, { BMI1 instructions are available }
  194. CPUX86_HAS_BMI2, { BMI2 instructions are available }
  195. CPUX86_HAS_CMPXCHG16B, { CMPXCHG16B is available }
  196. CPUX86_HAS_LAHF_SAHF, { LAHF/SAHF is available }
  197. CPUX86_HAS_POPCNT, { POPCNT is available }
  198. CPUX86_HAS_LZCNT, { LZCNT is available }
  199. CPUX86_HAS_MOVBE, { MOVBE is available }
  200. CPUX86_HAS_BSWAP, { BSWAP is available }
  201. CPUX86_HAS_OSXSAVE { XGETBV is available }
  202. );
  203. tfpuflags =
  204. (FPUX86_HAS_SSE3,
  205. FPUX86_HAS_SSE4_1,
  206. FPUX86_HAS_SSE4_2,
  207. FPUX86_HAS_SSSE3,
  208. FPUX86_HAS_AVXUNIT,
  209. FPUX86_HAS_FMA,
  210. FPUX86_HAS_FMA4,
  211. FPUX86_HAS_F16C,
  212. FPUX86_HAS_AVX2,
  213. FPUX86_HAS_32MMREGS,
  214. FPUX86_HAS_AVX512F,
  215. FPUX86_HAS_AVX512BW,
  216. FPUX86_HAS_AVX512CD,
  217. FPUX86_HAS_AVX512VL,
  218. FPUX86_HAS_AVX512DQ
  219. );
  220. { Instruction optimisation hints }
  221. TCPUOptimizeFlags =
  222. (CPUX86_HINT_FAST_BT_REG_IMM, { BT instructions with register source and immediate indices are at least as fast as logical instructions }
  223. CPUX86_HINT_FAST_BT_REG_REG, { BT instructions with register source and register indices are at least as fast as equivalent logical instructions }
  224. CPUX86_HINT_FAST_BTX_REG_IMM, { BTC/R/S instructions with register source and immediate indices are at least as fast as logical instructions }
  225. CPUX86_HINT_FAST_BTX_REG_REG, { BTC/R/S instructions with register source and register indices are at least as fast as equivalent logical instructions }
  226. CPUX86_HINT_FAST_BT_MEM_IMM, { BT instructions with memory sources and inmediate indices are at least as fast as logical instructions }
  227. CPUX86_HINT_FAST_BT_MEM_REG, { BT instructions with memory sources and register indices and a register index are at least as fast as equivalent logical instructions }
  228. CPUX86_HINT_FAST_BTX_MEM_IMM, { BTC/R/S instructions with memory sources and immediate indices are at least as fast as logical instructions }
  229. CPUX86_HINT_FAST_BTX_MEM_REG, { BTC/R/S instructions with memory sources and register indices are at least as fast as equivalent logical instructions }
  230. CPUX86_HINT_FAST_XCHG, { XCHG %reg,%reg executes in 2 cycles or fewer }
  231. CPUX86_HINT_FAST_PDEP_PEXT, { The BMI2 instructions PDEP and PEXT execute in a single cycle }
  232. CPUX86_HINT_FAST_3COMP_ADDR { A 3-component address (base, index and offset) has the same latency as the 2-component version (most notable with LEA instructions) }
  233. );
  234. const
  235. cpu_x86_64_v1_flags = [CPUX86_HAS_BSWAP,CPUX86_HAS_BTX,CPUX86_HAS_CMOV,CPUX86_HAS_SSEUNIT,CPUX86_HAS_SSE2];
  236. cpu_x86_64_v2_flags = cpu_x86_64_v1_flags+[CPUX86_HAS_CMPXCHG16B,CPUX86_HAS_LAHF_SAHF,CPUX86_HAS_POPCNT];
  237. cpu_x86_64_v3_flags = cpu_x86_64_v2_flags+[CPUX86_HAS_BMI1,CPUX86_HAS_BMI2,CPUX86_HAS_LZCNT,CPUX86_HAS_MOVBE,CPUX86_HAS_OSXSAVE]; { most is in the fpu flags here }
  238. cpu_x86_64_v4_flags = cpu_x86_64_v3_flags; { everything is in the fpu flags here }
  239. cpu_capabilities : array[tcputype] of set of tcpuflags = (
  240. { cpu_none } [],
  241. { Athlon64 } cpu_x86_64_v1_flags,
  242. { cpu_x86_64 } cpu_x86_64_v1_flags,
  243. { cpu_x86_64_v1 } cpu_x86_64_v1_flags,
  244. { cpu_core_i } cpu_x86_64_v1_flags+[CPUX86_HAS_POPCNT],
  245. { cpu_x86_64_v2 } cpu_x86_64_v2_flags,
  246. { cpu_bobcat } cpu_x86_64_v1_flags+[CPUX86_HAS_POPCNT,CPUX86_HAS_LZCNT],
  247. { cpu_core_avx } cpu_x86_64_v1_flags+[CPUX86_HAS_POPCNT],
  248. { cpu_jaguar } cpu_x86_64_v2_flags+[CPUX86_HAS_BMI1,CPUX86_HAS_LZCNT,CPUX86_HAS_MOVBE],
  249. { cpu_piledriver} cpu_x86_64_v2_flags+[CPUX86_HAS_BMI1,CPUX86_HAS_LZCNT,CPUX86_HAS_MOVBE],
  250. { cpu_excavator } cpu_x86_64_v3_flags,
  251. { cpu_core_avx2 } cpu_x86_64_v3_flags,
  252. { cpu_x86_64_v3 } cpu_x86_64_v3_flags,
  253. { cpu_zen } cpu_x86_64_v3_flags,
  254. { cpu_zen2 } cpu_x86_64_v3_flags,
  255. { cpu_x86_64_v4 } cpu_x86_64_v4_flags,
  256. { cpu_icelake } cpu_x86_64_v3_flags,
  257. { cpu_icelake_client } cpu_x86_64_v3_flags,
  258. { cpu_icelake_server } cpu_x86_64_v3_flags,
  259. { cpu_zen3 } cpu_x86_64_v3_flags,
  260. { cpu_zen4 } cpu_x86_64_v4_flags
  261. );
  262. fpu_x86_64_v1_flags = [];
  263. fpu_x86_64_v2_flags = fpu_x86_64_v1_flags+[FPUX86_HAS_SSE3,FPUX86_HAS_SSE4_1,FPUX86_HAS_SSE4_2,FPUX86_HAS_SSSE3];
  264. fpu_x86_64_v3_flags = fpu_x86_64_v2_flags+[FPUX86_HAS_AVXUNIT,FPUX86_HAS_FMA,FPUX86_HAS_F16C,FPUX86_HAS_AVX2];
  265. fpu_x86_64_v4_flags = fpu_x86_64_v3_flags;
  266. fpu_capabilities : array[tfputype] of set of tfpuflags = (
  267. { fpu_none } [],
  268. { fpu_sse64 } [],
  269. { fpu_x86_64_v1 } fpu_x86_64_v1_flags,
  270. { fpu_sse3 } fpu_x86_64_v1_flags+[FPUX86_HAS_SSE3],
  271. { fpu_ssse3 } fpu_x86_64_v1_flags+[FPUX86_HAS_SSE3,FPUX86_HAS_SSSE3],
  272. { fpu_sse41 } fpu_x86_64_v1_flags+[FPUX86_HAS_SSE3,FPUX86_HAS_SSE4_1],
  273. { fpu_sse42 } fpu_x86_64_v1_flags+[FPUX86_HAS_SSE3,FPUX86_HAS_SSE4_1,FPUX86_HAS_SSE4_2],
  274. { fpu_x86_64_v2 } fpu_x86_64_v2_flags,
  275. { fpu_avx } fpu_x86_64_v2_flags+[FPUX86_HAS_AVXUNIT],
  276. { fpu_fma } fpu_x86_64_v2_flags+[FPUX86_HAS_AVXUNIT,FPUX86_HAS_FMA],
  277. { fpu_avx2 } fpu_x86_64_v2_flags+[FPUX86_HAS_AVXUNIT,FPUX86_HAS_FMA,FPUX86_HAS_AVX2],
  278. { fpu_x86_64_v3 } fpu_x86_64_v3_flags,
  279. { fpu_avx512f } fpu_x86_64_v3_flags+[FPUX86_HAS_32MMREGS,FPUX86_HAS_AVX512F,FPUX86_HAS_AVX512VL,FPUX86_HAS_AVX512DQ],
  280. { fpu_x86_64_v4 } fpu_x86_64_v4_flags
  281. );
  282. cpu_optimization_hints : array[TCPUType] of set of TCPUOptimizeFlags = (
  283. { cpu_none } [],
  284. { cpu_Athlon64 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  285. { cpu_x86_64 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  286. { cpu_x86_64_v1 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  287. { cpu_core_i } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  288. { cpu_x86_64_v2 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  289. { cpu_bobcat } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  290. { cpu_core_avx } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG], { From Sandy Bridge up to Ice Lake, complex LEA instructions are much slower }
  291. { cpu_jaguar } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  292. { cpu_piledriver} [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  293. { cpu_excavator } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  294. { cpu_core_avx2 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_PDEP_PEXT],
  295. { cpu_x86_64_v3 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_PDEP_PEXT],
  296. { cpu_zen } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_BT_MEM_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  297. { cpu_zen2 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_BT_MEM_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  298. { cpu_x86_64_v4 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_BT_MEM_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_PDEP_PEXT,CPUX86_HINT_FAST_3COMP_ADDR],
  299. { cpu_icelake } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_BT_MEM_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_PDEP_PEXT,CPUX86_HINT_FAST_3COMP_ADDR],
  300. { cpu_icelake_client } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_BT_MEM_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_PDEP_PEXT,CPUX86_HINT_FAST_3COMP_ADDR],
  301. { cpu_icelake_server } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_BT_MEM_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_PDEP_PEXT,CPUX86_HINT_FAST_3COMP_ADDR],
  302. { cpu_zen3 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_BT_MEM_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_PDEP_PEXT,CPUX86_HINT_FAST_3COMP_ADDR],
  303. { cpu_zen4 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_BT_MEM_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_PDEP_PEXT,CPUX86_HINT_FAST_3COMP_ADDR]
  304. );
  305. Implementation
  306. end.