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