08c3a6
commit 70be93d1c58916d289a5e6e7c7d9b989707a9e41
08c3a6
Author: Noah Goldstein <goldstein.w.n@gmail.com>
08c3a6
Date:   Mon Jun 6 21:11:27 2022 -0700
08c3a6
08c3a6
    x86: Create header for VEC classes in x86 strings library
08c3a6
    
08c3a6
    This patch does not touch any existing code and is only meant to be a
08c3a6
    tool for future patches so that simple source files can more easily be
08c3a6
    maintained to target multiple VEC classes.
08c3a6
    
08c3a6
    There is no difference in the objdump of libc.so before and after this
08c3a6
    patch.
08c3a6
    Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
08c3a6
    
08c3a6
    (cherry picked from commit 8a780a6b910023e71f3173f37f0793834c047554)
08c3a6
08c3a6
diff --git a/sysdeps/x86_64/multiarch/avx-rtm-vecs.h b/sysdeps/x86_64/multiarch/avx-rtm-vecs.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..3f531dd47fceefe9
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/x86_64/multiarch/avx-rtm-vecs.h
08c3a6
@@ -0,0 +1,34 @@
08c3a6
+/* Common config for AVX-RTM VECs
08c3a6
+   All versions must be listed in ifunc-impl-list.c.
08c3a6
+   Copyright (C) 2022 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _AVX_RTM_VECS_H
08c3a6
+#define _AVX_RTM_VECS_H			1
08c3a6
+
08c3a6
+#define ZERO_UPPER_VEC_REGISTERS_RETURN	\
08c3a6
+	ZERO_UPPER_VEC_REGISTERS_RETURN_XTEST
08c3a6
+
08c3a6
+#define VZEROUPPER_RETURN		jmp L(return_vzeroupper)
08c3a6
+
08c3a6
+#define USE_WITH_RTM			1
08c3a6
+#include "avx-vecs.h"
08c3a6
+
08c3a6
+#undef SECTION
08c3a6
+#define SECTION(p)				p##.avx.rtm
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/x86_64/multiarch/avx-vecs.h b/sysdeps/x86_64/multiarch/avx-vecs.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..89680f5db827c332
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/x86_64/multiarch/avx-vecs.h
08c3a6
@@ -0,0 +1,47 @@
08c3a6
+/* Common config for AVX VECs
08c3a6
+   All versions must be listed in ifunc-impl-list.c.
08c3a6
+   Copyright (C) 2022 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _AVX_VECS_H
08c3a6
+#define _AVX_VECS_H			1
08c3a6
+
08c3a6
+#ifdef VEC_SIZE
08c3a6
+# error "Multiple VEC configs included!"
08c3a6
+#endif
08c3a6
+
08c3a6
+#define VEC_SIZE			32
08c3a6
+#include "vec-macros.h"
08c3a6
+
08c3a6
+#define USE_WITH_AVX		1
08c3a6
+#define SECTION(p)			p##.avx
08c3a6
+
08c3a6
+/* 4-byte mov instructions with AVX2.  */
08c3a6
+#define MOV_SIZE			4
08c3a6
+/* 1 (ret) + 3 (vzeroupper).  */
08c3a6
+#define RET_SIZE			4
08c3a6
+#define VZEROUPPER			vzeroupper
08c3a6
+
08c3a6
+#define VMOVU				vmovdqu
08c3a6
+#define VMOVA				vmovdqa
08c3a6
+#define VMOVNT				vmovntdq
08c3a6
+
08c3a6
+/* Often need to access xmm portion.  */
08c3a6
+#define VEC_xmm				VEC_any_xmm
08c3a6
+#define VEC					VEC_any_ymm
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/x86_64/multiarch/evex-vecs-common.h b/sysdeps/x86_64/multiarch/evex-vecs-common.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..99806ebcd7bde53d
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/x86_64/multiarch/evex-vecs-common.h
08c3a6
@@ -0,0 +1,39 @@
08c3a6
+/* Common config for EVEX256 and EVEX512 VECs
08c3a6
+   All versions must be listed in ifunc-impl-list.c.
08c3a6
+   Copyright (C) 2022 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _EVEX_VECS_COMMON_H
08c3a6
+#define _EVEX_VECS_COMMON_H			1
08c3a6
+
08c3a6
+#include "vec-macros.h"
08c3a6
+
08c3a6
+/* 6-byte mov instructions with EVEX.  */
08c3a6
+#define MOV_SIZE			6
08c3a6
+/* No vzeroupper needed.  */
08c3a6
+#define RET_SIZE			1
08c3a6
+#define VZEROUPPER
08c3a6
+
08c3a6
+#define VMOVU				vmovdqu64
08c3a6
+#define VMOVA				vmovdqa64
08c3a6
+#define VMOVNT				vmovntdq
08c3a6
+
08c3a6
+#define VEC_xmm				VEC_hi_xmm
08c3a6
+#define VEC_ymm				VEC_hi_ymm
08c3a6
+#define VEC_zmm				VEC_hi_zmm
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/x86_64/multiarch/evex256-vecs.h b/sysdeps/x86_64/multiarch/evex256-vecs.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..222ba46dc74cfcbd
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/x86_64/multiarch/evex256-vecs.h
08c3a6
@@ -0,0 +1,35 @@
08c3a6
+/* Common config for EVEX256 VECs
08c3a6
+   All versions must be listed in ifunc-impl-list.c.
08c3a6
+   Copyright (C) 2022 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _EVEX256_VECS_H
08c3a6
+#define _EVEX256_VECS_H			1
08c3a6
+
08c3a6
+#ifdef VEC_SIZE
08c3a6
+# error "Multiple VEC configs included!"
08c3a6
+#endif
08c3a6
+
08c3a6
+#define VEC_SIZE			32
08c3a6
+#include "evex-vecs-common.h"
08c3a6
+
08c3a6
+#define USE_WITH_EVEX256	1
08c3a6
+#define SECTION(p)			p##.evex
08c3a6
+
08c3a6
+#define VEC					VEC_ymm
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/x86_64/multiarch/evex512-vecs.h b/sysdeps/x86_64/multiarch/evex512-vecs.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..d1784d5368d8cebe
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/x86_64/multiarch/evex512-vecs.h
08c3a6
@@ -0,0 +1,35 @@
08c3a6
+/* Common config for EVEX512 VECs
08c3a6
+   All versions must be listed in ifunc-impl-list.c.
08c3a6
+   Copyright (C) 2022 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _EVEX512_VECS_H
08c3a6
+#define _EVEX512_VECS_H			1
08c3a6
+
08c3a6
+#ifdef VEC_SIZE
08c3a6
+# error "Multiple VEC configs included!"
08c3a6
+#endif
08c3a6
+
08c3a6
+#define VEC_SIZE			64
08c3a6
+#include "evex-vecs-common.h"
08c3a6
+
08c3a6
+#define USE_WITH_EVEX512	1
08c3a6
+#define SECTION(p)			p##.evex512
08c3a6
+
08c3a6
+#define VEC					VEC_zmm
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/x86_64/multiarch/sse2-vecs.h b/sysdeps/x86_64/multiarch/sse2-vecs.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..2b77a59d56ff2660
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/x86_64/multiarch/sse2-vecs.h
08c3a6
@@ -0,0 +1,47 @@
08c3a6
+/* Common config for SSE2 VECs
08c3a6
+   All versions must be listed in ifunc-impl-list.c.
08c3a6
+   Copyright (C) 2022 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _SSE2_VECS_H
08c3a6
+#define _SSE2_VECS_H			1
08c3a6
+
08c3a6
+#ifdef VEC_SIZE
08c3a6
+# error "Multiple VEC configs included!"
08c3a6
+#endif
08c3a6
+
08c3a6
+#define VEC_SIZE			16
08c3a6
+#include "vec-macros.h"
08c3a6
+
08c3a6
+#define USE_WITH_SSE2		1
08c3a6
+#define SECTION(p)			p
08c3a6
+
08c3a6
+/* 3-byte mov instructions with SSE2.  */
08c3a6
+#define MOV_SIZE			3
08c3a6
+/* No vzeroupper needed.  */
08c3a6
+#define RET_SIZE			1
08c3a6
+#define VZEROUPPER
08c3a6
+
08c3a6
+#define VMOVU				movups
08c3a6
+#define VMOVA				movaps
08c3a6
+#define VMOVNT				movntdq
08c3a6
+
08c3a6
+#define VEC_xmm				VEC_any_xmm
08c3a6
+#define VEC					VEC_any_xmm
08c3a6
+
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/x86_64/multiarch/vec-macros.h b/sysdeps/x86_64/multiarch/vec-macros.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..9f3ffecede9feb26
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/x86_64/multiarch/vec-macros.h
08c3a6
@@ -0,0 +1,90 @@
08c3a6
+/* Macro helpers for VEC_{type}({vec_num})
08c3a6
+   All versions must be listed in ifunc-impl-list.c.
08c3a6
+   Copyright (C) 2022 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _VEC_MACROS_H
08c3a6
+#define _VEC_MACROS_H			1
08c3a6
+
08c3a6
+#ifndef VEC_SIZE
08c3a6
+# error "Never include this file directly. Always include a vector config."
08c3a6
+#endif
08c3a6
+
08c3a6
+/* Defines so we can use SSE2 / AVX2 / EVEX / EVEX512 encoding with same
08c3a6
+   VEC(N) values.  */
08c3a6
+#define VEC_hi_xmm0				xmm16
08c3a6
+#define VEC_hi_xmm1				xmm17
08c3a6
+#define VEC_hi_xmm2				xmm18
08c3a6
+#define VEC_hi_xmm3				xmm19
08c3a6
+#define VEC_hi_xmm4				xmm20
08c3a6
+#define VEC_hi_xmm5				xmm21
08c3a6
+#define VEC_hi_xmm6				xmm22
08c3a6
+#define VEC_hi_xmm7				xmm23
08c3a6
+#define VEC_hi_xmm8				xmm24
08c3a6
+#define VEC_hi_xmm9				xmm25
08c3a6
+#define VEC_hi_xmm10			xmm26
08c3a6
+#define VEC_hi_xmm11			xmm27
08c3a6
+#define VEC_hi_xmm12			xmm28
08c3a6
+#define VEC_hi_xmm13			xmm29
08c3a6
+#define VEC_hi_xmm14			xmm30
08c3a6
+#define VEC_hi_xmm15			xmm31
08c3a6
+
08c3a6
+#define VEC_hi_ymm0				ymm16
08c3a6
+#define VEC_hi_ymm1				ymm17
08c3a6
+#define VEC_hi_ymm2				ymm18
08c3a6
+#define VEC_hi_ymm3				ymm19
08c3a6
+#define VEC_hi_ymm4				ymm20
08c3a6
+#define VEC_hi_ymm5				ymm21
08c3a6
+#define VEC_hi_ymm6				ymm22
08c3a6
+#define VEC_hi_ymm7				ymm23
08c3a6
+#define VEC_hi_ymm8				ymm24
08c3a6
+#define VEC_hi_ymm9				ymm25
08c3a6
+#define VEC_hi_ymm10			ymm26
08c3a6
+#define VEC_hi_ymm11			ymm27
08c3a6
+#define VEC_hi_ymm12			ymm28
08c3a6
+#define VEC_hi_ymm13			ymm29
08c3a6
+#define VEC_hi_ymm14			ymm30
08c3a6
+#define VEC_hi_ymm15			ymm31
08c3a6
+
08c3a6
+#define VEC_hi_zmm0				zmm16
08c3a6
+#define VEC_hi_zmm1				zmm17
08c3a6
+#define VEC_hi_zmm2				zmm18
08c3a6
+#define VEC_hi_zmm3				zmm19
08c3a6
+#define VEC_hi_zmm4				zmm20
08c3a6
+#define VEC_hi_zmm5				zmm21
08c3a6
+#define VEC_hi_zmm6				zmm22
08c3a6
+#define VEC_hi_zmm7				zmm23
08c3a6
+#define VEC_hi_zmm8				zmm24
08c3a6
+#define VEC_hi_zmm9				zmm25
08c3a6
+#define VEC_hi_zmm10			zmm26
08c3a6
+#define VEC_hi_zmm11			zmm27
08c3a6
+#define VEC_hi_zmm12			zmm28
08c3a6
+#define VEC_hi_zmm13			zmm29
08c3a6
+#define VEC_hi_zmm14			zmm30
08c3a6
+#define VEC_hi_zmm15			zmm31
08c3a6
+
08c3a6
+#define PRIMITIVE_VEC(vec, num)		vec##num
08c3a6
+
08c3a6
+#define VEC_any_xmm(i)			PRIMITIVE_VEC(xmm, i)
08c3a6
+#define VEC_any_ymm(i)			PRIMITIVE_VEC(ymm, i)
08c3a6
+#define VEC_any_zmm(i)			PRIMITIVE_VEC(zmm, i)
08c3a6
+
08c3a6
+#define VEC_hi_xmm(i)			PRIMITIVE_VEC(VEC_hi_xmm, i)
08c3a6
+#define VEC_hi_ymm(i)			PRIMITIVE_VEC(VEC_hi_ymm, i)
08c3a6
+#define VEC_hi_zmm(i)			PRIMITIVE_VEC(VEC_hi_zmm, i)
08c3a6
+
08c3a6
+#endif