x86cpu.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /* ANSI-C code produced by genperf */
  2. #include <util.h>
  3. #include <ctype.h>
  4. #include <libyasm.h>
  5. #include <libyasm/phash.h>
  6. #include "modules/arch/x86/x86arch.h"
  7. #define PROC_8086 0
  8. #define PROC_186 1
  9. #define PROC_286 2
  10. #define PROC_386 3
  11. #define PROC_486 4
  12. #define PROC_586 5
  13. #define PROC_686 6
  14. #define PROC_p2 7
  15. #define PROC_p3 8
  16. #define PROC_p4 9
  17. #define PROC_prescott 10
  18. #define PROC_conroe 11
  19. #define PROC_penryn 12
  20. #define PROC_nehalem 13
  21. #define PROC_westmere 14
  22. #define PROC_sandybridge 15
  23. #define PROC_ivybridge 16
  24. #define PROC_haswell 17
  25. #define PROC_broadwell 18
  26. #define PROC_skylake 19
  27. static void
  28. x86_cpu_intel(wordptr cpu, yasm_arch_x86 *arch_x86, unsigned int data)
  29. {
  30. BitVector_Empty(cpu);
  31. BitVector_Bit_On(cpu, CPU_Priv);
  32. if (data >= PROC_286)
  33. BitVector_Bit_On(cpu, CPU_Prot);
  34. if (data >= PROC_386)
  35. BitVector_Bit_On(cpu, CPU_SMM);
  36. if (data >= PROC_skylake) {
  37. BitVector_Bit_On(cpu, CPU_SHA);
  38. }
  39. if (data >= PROC_broadwell) {
  40. BitVector_Bit_On(cpu, CPU_RDSEED);
  41. BitVector_Bit_On(cpu, CPU_ADX);
  42. BitVector_Bit_On(cpu, CPU_PRFCHW);
  43. }
  44. if (data >= PROC_haswell) {
  45. BitVector_Bit_On(cpu, CPU_FMA);
  46. BitVector_Bit_On(cpu, CPU_AVX2);
  47. BitVector_Bit_On(cpu, CPU_BMI1);
  48. BitVector_Bit_On(cpu, CPU_BMI2);
  49. BitVector_Bit_On(cpu, CPU_INVPCID);
  50. BitVector_Bit_On(cpu, CPU_LZCNT);
  51. BitVector_Bit_On(cpu, CPU_TSX);
  52. BitVector_Bit_On(cpu, CPU_SMAP);
  53. }
  54. if (data >= PROC_ivybridge) {
  55. BitVector_Bit_On(cpu, CPU_F16C);
  56. BitVector_Bit_On(cpu, CPU_FSGSBASE);
  57. BitVector_Bit_On(cpu, CPU_RDRAND);
  58. }
  59. if (data >= PROC_sandybridge) {
  60. BitVector_Bit_On(cpu, CPU_AVX);
  61. BitVector_Bit_On(cpu, CPU_XSAVEOPT);
  62. BitVector_Bit_On(cpu, CPU_EPTVPID);
  63. BitVector_Bit_On(cpu, CPU_SMX);
  64. }
  65. if (data >= PROC_westmere) {
  66. BitVector_Bit_On(cpu, CPU_AES);
  67. BitVector_Bit_On(cpu, CPU_CLMUL);
  68. }
  69. if (data >= PROC_nehalem) {
  70. BitVector_Bit_On(cpu, CPU_SSE42);
  71. BitVector_Bit_On(cpu, CPU_XSAVE);
  72. }
  73. if (data >= PROC_penryn)
  74. BitVector_Bit_On(cpu, CPU_SSE41);
  75. if (data >= PROC_conroe)
  76. BitVector_Bit_On(cpu, CPU_SSSE3);
  77. if (data >= PROC_prescott)
  78. BitVector_Bit_On(cpu, CPU_SSE3);
  79. if (data >= PROC_p4)
  80. BitVector_Bit_On(cpu, CPU_SSE2);
  81. if (data >= PROC_p3)
  82. BitVector_Bit_On(cpu, CPU_SSE);
  83. if (data >= PROC_p2)
  84. BitVector_Bit_On(cpu, CPU_MMX);
  85. if (data >= PROC_486)
  86. BitVector_Bit_On(cpu, CPU_FPU);
  87. if (data >= PROC_prescott)
  88. BitVector_Bit_On(cpu, CPU_EM64T);
  89. if (data >= PROC_p4)
  90. BitVector_Bit_On(cpu, CPU_P4);
  91. if (data >= PROC_p3)
  92. BitVector_Bit_On(cpu, CPU_P3);
  93. if (data >= PROC_686)
  94. BitVector_Bit_On(cpu, CPU_686);
  95. if (data >= PROC_586)
  96. BitVector_Bit_On(cpu, CPU_586);
  97. if (data >= PROC_486)
  98. BitVector_Bit_On(cpu, CPU_486);
  99. if (data >= PROC_386)
  100. BitVector_Bit_On(cpu, CPU_386);
  101. if (data >= PROC_286)
  102. BitVector_Bit_On(cpu, CPU_286);
  103. if (data >= PROC_186)
  104. BitVector_Bit_On(cpu, CPU_186);
  105. BitVector_Bit_On(cpu, CPU_086);
  106. /* Use Intel long NOPs if 686 or better */
  107. if (data >= PROC_686)
  108. arch_x86->nop = X86_NOP_INTEL;
  109. else
  110. arch_x86->nop = X86_NOP_BASIC;
  111. }
  112. static void
  113. x86_cpu_ia64(wordptr cpu, yasm_arch_x86 *arch_x86, unsigned int data)
  114. {
  115. BitVector_Empty(cpu);
  116. BitVector_Bit_On(cpu, CPU_Priv);
  117. BitVector_Bit_On(cpu, CPU_Prot);
  118. BitVector_Bit_On(cpu, CPU_SMM);
  119. BitVector_Bit_On(cpu, CPU_SSE2);
  120. BitVector_Bit_On(cpu, CPU_SSE);
  121. BitVector_Bit_On(cpu, CPU_MMX);
  122. BitVector_Bit_On(cpu, CPU_FPU);
  123. BitVector_Bit_On(cpu, CPU_IA64);
  124. BitVector_Bit_On(cpu, CPU_P4);
  125. BitVector_Bit_On(cpu, CPU_P3);
  126. BitVector_Bit_On(cpu, CPU_686);
  127. BitVector_Bit_On(cpu, CPU_586);
  128. BitVector_Bit_On(cpu, CPU_486);
  129. BitVector_Bit_On(cpu, CPU_386);
  130. BitVector_Bit_On(cpu, CPU_286);
  131. BitVector_Bit_On(cpu, CPU_186);
  132. BitVector_Bit_On(cpu, CPU_086);
  133. }
  134. #define PROC_bulldozer 11
  135. #define PROC_k10 10
  136. #define PROC_venice 9
  137. #define PROC_hammer 8
  138. #define PROC_k7 7
  139. #define PROC_k6 6
  140. static void
  141. x86_cpu_amd(wordptr cpu, yasm_arch_x86 *arch_x86, unsigned int data)
  142. {
  143. BitVector_Empty(cpu);
  144. BitVector_Bit_On(cpu, CPU_Priv);
  145. BitVector_Bit_On(cpu, CPU_Prot);
  146. BitVector_Bit_On(cpu, CPU_SMM);
  147. BitVector_Bit_On(cpu, CPU_3DNow);
  148. if (data >= PROC_bulldozer) {
  149. BitVector_Bit_On(cpu, CPU_XOP);
  150. BitVector_Bit_On(cpu, CPU_FMA4);
  151. }
  152. if (data >= PROC_k10)
  153. BitVector_Bit_On(cpu, CPU_SSE4a);
  154. if (data >= PROC_venice)
  155. BitVector_Bit_On(cpu, CPU_SSE3);
  156. if (data >= PROC_hammer)
  157. BitVector_Bit_On(cpu, CPU_SSE2);
  158. if (data >= PROC_k7)
  159. BitVector_Bit_On(cpu, CPU_SSE);
  160. if (data >= PROC_k6)
  161. BitVector_Bit_On(cpu, CPU_MMX);
  162. BitVector_Bit_On(cpu, CPU_FPU);
  163. if (data >= PROC_hammer)
  164. BitVector_Bit_On(cpu, CPU_Hammer);
  165. if (data >= PROC_k7)
  166. BitVector_Bit_On(cpu, CPU_Athlon);
  167. if (data >= PROC_k6)
  168. BitVector_Bit_On(cpu, CPU_K6);
  169. BitVector_Bit_On(cpu, CPU_686);
  170. BitVector_Bit_On(cpu, CPU_586);
  171. BitVector_Bit_On(cpu, CPU_486);
  172. BitVector_Bit_On(cpu, CPU_386);
  173. BitVector_Bit_On(cpu, CPU_286);
  174. BitVector_Bit_On(cpu, CPU_186);
  175. BitVector_Bit_On(cpu, CPU_086);
  176. /* Use AMD long NOPs if k6 or better */
  177. if (data >= PROC_k6)
  178. arch_x86->nop = X86_NOP_AMD;
  179. else
  180. arch_x86->nop = X86_NOP_BASIC;
  181. }
  182. static void
  183. x86_cpu_set(wordptr cpu, yasm_arch_x86 *arch_x86, unsigned int data)
  184. {
  185. BitVector_Bit_On(cpu, data);
  186. }
  187. static void
  188. x86_cpu_clear(wordptr cpu, yasm_arch_x86 *arch_x86, unsigned int data)
  189. {
  190. BitVector_Bit_Off(cpu, data);
  191. }
  192. static void
  193. x86_cpu_set_sse4(wordptr cpu, yasm_arch_x86 *arch_x86, unsigned int data)
  194. {
  195. BitVector_Bit_On(cpu, CPU_SSE41);
  196. BitVector_Bit_On(cpu, CPU_SSE42);
  197. }
  198. static void
  199. x86_cpu_clear_sse4(wordptr cpu, yasm_arch_x86 *arch_x86, unsigned int data)
  200. {
  201. BitVector_Bit_Off(cpu, CPU_SSE41);
  202. BitVector_Bit_Off(cpu, CPU_SSE42);
  203. }
  204. static void
  205. x86_nop(wordptr cpu, yasm_arch_x86 *arch_x86, unsigned int data)
  206. {
  207. arch_x86->nop = data;
  208. }
  209. struct cpu_parse_data {
  210. const char *name;
  211. void (*handler) (wordptr cpu, yasm_arch_x86 *arch_x86, unsigned int data);
  212. unsigned int data;
  213. };
  214. static const struct cpu_parse_data *
  215. cpu_find(const char *key, size_t len)
  216. {
  217. static const struct cpu_parse_data pd[179] = {
  218. {"noeptvpid", x86_cpu_clear, CPU_EPTVPID},
  219. {"amd", x86_cpu_set, CPU_AMD},
  220. {"sse41", x86_cpu_set, CPU_SSE41},
  221. {"pentium", x86_cpu_intel, PROC_586},
  222. {"intelnop", x86_nop, X86_NOP_INTEL},
  223. {"pclmulqdq", x86_cpu_set, CPU_CLMUL},
  224. {"sse42", x86_cpu_set, CPU_SSE42},
  225. {"nobmi2", x86_cpu_clear, CPU_BMI2},
  226. {"pentium3", x86_cpu_intel, PROC_p3},
  227. {"broadwell", x86_cpu_intel, PROC_broadwell},
  228. {"aes", x86_cpu_set, CPU_AES},
  229. {"eptvpid", x86_cpu_set, CPU_EPTVPID},
  230. {"f16c", x86_cpu_set, CPU_F16C},
  231. {"amdnop", x86_nop, X86_NOP_AMD},
  232. {"pentium-2", x86_cpu_intel, PROC_p2},
  233. {"nofpu", x86_cpu_clear, CPU_FPU},
  234. {"bmi2", x86_cpu_set, CPU_BMI2},
  235. {"katmai", x86_cpu_intel, PROC_p3},
  236. {"pentiumiii", x86_cpu_intel, PROC_p3},
  237. {"fpu", x86_cpu_set, CPU_FPU},
  238. {"noundoc", x86_cpu_clear, CPU_Undoc},
  239. {"no3dnow", x86_cpu_clear, CPU_3DNow},
  240. {"i486", x86_cpu_intel, PROC_486},
  241. {"noundocumented", x86_cpu_clear, CPU_Undoc},
  242. {"sse", x86_cpu_set, CPU_SSE},
  243. {"nossse3", x86_cpu_clear, CPU_SSSE3},
  244. {"noclmul", x86_cpu_clear, CPU_CLMUL},
  245. {"tsx", x86_cpu_set, CPU_TSX},
  246. {"nocyrix", x86_cpu_clear, CPU_Cyrix},
  247. {"nosse", x86_cpu_clear, CPU_SSE},
  248. {"nofma", x86_cpu_clear, CPU_FMA},
  249. {"phenom", x86_cpu_amd, PROC_k10},
  250. {"haswell", x86_cpu_intel, PROC_haswell},
  251. {"noprot", x86_cpu_clear, CPU_Prot},
  252. {"padlock", x86_cpu_set, CPU_PadLock},
  253. {"nopclmulqdq", x86_cpu_clear, CPU_CLMUL},
  254. {"nofma4", x86_cpu_clear, CPU_FMA4},
  255. {"nofsgsbase", x86_cpu_clear, CPU_FSGSBASE},
  256. {"prot", x86_cpu_set, CPU_Prot},
  257. {"opteron", x86_cpu_amd, PROC_hammer},
  258. {"nof16c", x86_cpu_clear, CPU_F16C},
  259. {"i386", x86_cpu_intel, PROC_386},
  260. {"ssse3", x86_cpu_set, CPU_SSSE3},
  261. {"protected", x86_cpu_set, CPU_Prot},
  262. {"bulldozer", x86_cpu_amd, PROC_bulldozer},
  263. {"lzcnt", x86_cpu_set, CPU_LZCNT},
  264. {"obs", x86_cpu_set, CPU_Obs},
  265. {"noprotected", x86_cpu_clear, CPU_Prot},
  266. {"athlon-64", x86_cpu_amd, PROC_hammer},
  267. {"undocumented", x86_cpu_set, CPU_Undoc},
  268. {"i686", x86_cpu_intel, PROC_686},
  269. {"k8", x86_cpu_amd, PROC_hammer},
  270. {"k10", x86_cpu_amd, PROC_k10},
  271. {"noavx2", x86_cpu_clear, CPU_AVX2},
  272. {"sandybridge", x86_cpu_intel, PROC_sandybridge},
  273. {"nommx", x86_cpu_clear, CPU_MMX},
  274. {"priv", x86_cpu_set, CPU_Priv},
  275. {"sse4.1", x86_cpu_set, CPU_SSE41},
  276. {"8086", x86_cpu_intel, PROC_8086},
  277. {"noprivileged", x86_cpu_clear, CPU_Priv},
  278. {"i586", x86_cpu_intel, PROC_586},
  279. {"ia-64", x86_cpu_ia64, 0},
  280. {"nosse2", x86_cpu_clear, CPU_SSE2},
  281. {"obsolete", x86_cpu_set, CPU_Obs},
  282. {"186", x86_cpu_intel, PROC_186},
  283. {"sse4a", x86_cpu_set, CPU_SSE4a},
  284. {"ia64", x86_cpu_ia64, 0},
  285. {"core2", x86_cpu_intel, PROC_conroe},
  286. {"noxsaveopt", x86_cpu_clear, CPU_XSAVEOPT},
  287. {"sse4.2", x86_cpu_set, CPU_SSE42},
  288. {"prescott", x86_cpu_intel, PROC_prescott},
  289. {"avx2", x86_cpu_set, CPU_AVX2},
  290. {"80186", x86_cpu_intel, PROC_186},
  291. {"nopriv", x86_cpu_clear, CPU_Priv},
  292. {"nosse4.1", x86_cpu_clear, CPU_SSE41},
  293. {"nordseed", x86_cpu_clear, CPU_RDSEED},
  294. {"pentium2", x86_cpu_intel, PROC_p2},
  295. {"conroe", x86_cpu_intel, PROC_conroe},
  296. {"nosse42", x86_cpu_clear, CPU_SSE42},
  297. {"pentium-ii", x86_cpu_intel, PROC_p2},
  298. {"svm", x86_cpu_set, CPU_SVM},
  299. {"386", x86_cpu_intel, PROC_386},
  300. {"em64t", x86_cpu_set, CPU_EM64T},
  301. {"p2", x86_cpu_intel, PROC_p2},
  302. {"athlon64", x86_cpu_amd, PROC_hammer},
  303. {"3dnow", x86_cpu_set, CPU_3DNow},
  304. {"nosse4", x86_cpu_clear_sse4, 0},
  305. {"nosmx", x86_cpu_clear, CPU_SMX},
  306. {"williamette", x86_cpu_intel, PROC_p4},
  307. {"family10h", x86_cpu_amd, PROC_k10},
  308. {"athlon", x86_cpu_amd, PROC_k7},
  309. {"586", x86_cpu_intel, PROC_586},
  310. {"686", x86_cpu_intel, PROC_686},
  311. {"smm", x86_cpu_set, CPU_SMM},
  312. {"xsave", x86_cpu_set, CPU_XSAVE},
  313. {"privileged", x86_cpu_set, CPU_Priv},
  314. {"p6", x86_cpu_intel, PROC_686},
  315. {"smap", x86_cpu_set, CPU_SMAP},
  316. {"avx", x86_cpu_set, CPU_AVX},
  317. {"pentium-4", x86_cpu_intel, PROC_p4},
  318. {"pentiumii", x86_cpu_intel, PROC_p2},
  319. {"sha", x86_cpu_set, CPU_SHA},
  320. {"fma4", x86_cpu_set, CPU_FMA4},
  321. {"pentium-iii", x86_cpu_intel, PROC_p3},
  322. {"skylake", x86_cpu_intel, PROC_skylake},
  323. {"nosse4.2", x86_cpu_clear, CPU_SSE42},
  324. {"pentium4", x86_cpu_intel, PROC_p4},
  325. {"noaes", x86_cpu_clear, CPU_AES},
  326. {"i186", x86_cpu_intel, PROC_186},
  327. {"rdrand", x86_cpu_set, CPU_RDRAND},
  328. {"80286", x86_cpu_intel, PROC_286},
  329. {"pentiumiv", x86_cpu_intel, PROC_p4},
  330. {"xop", x86_cpu_set, CPU_XOP},
  331. {"mmx", x86_cpu_set, CPU_MMX},
  332. {"486", x86_cpu_intel, PROC_486},
  333. {"clawhammer", x86_cpu_amd, PROC_hammer},
  334. {"rdseed", x86_cpu_set, CPU_RDSEED},
  335. {"i286", x86_cpu_intel, PROC_286},
  336. {"prfchw", x86_cpu_set, CPU_PRFCHW},
  337. {"nosse3", x86_cpu_clear, CPU_SSE3},
  338. {"sse4", x86_cpu_set_sse4, 0},
  339. {"pentium-iv", x86_cpu_intel, PROC_p4},
  340. {"p4", x86_cpu_intel, PROC_p4},
  341. {"nordrand", x86_cpu_clear, CPU_RDRAND},
  342. {"ppro", x86_cpu_intel, PROC_686},
  343. {"p5", x86_cpu_intel, PROC_586},
  344. {"notbm", x86_cpu_clear, CPU_TBM},
  345. {"cyrix", x86_cpu_set, CPU_Cyrix},
  346. {"80386", x86_cpu_intel, PROC_386},
  347. {"k6", x86_cpu_amd, PROC_k6},
  348. {"basicnop", x86_nop, X86_NOP_BASIC},
  349. {"nomovbe", x86_cpu_clear, CPU_MOVBE},
  350. {"noadx", x86_cpu_clear, CPU_ADX},
  351. {"nosmap", x86_cpu_clear, CPU_SMAP},
  352. {"nosmm", x86_cpu_clear, CPU_SMM},
  353. {"xsaveopt", x86_cpu_set, CPU_XSAVEOPT},
  354. {"pentium-3", x86_cpu_intel, PROC_p3},
  355. {"nosvm", x86_cpu_clear, CPU_SVM},
  356. {"nosha", x86_cpu_clear, CPU_SHA},
  357. {"invpcid", x86_cpu_set, CPU_INVPCID},
  358. {"nobmi1", x86_cpu_clear, CPU_BMI1},
  359. {"ivybridge", x86_cpu_intel, PROC_ivybridge},
  360. {"p3", x86_cpu_intel, PROC_p3},
  361. {"pentiumpro", x86_cpu_intel, PROC_686},
  362. {"penryn", x86_cpu_intel, PROC_penryn},
  363. {"80486", x86_cpu_intel, PROC_486},
  364. {"noxop", x86_cpu_clear, CPU_XOP},
  365. {"undoc", x86_cpu_set, CPU_Undoc},
  366. {"noobsolete", x86_cpu_clear, CPU_Obs},
  367. {"noavx", x86_cpu_clear, CPU_AVX},
  368. {"nolzcnt", x86_cpu_clear, CPU_LZCNT},
  369. {"noprfchw", x86_cpu_clear, CPU_PRFCHW},
  370. {"notsx", x86_cpu_clear, CPU_TSX},
  371. {"bmi1", x86_cpu_set, CPU_BMI1},
  372. {"itanium", x86_cpu_ia64, 0},
  373. {"venice", x86_cpu_amd, PROC_venice},
  374. {"noxsave", x86_cpu_clear, CPU_XSAVE},
  375. {"noamd", x86_cpu_clear, CPU_AMD},
  376. {"noobs", x86_cpu_clear, CPU_Obs},
  377. {"noem64t", x86_cpu_clear, CPU_EM64T},
  378. {"hammer", x86_cpu_amd, PROC_hammer},
  379. {"nehalem", x86_cpu_intel, PROC_nehalem},
  380. {"sse3", x86_cpu_set, CPU_SSE3},
  381. {"sse2", x86_cpu_set, CPU_SSE2},
  382. {"clmul", x86_cpu_set, CPU_CLMUL},
  383. {"smx", x86_cpu_set, CPU_SMX},
  384. {"nosse4a", x86_cpu_clear, CPU_SSE4a},
  385. {"tbm", x86_cpu_set, CPU_TBM},
  386. {"fma", x86_cpu_set, CPU_FMA},
  387. {"nopadlock", x86_cpu_clear, CPU_PadLock},
  388. {"nosse41", x86_cpu_clear, CPU_SSE41},
  389. {"adx", x86_cpu_set, CPU_ADX},
  390. {"westmere", x86_cpu_intel, PROC_westmere},
  391. {"k7", x86_cpu_amd, PROC_k7},
  392. {"noinvpcid", x86_cpu_clear, CPU_INVPCID},
  393. {"fsgsbase", x86_cpu_set, CPU_FSGSBASE},
  394. {"corei7", x86_cpu_intel, PROC_nehalem},
  395. {"movbe", x86_cpu_set, CPU_MOVBE},
  396. {"286", x86_cpu_intel, PROC_286}
  397. };
  398. static const unsigned char tab[] = {
  399. 183,125,113,40,125,0,0,0,183,146,116,85,0,113,113,183,
  400. 113,131,0,82,88,0,131,125,85,0,113,0,0,7,0,40,
  401. 22,7,0,0,125,220,87,183,184,7,0,0,0,113,11,0,
  402. 84,0,0,0,0,131,0,113,0,120,0,113,0,0,51,11,
  403. 55,190,0,0,183,61,120,131,85,135,0,0,0,0,0,82,
  404. 74,183,0,87,220,0,235,0,220,229,0,0,220,243,124,145,
  405. 0,220,131,0,221,0,0,0,237,0,135,125,124,168,0,69,
  406. 0,124,22,0,131,131,163,113,184,214,155,133,55,0,0,0,
  407. };
  408. const struct cpu_parse_data *ret;
  409. unsigned long rsl, val = phash_lookup(key, len, 0xdaa66d2bUL);
  410. rsl = ((val>>25)^tab[val&0x7f]);
  411. if (rsl >= 179) return NULL;
  412. ret = &pd[rsl];
  413. if (strcmp(key, ret->name) != 0) return NULL;
  414. return ret;
  415. }
  416. void
  417. yasm_x86__parse_cpu(yasm_arch_x86 *arch_x86, const char *cpuid,
  418. size_t cpuid_len)
  419. {
  420. /*@null@*/ const struct cpu_parse_data *pdata;
  421. wordptr new_cpu;
  422. size_t i;
  423. static char lcaseid[16];
  424. if (cpuid_len > 15)
  425. return;
  426. for (i=0; i<cpuid_len; i++)
  427. lcaseid[i] = tolower(cpuid[i]);
  428. lcaseid[cpuid_len] = '\0';
  429. pdata = cpu_find(lcaseid, cpuid_len);
  430. if (!pdata) {
  431. yasm_warn_set(YASM_WARN_GENERAL,
  432. N_("unrecognized CPU identifier `%s'"), cpuid);
  433. return;
  434. }
  435. new_cpu = BitVector_Clone(arch_x86->cpu_enables[arch_x86->active_cpu]);
  436. pdata->handler(new_cpu, arch_x86, pdata->data);
  437. /* try to find an existing match in the CPU table first */
  438. for (i=0; i<arch_x86->cpu_enables_size; i++) {
  439. if (BitVector_equal(arch_x86->cpu_enables[i], new_cpu)) {
  440. arch_x86->active_cpu = i;
  441. BitVector_Destroy(new_cpu);
  442. return;
  443. }
  444. }
  445. /* not found, need to add a new entry */
  446. arch_x86->active_cpu = arch_x86->cpu_enables_size++;
  447. arch_x86->cpu_enables =
  448. yasm_xrealloc(arch_x86->cpu_enables,
  449. arch_x86->cpu_enables_size*sizeof(wordptr));
  450. arch_x86->cpu_enables[arch_x86->active_cpu] = new_cpu;
  451. }