]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/x86_64/multiarch/scripts/gen-reg-macros.py
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / x86_64 / multiarch / scripts / gen-reg-macros.py
CommitLineData
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
20Inputs: None
21Output: Prints header fill to stdout
22
23API:
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
38import sys
39import os
40from datetime import datetime
41
42registers = [["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
51mask_insns = [
52 "kmov",
53 "kortest",
54 "kor",
55 "ktest",
56 "kand",
57 "kxor",
58 "knot",
59 "kxnor",
60]
61mask_insns_ext = ["b", "w", "d", "q"]
62
63cr = """
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
82print("/* This file was generated by: {}.".format(os.path.basename(
83 sys.argv[0])))
84print(cr.format(datetime.today().year))
85
86print("#ifndef _REG_MACROS_H")
87print("#define _REG_MACROS_H\t1")
88print("")
89for reg in registers:
90 for i in range(0, 4):
91 print("#define {}_{}\t{}".format(reg[0], 8 << i, reg[3 - i]))
92
93print("")
94for 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]))
98for i in range(0, 3):
99 print("#define kunpack_{}\tkunpack{}{}".format(8 << i, mask_insns_ext[i],
100 mask_insns_ext[i + 1]))
101mask_insns.append("kunpack")
102
103print("")
104print(
105 "/* Common API for accessing proper width GPR is V{upcase_GPR_name}. */")
106for reg in registers:
107 print("#define V{}\tVGPR({})".format(reg[0].upper(), reg[0]))
108
109print("")
110
111print(
112 "/* Common API for accessing proper width mask insn is {upcase_mask_insn}. */"
113)
114for mask_insn in mask_insns:
115 print("#define {} \tVKINSN({})".format(mask_insn.upper(), mask_insn))
116print("")
117
118print("#ifdef USE_WIDE_CHAR")
119print("# define REG_WIDTH 32")
120print("#else")
121print("# define REG_WIDTH VEC_SIZE")
122print("#endif")
123print("")
124print("#define VPASTER(x, y)\tx##_##y")
125print("#define VEVALUATOR(x, y)\tVPASTER(x, y)")
126print("")
127print("#define VGPR_SZ(reg_name, reg_size)\tVEVALUATOR(reg_name, reg_size)")
128print("#define VKINSN_SZ(insn, reg_size)\tVEVALUATOR(insn, reg_size)")
129print("")
130print("#define VGPR(reg_name)\tVGPR_SZ(reg_name, REG_WIDTH)")
131print("#define VKINSN(mask_insn)\tVKINSN_SZ(mask_insn, REG_WIDTH)")
132
133print("\n#endif")