about summary refs log tree commit diff
path: root/sysdeps/x86_64/multiarch/scripts
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2022-10-14 22:00:25 -0500
committerNoah Goldstein <goldstein.w.n@gmail.com>2022-10-14 21:21:58 -0700
commit52ab7604db35e0421bc3d2468a3af52b2c513a7b (patch)
tree2763b19062339644b3a747ad81ca38d253bd8ce7 /sysdeps/x86_64/multiarch/scripts
parent2c42257314536b94cc8d52edede86e94e98c1436 (diff)
downloadglibc-52ab7604db35e0421bc3d2468a3af52b2c513a7b.tar.gz
glibc-52ab7604db35e0421bc3d2468a3af52b2c513a7b.tar.xz
glibc-52ab7604db35e0421bc3d2468a3af52b2c513a7b.zip
x86: Update VEC macros to complete API for evex/evex512 impls
1) Copy so that backport will be easier.
2) Make section only define if there is not a previous definition
3) Add `VEC_lo` definition for proper reg-width but in the
   ymm/zmm0-15 range.
4) Add macros for accessing GPRs based on VEC_SIZE
        This is to make it easier to do think like:
        ```
            vpcmpb %VEC(0), %VEC(1), %k0
            kmov{d|q} %k0, %{eax|rax}
            test %{eax|rax}
        ```
        It adds macro s.t any GPR can get the proper width with:
            `V{upcase_GPR_name}`

        and any mask insn can get the proper width with:
            `{upcase_mask_insn_without_postfix}`

This commit does not change libc.so

Tested build on x86-64
Diffstat (limited to 'sysdeps/x86_64/multiarch/scripts')
-rw-r--r--sysdeps/x86_64/multiarch/scripts/gen-reg-macros.py133
1 files changed, 133 insertions, 0 deletions
diff --git a/sysdeps/x86_64/multiarch/scripts/gen-reg-macros.py b/sysdeps/x86_64/multiarch/scripts/gen-reg-macros.py
new file mode 100644
index 0000000000..9fb6903212
--- /dev/null
+++ b/sysdeps/x86_64/multiarch/scripts/gen-reg-macros.py
@@ -0,0 +1,133 @@
+#!/usr/bin/python3
+# Copyright (C) 2022 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")