2
0

cpuinfo.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. );
  57. tfputype =
  58. (fpu_none,
  59. // fpu_soft, { generic }
  60. fpu_sse64,
  61. fpu_x86_64_v1,
  62. fpu_sse3,
  63. fpu_ssse3,
  64. fpu_sse41,
  65. fpu_sse42,
  66. fpu_x86_64_v2,
  67. fpu_avx,
  68. fpu_fma,
  69. fpu_avx2,
  70. fpu_x86_64_v3,
  71. fpu_avx512f,
  72. fpu_x86_64_v4
  73. );
  74. tcontrollertype =
  75. (ct_none
  76. );
  77. tcontrollerdatatype = record
  78. controllertypestr, controllerunitstr: string[20];
  79. cputype: tcputype; fputype: tfputype;
  80. flashbase, flashsize, srambase, sramsize, eeprombase, eepromsize, bootbase, bootsize: dword;
  81. end;
  82. Const
  83. { Is there support for dealing with multiple microcontrollers available }
  84. { for this platform? }
  85. ControllerSupport = false;
  86. { Size of native extended type }
  87. extended_size = 10;
  88. { target cpu string (used by compiler options) }
  89. target_cpu_string = 'x86_64';
  90. { We know that there are fields after sramsize
  91. but we don't care about this warning }
  92. {$PUSH}
  93. {$WARN 3177 OFF}
  94. embedded_controllers : array [tcontrollertype] of tcontrollerdatatype =
  95. (
  96. (controllertypestr:''; controllerunitstr:''; cputype:cpu_none; fputype:fpu_none; flashbase:0; flashsize:0; srambase:0; sramsize:0));
  97. {$POP}
  98. { calling conventions supported by the code generator }
  99. supported_calling_conventions : tproccalloptions = [
  100. pocall_internproc,
  101. { pocall_compilerproc,
  102. pocall_inline,}
  103. pocall_register,
  104. pocall_safecall,
  105. pocall_stdcall,
  106. pocall_cdecl,
  107. pocall_cppdecl,
  108. pocall_mwpascal,
  109. pocall_sysv_abi_default,
  110. pocall_sysv_abi_cdecl,
  111. pocall_ms_abi_default,
  112. pocall_ms_abi_cdecl,
  113. pocall_vectorcall
  114. ];
  115. cputypestr : array[tcputype] of string[16] = ('',
  116. 'ATHLON64',
  117. 'X86-64',
  118. 'X86-64-V1',
  119. 'COREI',
  120. 'X86-64-V2',
  121. 'BOBCAT',
  122. 'COREAVX',
  123. 'JAGUAR',
  124. 'PILEDRIVER',
  125. 'EXCAVATOR',
  126. 'COREAVX2',
  127. 'X86-64-V3',
  128. 'ZEN',
  129. 'ZEN2',
  130. 'X86-64-V4',
  131. 'ICELAKE',
  132. 'ICELAKE-CLIENT',
  133. 'ICELAKE-SERVER',
  134. 'ZEN3'
  135. );
  136. fputypestr : array[tfputype] of string[9] = (
  137. 'NONE',
  138. // 'SOFT',
  139. 'SSE64',
  140. 'X86-64-V1',
  141. 'SSE3',
  142. 'SSSE3',
  143. 'SSE41',
  144. 'SSE42',
  145. 'X86-64-V1',
  146. 'AVX',
  147. 'FMA',
  148. 'AVX2',
  149. 'X86-64-V3',
  150. 'AVX512F',
  151. 'X86-64-V4'
  152. );
  153. fputypestrllvm : array[tfputype] of string[9] = ('',
  154. // 'SOFT',
  155. '',
  156. 'x86-64-v1',
  157. 'sse3',
  158. 'ssse3',
  159. 'sse4.1',
  160. 'sse4.2',
  161. 'x86-64-v2',
  162. 'avx',
  163. 'fma',
  164. 'avx2',
  165. 'x86-64-v3',
  166. 'avx512f',
  167. 'x86-64-v4'
  168. );
  169. sse_singlescalar = [fpu_sse64..fpu_avx512f];
  170. sse_doublescalar = [fpu_sse64..fpu_avx512f];
  171. fpu_avx_instructionsets = [fpu_avx,fpu_fma,fpu_avx2,fpu_avx512f];
  172. { Supported optimizations, only used for information }
  173. supported_optimizerswitches = genericlevel1optimizerswitches+
  174. genericlevel2optimizerswitches+
  175. genericlevel3optimizerswitches-
  176. { no need to write info about those }
  177. [cs_opt_level1,cs_opt_level2,cs_opt_level3]+
  178. [{$ifndef llvm}cs_opt_regvar,{$endif}cs_opt_loopunroll,cs_opt_stackframe,cs_userbp,
  179. cs_opt_tailrecursion,cs_opt_nodecse,cs_opt_reorder_fields,cs_opt_fastmath];
  180. level1optimizerswitches = genericlevel1optimizerswitches;
  181. level2optimizerswitches = genericlevel2optimizerswitches + level1optimizerswitches +
  182. [{$ifndef llvm}cs_opt_regvar,{$endif}cs_opt_stackframe,cs_opt_tailrecursion,cs_opt_nodecse,cs_opt_consts];
  183. level3optimizerswitches = genericlevel3optimizerswitches + level2optimizerswitches;
  184. level4optimizerswitches = genericlevel4optimizerswitches + level3optimizerswitches + [cs_userbp];
  185. type
  186. tcpuflags =
  187. (CPUX86_HAS_BTX, { Bit-test instructions (BT, BTC, BTR and BTS) are available }
  188. CPUX86_HAS_CMOV, { CMOVcc instructions are available }
  189. CPUX86_HAS_SSEUNIT, { SSE instructions are available }
  190. CPUX86_HAS_SSE2, { SSE2 instructions are available }
  191. CPUX86_HAS_BMI1, { BMI1 instructions are available }
  192. CPUX86_HAS_BMI2, { BMI2 instructions are available }
  193. CPUX86_HAS_CMPXCHG16B, { CMPXCHG16B is available }
  194. CPUX86_HAS_LAHF_SAHF, { LAHF/SAHF is available }
  195. CPUX86_HAS_POPCNT, { POPCNT is available }
  196. CPUX86_HAS_LZCNT, { LZCNT is available }
  197. CPUX86_HAS_MOVBE, { MOVBE is available }
  198. CPUX86_HAS_BSWAP, { BSWAP is available }
  199. CPUX86_HAS_OSXSAVE { XGETBV is available }
  200. );
  201. tfpuflags =
  202. (FPUX86_HAS_SSE3,
  203. FPUX86_HAS_SSE4_1,
  204. FPUX86_HAS_SSE4_2,
  205. FPUX86_HAS_SSSE3,
  206. FPUX86_HAS_AVXUNIT,
  207. FPUX86_HAS_FMA,
  208. FPUX86_HAS_FMA4,
  209. FPUX86_HAS_F16C,
  210. FPUX86_HAS_AVX2,
  211. FPUX86_HAS_32MMREGS,
  212. FPUX86_HAS_AVX512F,
  213. FPUX86_HAS_AVX512BW,
  214. FPUX86_HAS_AVX512CD,
  215. FPUX86_HAS_AVX512VL,
  216. FPUX86_HAS_AVX512DQ
  217. );
  218. { Instruction optimisation hints }
  219. TCPUOptimizeFlags =
  220. (CPUX86_HINT_FAST_BT_REG_IMM, { BT instructions with register source and immediate indices are at least as fast as logical instructions }
  221. CPUX86_HINT_FAST_BT_REG_REG, { BT instructions with register source and register indices are at least as fast as equivalent logical instructions }
  222. CPUX86_HINT_FAST_BTX_REG_IMM, { BTC/R/S instructions with register source and immediate indices are at least as fast as logical instructions }
  223. 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 }
  224. CPUX86_HINT_FAST_BT_MEM_IMM, { BT instructions with memory sources and inmediate indices are at least as fast as logical instructions }
  225. 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 }
  226. CPUX86_HINT_FAST_BTX_MEM_IMM, { BTC/R/S instructions with memory sources and immediate indices are at least as fast as logical instructions }
  227. 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 }
  228. CPUX86_HINT_FAST_XCHG, { XCHG %reg,%reg executes in 2 cycles or fewer }
  229. CPUX86_HINT_FAST_PDEP_PEXT, { The BMI2 instructions PDEP and PEXT execute in a single cycle }
  230. 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) }
  231. );
  232. const
  233. cpu_x86_64_v1_flags = [CPUX86_HAS_BSWAP,CPUX86_HAS_BTX,CPUX86_HAS_CMOV,CPUX86_HAS_SSEUNIT,CPUX86_HAS_SSE2];
  234. cpu_x86_64_v2_flags = cpu_x86_64_v1_flags+[CPUX86_HAS_CMPXCHG16B,CPUX86_HAS_LAHF_SAHF,CPUX86_HAS_POPCNT];
  235. 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 }
  236. cpu_x86_64_v4_flags = cpu_x86_64_v3_flags; { everything is in the fpu flags here }
  237. cpu_capabilities : array[tcputype] of set of tcpuflags = (
  238. { cpu_none } [],
  239. { Athlon64 } cpu_x86_64_v1_flags,
  240. { cpu_x86_64 } cpu_x86_64_v1_flags,
  241. { cpu_x86_64_v1 } cpu_x86_64_v1_flags,
  242. { cpu_core_i } cpu_x86_64_v1_flags+[CPUX86_HAS_POPCNT],
  243. { cpu_x86_64_v2 } cpu_x86_64_v2_flags,
  244. { cpu_bobcat } [CPUX86_HAS_BSWAP,CPUX86_HAS_BTX,CPUX86_HAS_CMOV,CPUX86_HAS_SSEUNIT,CPUX86_HAS_SSE2,CPUX86_HAS_POPCNT,CPUX86_HAS_LZCNT],
  245. { cpu_core_avx } [CPUX86_HAS_BSWAP,CPUX86_HAS_BTX,CPUX86_HAS_CMOV,CPUX86_HAS_SSEUNIT,CPUX86_HAS_SSE2,CPUX86_HAS_POPCNT],
  246. { cpu_jaguar } cpu_x86_64_v2_flags,
  247. { cpu_piledriver} [CPUX86_HAS_BSWAP,CPUX86_HAS_BTX,CPUX86_HAS_CMOV,CPUX86_HAS_SSEUNIT,CPUX86_HAS_SSE2,CPUX86_HAS_POPCNT,CPUX86_HAS_BMI1,CPUX86_HAS_LZCNT,CPUX86_HAS_MOVBE],
  248. { cpu_excavator } cpu_x86_64_v3_flags,
  249. { cpu_core_avx2 } cpu_x86_64_v3_flags,
  250. { cpu_x86_64_v3 } cpu_x86_64_v3_flags,
  251. { cpu_zen } cpu_x86_64_v3_flags,
  252. { cpu_zen2 } cpu_x86_64_v3_flags,
  253. { cpu_x86_64_v4 } cpu_x86_64_v4_flags,
  254. { cpu_icelake } cpu_x86_64_v3_flags,
  255. { cpu_icelake_client } cpu_x86_64_v3_flags,
  256. { cpu_icelake_server } cpu_x86_64_v3_flags,
  257. { cpu_zen3 } cpu_x86_64_v3_flags
  258. );
  259. fpu_x86_64_v1_flags = [];
  260. fpu_x86_64_v2_flags = fpu_x86_64_v1_flags+[FPUX86_HAS_SSE3,FPUX86_HAS_SSE4_1,FPUX86_HAS_SSE4_2,FPUX86_HAS_SSSE3];
  261. fpu_x86_64_v3_flags = fpu_x86_64_v2_flags+[FPUX86_HAS_AVXUNIT,FPUX86_HAS_FMA,FPUX86_HAS_F16C,FPUX86_HAS_AVX2];
  262. fpu_x86_64_v4_flags = fpu_x86_64_v3_flags;
  263. fpu_capabilities : array[tfputype] of set of tfpuflags = (
  264. { fpu_none } [],
  265. { fpu_sse64 } [],
  266. { fpu_x86_64_v1 } fpu_x86_64_v1_flags,
  267. { fpu_sse3 } fpu_x86_64_v1_flags+[FPUX86_HAS_SSE3],
  268. { fpu_ssse3 } fpu_x86_64_v1_flags+[FPUX86_HAS_SSE3,FPUX86_HAS_SSSE3],
  269. { fpu_sse41 } fpu_x86_64_v1_flags+[FPUX86_HAS_SSE3,FPUX86_HAS_SSE4_1],
  270. { fpu_sse42 } fpu_x86_64_v1_flags+[FPUX86_HAS_SSE3,FPUX86_HAS_SSE4_1,FPUX86_HAS_SSE4_2],
  271. { fpu_x86_64_v2 } fpu_x86_64_v2_flags,
  272. { fpu_avx } fpu_x86_64_v2_flags+[FPUX86_HAS_AVXUNIT],
  273. { fpu_fma } fpu_x86_64_v2_flags+[FPUX86_HAS_AVXUNIT,FPUX86_HAS_FMA],
  274. { fpu_avx2 } fpu_x86_64_v2_flags+[FPUX86_HAS_AVXUNIT,FPUX86_HAS_FMA,FPUX86_HAS_AVX2],
  275. { fpu_x86_64_v3 } fpu_x86_64_v3_flags,
  276. { fpu_avx512f } fpu_x86_64_v3_flags+[FPUX86_HAS_32MMREGS,FPUX86_HAS_AVX512F,FPUX86_HAS_AVX512VL,FPUX86_HAS_AVX512DQ],
  277. { fpu_x86_64_v4 } fpu_x86_64_v4_flags
  278. );
  279. cpu_optimization_hints : array[TCPUType] of set of TCPUOptimizeFlags = (
  280. { cpu_none } [],
  281. { cpu_Athlon64 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  282. { cpu_x86_64 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  283. { 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],
  284. { cpu_core_i } [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_v2 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  286. { cpu_bobcat } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  287. { 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 }
  288. { cpu_jaguar } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  289. { cpu_piledriver} [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  290. { cpu_excavator } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_3COMP_ADDR],
  291. { cpu_core_avx2 } [CPUX86_HINT_FAST_BT_REG_IMM,CPUX86_HINT_FAST_BTX_REG_IMM,CPUX86_HINT_FAST_XCHG,CPUX86_HINT_FAST_PDEP_PEXT],
  292. { 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],
  293. { 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],
  294. { 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],
  295. { 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],
  296. { 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],
  297. { 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],
  298. { 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],
  299. { 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]
  300. );
  301. Implementation
  302. end.