Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

556 lines
15 KiB

  1. #!/usr/local/bin/perl5 -w
  2. ##
  3. ## Copyright (c) 2000, Intel Corporation
  4. ## All rights reserved.
  5. ##
  6. ## WARRANTY DISCLAIMER
  7. ##
  8. ## THESE MATERIALS ARE PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  9. ## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  10. ## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  11. ## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
  12. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  13. ## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  14. ## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  15. ## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  16. ## OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
  17. ## NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THESE
  18. ## MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19. ##
  20. ## Intel Corporation is the author of the Materials, and requests that all
  21. ## problem reports or change requests be submitted to it directly at
  22. ## http://developer.intel.com/opensource.
  23. ##
  24. $GenDir = shift(@ARGV);
  25. $EmdbDir = shift(@ARGV);
  26. ################################################
  27. # CONSTANTS AND VARIABLES
  28. ################################################
  29. ### Second role instruction flag
  30. # ASSUMPTIONS:
  31. #1) Each instructions has at most one operand with a second role.
  32. #2) The _2ROLE flags are made up of EXACTLY one decimal digit.
  33. $_2ROLE_NONE = 0;
  34. $_2ROLE_DST = 1;
  35. $_2ROLE_SRC = 2;
  36. ### NOTE
  37. # All arrays of completers below must be sorted by their length in descending order
  38. ### Compare types comleters which can appear in mnemonics
  39. @cmp_types = ("or\.andcm", "and", "unc", "or");
  40. ### Compare relations comleters which can appear in mnemonics
  41. @cmp_rels = ("unord", "ord", "neq", "nlt", "nle", "geu", "ltu", "eq", "ne", "lt", "ge", "gt", "le");
  42. ### All those instructions that have floating point precision specification
  43. @fp_precis_insts = ("EM_FNMA", "EM_SETF", "EM_GETF", "EM_FMA", "EM_FMS");
  44. ### Branch types comleters which can appear in mnemonics
  45. @branch_types = ("CLOOP", "CEXIT", "WEXIT", "COND", "CALL", "CTOP", "WTOP", "RET", "IA");
  46. ### Memory access hints comleters which can appear in mnemonics
  47. @mem_access_hints = ("nt1", "nt2", "nta");
  48. ### Prefix of branch_hints enumerators
  49. $branch_hint_prefix = "EM_branch_hint";
  50. ### Prefix of memory_access_hints enumerators
  51. $mem_access_hint_prefix = "EM_memory_access_hint";
  52. ### Hints file (EM_hints.h) header
  53. $hints_header = "#ifndef EM_HINTS_H\n#define EM_HINTS_H\n\n";
  54. ### Add branch hints enumeration's header
  55. $branch_hints_header = ("typedef enum ".$branch_hint_prefix."_e\n{\n");
  56. $branch_hints_header .= (" ".$branch_hint_prefix."_none");
  57. ### Branch hints enumeration's tail
  58. $branch_hints_tail = (",\n ".$branch_hint_prefix."_last\n} ".$branch_hint_prefix."_t;\n\n");
  59. ### Memory access hints enumeration's header
  60. $mem_access_hints_header = ("typedef enum ".$mem_access_hint_prefix."_e\n{\n");
  61. $mem_access_hints_header .= (" ".$mem_access_hint_prefix."_none");
  62. ### Memory access hints enumeration's tail
  63. $mem_access_hints_tail = (",\n ".$mem_access_hint_prefix."_last\n} ".$mem_access_hint_prefix."_t;\n\n");
  64. ### Hints file (EM_hints.h) tail
  65. $hints_tail = ("\n#endif /* EM_HINTS_H */\n");
  66. ### BR_hints: Associative array that holds existing branch hints
  67. $BR_hints{"none"} = "exist"; #enumerated by 0 - printed the first in EM_hints.h
  68. $BR_hints{"last"} = "exist"; #printed the last in EM_hints.h
  69. ### MEM_ACCESS_hints: Associative array that holds existing memory access hints
  70. $MEM_ACCESS_hints{"none"} = "exist"; #enumerated by 0 - printed the first in EM_hints.h
  71. $MEM_ACCESS_hints{"last"} = "exist"; #printed the last in EM_hints.h
  72. ### Initialize branch hints enumeration string
  73. $branch_hints_enum = "";
  74. ### Initilize memory access hints enumeration string
  75. $mem_access_hints_enum = "";
  76. ### memory_size: Associative array that maps "letter" into mem_size
  77. %memory_size = ("s", 4, "d", 8, "e", 10, "q", 16);
  78. ################################################
  79. # open input and output files
  80. ################################################
  81. ### Input file: all_emdb.c
  82. open(EMDB_ALL, "$GenDir/all_emdb.tab") || die "Can't open all_emdb.tab\n";
  83. ### Output file: decoder.txt
  84. open(EMDB5, ">$GenDir/decoder.txt") || die "Can't open decoder.txt\n";
  85. ### Output file: EM_hints.h
  86. open (HINTS_ENUM, ">$GenDir/EM_hints.h") || die "Can't open EM_hints.h\n";
  87. ### Column names in decoder.txt
  88. @dec_col_names = ("inst_id", "mem_size", "dec_flags",
  89. "false_pred_flag", "modifiers", "br_hint_flag", "br_flag", "control_transfer_flag");
  90. ### Type names in decoder.txt
  91. @dec_type_names = ("Inst_id_t", "Mem_size_t", "int",
  92. "int", "EM_Decoder_modifiers_t", "int", "int", "int");
  93. ### Prefix names in decoder.txt
  94. @dec_prefix_names = ("---", "---", "---", "---",
  95. "EM_cmp_type;EM_CMP_REL;EM_branch_type;EM_branch_hint;EM_FP_PRECISION;EM_FP_STATUS;EM_memory_access_hint",
  96. "---", "---", "---");
  97. ###open emdb.txt to extract its version
  98. open(EMDB, "$EmdbDir/emdb.txt") || die "Can't open emdb.txt\n";
  99. ### Skip comments in emdb.txt file
  100. while (<EMDB>)
  101. {
  102. last if /^###/;
  103. }
  104. close (EMDB);
  105. ### Set emdb.txt version
  106. die "ERROR !!! unexpected EMDB.txt header format\n" if ($_ !~ /\$Revision/);
  107. $EMDB_version = $_;
  108. ### Select decoder.txt to be the current output file
  109. select(EMDB5);
  110. ### Print headers in decoder.txt
  111. print $EMDB_version;
  112. ### Set format for output to decoder.txt
  113. format EMDB5 =
  114. @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  115. $id, $mem_size, $dec_flags, $false_pred_flag, $modifiers, $br_hint_flag, $br_flag, $control_transfer_flag
  116. .
  117. ### Print column names
  118. ($id, $mem_size, $dec_flags, $false_pred_flag, $modifiers, $br_hint_flag, $br_flag, $control_transfer_flag) = @dec_col_names;
  119. $id = "&" . $id;
  120. write;
  121. ### Print type names
  122. ($id, $mem_size, $dec_flags, $false_pred_flag, $modifiers, $br_hint_flag, $br_flag, $control_transfer_flag) = @dec_type_names;
  123. $id = "?" . $id;
  124. write;
  125. ### Print prefix names
  126. ($id, $mem_size, $dec_flags, $false_pred_flag, $modifiers, $br_hint_flag, $br_flag, $control_transfer_flag) = @dec_prefix_names;
  127. $id = "@" . $id;
  128. write;
  129. ### While loop over lines of all_emdb.tab
  130. ### Each line is read into $_
  131. while (<EMDB_ALL>)
  132. {
  133. if (/^EM_/)
  134. {
  135. ### Initialization
  136. $mem_size = 0;
  137. $dec_flags = $_2ROLE_NONE;
  138. ### Extract instruction id and mnemonic from current input line
  139. ($id, $mnemonic) = split(/,/, $_);
  140. ### Set mem_size
  141. if ($mnemonic =~ /ld(\d+)/)
  142. {
  143. $mem_size = $1;
  144. }
  145. elsif ($mnemonic =~ /ldf(\d+)/)
  146. {
  147. $mem_size = $1;
  148. }
  149. elsif ($mnemonic =~ /ldfp(\d+)/)
  150. {
  151. $mem_size = $1;
  152. }
  153. elsif ($mnemonic =~ /ldfpd/)
  154. {
  155. $mem_size = 16;
  156. }
  157. elsif ($mnemonic =~ /ldfps/)
  158. {
  159. $mem_size = 8;
  160. }
  161. elsif ($mnemonic =~ /ldf([a-z])/)
  162. {
  163. die "ERROR !!! unexpected mnemonic: \"ldf$1\"\n" if (!$memory_size{$1});
  164. $mem_size = $memory_size{$1};
  165. }
  166. elsif ($mnemonic =~ /ldf\./)
  167. {
  168. $mem_size = 16;
  169. }
  170. elsif ($mnemonic =~ /lfetch/)
  171. {
  172. $mem_size = 32;
  173. }
  174. elsif ($mnemonic =~ /st(\d+)/)
  175. {
  176. $mem_size = $1;
  177. }
  178. elsif ($mnemonic =~ /stf(\d+)/)
  179. {
  180. $mem_size = $1;
  181. }
  182. elsif ($mnemonic =~ /stf([a-z])/)
  183. {
  184. die "ERROR !!! unexpected mnemonic: \"stf$1\"\n" if (!$memory_size{$1});
  185. $mem_size = $memory_size{$1};
  186. }
  187. elsif ($mnemonic =~ /stf\./)
  188. {
  189. $mem_size = 16;
  190. }
  191. elsif ($mnemonic =~ /fetchadd(\d+)/)
  192. {
  193. $mem_size = $1;
  194. }
  195. elsif ($mnemonic =~ /xchg(\d+)/)
  196. {
  197. $mem_size = $1;
  198. }
  199. ### Set second role flag
  200. ### loads or lfetchs with "_R2" or "IMM" in inst_id
  201. #!!! to be updated when this conventions change !!!
  202. if ((($id =~ /EM_LD/) && (($id =~ /_R2/)||($id =~ /IMM/)||($id =~ /_(\d+)/))) ||
  203. (($id =~ /EM_LFETCH/) && (($id =~ /_R2/)||($id =~ /IMM/))))
  204. {
  205. $dec_flags = $_2ROLE_DST;
  206. }
  207. elsif (($id =~ /EM_ST/) && ($id =~ /IMM/)) ### stores with "IMM" in inst_id
  208. {
  209. $dec_flags = $_2ROLE_SRC;
  210. }
  211. ### Set false predicate exec flag
  212. &Set_false_pred_flag();
  213. ### Set branch flags
  214. &Set_branch_flags();
  215. ### Set control transfer flag
  216. &Set_control_transfer_flag();
  217. ### Set modifiers: cmp_type, cmp_rel, branch_type, branch_hint, fp_precision, fp_status, mem_access_hint
  218. &Set_modifiers();
  219. ### Join all the modifiers separated by ';'
  220. $modifiers = join(';', $cmp_type, $cmp_rel, $branch_type, $branch_hint,
  221. $fp_precision, $fp_status, $mem_access_hint);
  222. write;
  223. }
  224. }
  225. ### Print headers in EM_hints.h
  226. print HINTS_ENUM $hints_header;
  227. &Print_branch_hints();
  228. ### Print memory access hints enumeration in EM_hints.h
  229. &Print_mem_access_hints();
  230. ### Print tail in EM_hints.h
  231. print HINTS_ENUM $hints_tail;
  232. ### Close open files
  233. close(HINTS_ENUM);
  234. close(EMDB_ALL);
  235. close(EMDB5);
  236. ##################################
  237. # PROCEDURES
  238. ##################################
  239. sub Set_modifiers
  240. {
  241. $cmp_type = "none";
  242. $cmp_rel = "NONE";
  243. ### Set cmp_rel modifier
  244. for ($i=0; $i <= $#cmp_rels; $i++)
  245. {
  246. if ($mnemonic =~ /\.$cmp_rels[$i]/)
  247. {
  248. $cmp_rel = "\U$cmp_rels[$i]";
  249. last;
  250. }
  251. }
  252. ### Set cmp_type modifier
  253. for ($i=0; $i <= $#cmp_types; $i++)
  254. {
  255. if ($mnemonic =~ /\.$cmp_types[$i]/)
  256. {
  257. $cmp_type = $cmp_types[$i];
  258. $cmp_type =~ s/\./_/g;
  259. last;
  260. }
  261. }
  262. ### Set fp_precision modifier
  263. $fp_precision = "NONE";
  264. for ($i=0; $i <= $#fp_precis_insts; $i++)
  265. {
  266. if ($id =~ /$fp_precis_insts[$i]_/)
  267. {
  268. if ($id =~ /_S_/)
  269. {
  270. $fp_precision = "SINGLE";
  271. }
  272. elsif ($id =~ /_D_/)
  273. {
  274. $fp_precision = "DOUBLE";
  275. }
  276. else
  277. {
  278. $fp_precision = "DYNAMIC";
  279. }
  280. last;
  281. }
  282. }
  283. ### Set fp_status modifier
  284. $fp_status = "NONE";
  285. if ($mnemonic =~ /\.s0/)
  286. {
  287. $fp_status = "S0";
  288. }
  289. elsif ($mnemonic =~ /\.s1/)
  290. {
  291. $fp_status = "S1";
  292. }
  293. elsif ($mnemonic =~ /\.s2/)
  294. {
  295. $fp_status = "S2";
  296. }
  297. elsif ($mnemonic =~ /\.s3/)
  298. {
  299. $fp_status = "S3";
  300. }
  301. ### Set branch_type modifier
  302. $branch_type = "none";
  303. $branch_hint = "none";
  304. if ($id =~ /EM_BR_/ || $id =~ /EM_BRL_/) ### Pattern: mnemonic - "br.type.hints"
  305. {
  306. for ($i=0; $i <= $#branch_types; $i++)
  307. {
  308. if ($id =~ /_$branch_types[$i]/)
  309. {
  310. if ($id =~ /TARGET25/ || $id =~ /TARGET64/)
  311. {
  312. $branch_type = "direct";
  313. }
  314. else
  315. {
  316. $branch_type = "indirect";
  317. }
  318. $branch_type .= "_\L$branch_types[$i]";
  319. last;
  320. }
  321. }
  322. }
  323. ### Set branch_hint modifier
  324. if ($mnemonic =~ /brp\./) ### Pattern: mnemonic - "brp.[ret.]hints"
  325. {
  326. $branch_hint = $mnemonic;
  327. $branch_hint =~ s/brp\.//;
  328. $branch_hint =~ s/\./_/g;
  329. }
  330. elsif ($id =~ /^EM_MOV_/ && $id =~ /TAG13/) ### Pattern: inst_id - EM_MOV_[RET_]HINTS__B1_R2_TAG13
  331. ### mnemonic - "mov.[ret.]hints"
  332. {
  333. $branch_hint = $mnemonic;
  334. $branch_hint =~ s/mov\.//;
  335. $branch_hint =~ s/\./_/g;
  336. }
  337. elsif ($id =~ /EM_BR_/ || $id =~ /EM_BRL_/) ### Pattern: mnemonic - "br.type.hints"
  338. {
  339. for ($i=0; $i <= $#branch_types; $i++)
  340. {
  341. if ($id =~ /_$branch_types[$i]/)
  342. {
  343. $branch_hint = $mnemonic;
  344. $br_type_low = "\L$branch_types[$i]";
  345. $branch_hint =~ s/br\.$br_type_low\.//;
  346. $branch_hint =~ s/brl\.$br_type_low\.//;
  347. $branch_hint =~ s/\./_/g;
  348. last;
  349. }
  350. }
  351. }
  352. ### Append the branch hint enumerator (if first appearance)
  353. ### to the enums string
  354. if (! $BR_hints{$branch_hint})
  355. {
  356. $BR_hints{$branch_hint} = "exist";
  357. $hint = join('_', $branch_hint_prefix, $branch_hint);
  358. $branch_hints_enum .= ",\n $hint";
  359. }
  360. ### Set mem_access_hint modifier
  361. $mem_access_hint = "none";
  362. for ($i=0; $i <= $#mem_access_hints; $i++)
  363. {
  364. if ($mnemonic =~ /\.$mem_access_hints[$i]/)
  365. {
  366. $mem_access_hint = $mem_access_hints[$i];
  367. last;
  368. }
  369. }
  370. ### Append the memory access hint enumerator (if first appearance)
  371. ### to the enums string
  372. if (! $MEM_ACCESS_hints{$mem_access_hint})
  373. {
  374. $MEM_ACCESS_hints{$mem_access_hint} = "exist";
  375. $hint = join('_', $mem_access_hint_prefix, $mem_access_hint);
  376. $mem_access_hints_enum .= ",\n $hint";
  377. }
  378. }
  379. ### False qualifying predicate exec flag
  380. sub Set_false_pred_flag
  381. {
  382. if (($mnemonic =~ /\.unc/) ||
  383. ($mnemonic =~ /frcpa/) ||
  384. ($mnemonic =~ /frsqrta/) ||
  385. ($mnemonic =~ /fprcpa/) ||
  386. ($mnemonic =~ /fprsqrta/) ||
  387. (($mnemonic =~ /br\./) && (($mnemonic =~ /\.cloop/) || ($mnemonic =~ /\.cexit/) ||
  388. ($mnemonic =~ /\.ctop/) || ($mnemonic =~ /\.wtop/) ||
  389. ($mnemonic =~ /\.wexit/)))
  390. )
  391. {
  392. $false_pred_flag = 1;
  393. }
  394. else
  395. {
  396. $false_pred_flag = 0;
  397. }
  398. }
  399. ### Branch flag
  400. sub Set_branch_flags
  401. {
  402. if ($id =~ /EM_BRP_/)
  403. {
  404. $br_hint_flag = 1;
  405. $br_flag = 0;
  406. }
  407. elsif ($id =~ /EM_BR_/ || $id =~ /EM_BRL_/)
  408. {
  409. $br_hint_flag = 0;
  410. $br_flag = 1;
  411. }
  412. else
  413. {
  414. $br_hint_flag = 0;
  415. $br_flag = 0;
  416. }
  417. }
  418. ### Print branch hints enumeration in EM_hints.h
  419. sub Print_branch_hints
  420. {
  421. ### Print branch hints enumeration's header
  422. print HINTS_ENUM $branch_hints_header;
  423. ### Print branch hints enumeration string
  424. print HINTS_ENUM $branch_hints_enum;
  425. ### Print branch hints enumeration's tail
  426. print HINTS_ENUM $branch_hints_tail;
  427. }
  428. ### Print memory access hints enumeration in EM_hints.h
  429. sub Print_mem_access_hints
  430. {
  431. ### Print memory access hints enumeration's header
  432. print HINTS_ENUM $mem_access_hints_header;
  433. ### Print memory access hints enumeration string
  434. print HINTS_ENUM $mem_access_hints_enum;
  435. ### Print memory access hints enumeration's tail
  436. print HINTS_ENUM $mem_access_hints_tail;
  437. }
  438. ### Control transfer flag
  439. sub Set_control_transfer_flag
  440. {
  441. if ($id =~ /EM_BR_/ || $id =~ /EM_BRL_/ || $id =~ /EM_RFI/ || $id =~ /EM_BREAK/ ||
  442. ($id =~ /TARGET25/ && $id !~ /EM_BRP_/))
  443. {
  444. $control_transfer_flag = 1;
  445. }
  446. else
  447. {
  448. $control_transfer_flag = 0;
  449. }
  450. }