]>
Commit | Line | Data |
---|---|---|
52ab7604 | 1 | #!/usr/bin/python3 |
6d7e8eda | 2 | # Copyright (C) 2022-2023 Free Software Foundation, Inc. |
52ab7604 NG |
3 | # This file is part of the GNU C Library. |
4 | # | |
5 | # The GNU C Library is free software; you can redistribute it and/or | |
6 | # modify it under the terms of the GNU Lesser General Public | |
7 | # License as published by the Free Software Foundation; either | |
8 | # version 2.1 of the License, or (at your option) any later version. | |
9 | # | |
10 | # The GNU C Library is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | # Lesser General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU Lesser General Public | |
16 | # License along with the GNU C Library; if not, see | |
17 | # <https://www.gnu.org/licenses/>. | |
18 | """Generate macros for getting GPR name of a certain size | |
19 | ||
20 | Inputs: None | |
21 | Output: Prints header fill to stdout | |
22 | ||
23 | API: | |
24 | V{upcase_GPR_name} | |
25 | - Get register name REG_WIDTH component of `upcase_GPR_name` | |
26 | {upcase_mask_insn_without_postfix} | |
27 | - Get proper REG_WIDTH mask insn for `upcase_mask_insn_without_postfix` | |
28 | VGPR(reg_name) | |
29 | - Get register name REG_WIDTH component of `reg_name` | |
30 | VKINSN(mask_insn) | |
31 | - Get proper REG_WIDTH mask insn for `mask_insn` | |
32 | VGPR_SZ(reg_name, reg_size) | |
33 | - Get register name `reg_size` component of `reg_name` | |
34 | VKINSN_SZ(mask_insn, insn_size) | |
35 | - Get proper `insn_size` mask insn for `mask_insn` | |
36 | """ | |
37 | ||
38 | import sys | |
39 | import os | |
40 | from datetime import datetime | |
41 | ||
42 | registers = [["rax", "eax", "ax", "al"], ["rbx", "ebx", "bx", "bl"], | |
43 | ["rcx", "ecx", "cx", "cl"], ["rdx", "edx", "dx", "dl"], | |
44 | ["rbp", "ebp", "bp", "bpl"], ["rsp", "esp", "sp", "spl"], | |
45 | ["rsi", "esi", "si", "sil"], ["rdi", "edi", "di", "dil"], | |
46 | ["r8", "r8d", "r8w", "r8b"], ["r9", "r9d", "r9w", "r9b"], | |
47 | ["r10", "r10d", "r10w", "r10b"], ["r11", "r11d", "r11w", "r11b"], | |
48 | ["r12", "r12d", "r12w", "r12b"], ["r13", "r13d", "r13w", "r13b"], | |
49 | ["r14", "r14d", "r14w", "r14b"], ["r15", "r15d", "r15w", "r15b"]] | |
50 | ||
51 | mask_insns = [ | |
52 | "kmov", | |
53 | "kortest", | |
54 | "kor", | |
55 | "ktest", | |
56 | "kand", | |
57 | "kxor", | |
58 | "knot", | |
59 | "kxnor", | |
60 | ] | |
61 | mask_insns_ext = ["b", "w", "d", "q"] | |
62 | ||
63 | cr = """ | |
64 | Copyright (C) {} Free Software Foundation, Inc. | |
65 | This file is part of the GNU C Library. | |
66 | ||
67 | The GNU C Library is free software; you can redistribute it and/or | |
68 | modify it under the terms of the GNU Lesser General Public | |
69 | License as published by the Free Software Foundation; either | |
70 | version 2.1 of the License, or (at your option) any later version. | |
71 | ||
72 | The GNU C Library is distributed in the hope that it will be useful, | |
73 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
74 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
75 | Lesser General Public License for more details. | |
76 | ||
77 | You should have received a copy of the GNU Lesser General Public | |
78 | License along with the GNU C Library; if not, see | |
79 | <https://www.gnu.org/licenses/>. */ | |
80 | """ | |
81 | ||
82 | print("/* This file was generated by: {}.".format(os.path.basename( | |
83 | sys.argv[0]))) | |
84 | print(cr.format(datetime.today().year)) | |
85 | ||
86 | print("#ifndef _REG_MACROS_H") | |
87 | print("#define _REG_MACROS_H\t1") | |
88 | print("") | |
89 | for reg in registers: | |
90 | for i in range(0, 4): | |
91 | print("#define {}_{}\t{}".format(reg[0], 8 << i, reg[3 - i])) | |
92 | ||
93 | print("") | |
94 | for mask_insn in mask_insns: | |
95 | for i in range(0, 4): | |
96 | print("#define {}_{}\t{}{}".format(mask_insn, 8 << i, mask_insn, | |
97 | mask_insns_ext[i])) | |
98 | for i in range(0, 3): | |
99 | print("#define kunpack_{}\tkunpack{}{}".format(8 << i, mask_insns_ext[i], | |
100 | mask_insns_ext[i + 1])) | |
101 | mask_insns.append("kunpack") | |
102 | ||
103 | print("") | |
104 | print( | |
105 | "/* Common API for accessing proper width GPR is V{upcase_GPR_name}. */") | |
106 | for reg in registers: | |
107 | print("#define V{}\tVGPR({})".format(reg[0].upper(), reg[0])) | |
108 | ||
109 | print("") | |
110 | ||
111 | print( | |
112 | "/* Common API for accessing proper width mask insn is {upcase_mask_insn}. */" | |
113 | ) | |
114 | for mask_insn in mask_insns: | |
115 | print("#define {} \tVKINSN({})".format(mask_insn.upper(), mask_insn)) | |
116 | print("") | |
117 | ||
118 | print("#ifdef USE_WIDE_CHAR") | |
119 | print("# define REG_WIDTH 32") | |
120 | print("#else") | |
121 | print("# define REG_WIDTH VEC_SIZE") | |
122 | print("#endif") | |
123 | print("") | |
124 | print("#define VPASTER(x, y)\tx##_##y") | |
125 | print("#define VEVALUATOR(x, y)\tVPASTER(x, y)") | |
126 | print("") | |
127 | print("#define VGPR_SZ(reg_name, reg_size)\tVEVALUATOR(reg_name, reg_size)") | |
128 | print("#define VKINSN_SZ(insn, reg_size)\tVEVALUATOR(insn, reg_size)") | |
129 | print("") | |
130 | print("#define VGPR(reg_name)\tVGPR_SZ(reg_name, REG_WIDTH)") | |
131 | print("#define VKINSN(mask_insn)\tVKINSN_SZ(mask_insn, REG_WIDTH)") | |
132 | ||
133 | print("\n#endif") |