| 1 | /* Enumerate available IFUNC implementations of a function. x86-64 version. |
| 2 | Copyright (C) 2012-2016 Free Software Foundation, Inc. |
| 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 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #include <assert.h> |
| 20 | #include <string.h> |
| 21 | #include <wchar.h> |
| 22 | #include <ifunc-impl-list.h> |
| 23 | #include <sysdep.h> |
| 24 | #include "init-arch.h" |
| 25 | |
| 26 | /* Maximum number of IFUNC implementations. */ |
| 27 | #define MAX_IFUNC 5 |
| 28 | |
| 29 | /* Fill ARRAY of MAX elements with IFUNC implementations for function |
| 30 | NAME supported on target machine and return the number of valid |
| 31 | entries. */ |
| 32 | |
| 33 | size_t |
| 34 | __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, |
| 35 | size_t max) |
| 36 | { |
| 37 | assert (max >= MAX_IFUNC); |
| 38 | |
| 39 | size_t i = 0; |
| 40 | |
| 41 | /* Support sysdeps/x86_64/multiarch/memcmp.S. */ |
| 42 | IFUNC_IMPL (i, name, memcmp, |
| 43 | IFUNC_IMPL_ADD (array, i, memcmp, HAS_CPU_FEATURE (SSE4_1), |
| 44 | __memcmp_sse4_1) |
| 45 | IFUNC_IMPL_ADD (array, i, memcmp, HAS_CPU_FEATURE (SSSE3), |
| 46 | __memcmp_ssse3) |
| 47 | IFUNC_IMPL_ADD (array, i, memcmp, 1, __memcmp_sse2)) |
| 48 | |
| 49 | /* Support sysdeps/x86_64/multiarch/memmove_chk.c. */ |
| 50 | IFUNC_IMPL (i, name, __memmove_chk, |
| 51 | #ifdef HAVE_AVX512_ASM_SUPPORT |
| 52 | IFUNC_IMPL_ADD (array, i, __memmove_chk, |
| 53 | HAS_ARCH_FEATURE (AVX512F_Usable), |
| 54 | __memmove_chk_avx512_no_vzeroupper) |
| 55 | #endif |
| 56 | IFUNC_IMPL_ADD (array, i, __memmove_chk, |
| 57 | HAS_ARCH_FEATURE (AVX_Usable), |
| 58 | __memmove_chk_avx_unaligned) |
| 59 | IFUNC_IMPL_ADD (array, i, __memmove_chk, |
| 60 | HAS_CPU_FEATURE (SSSE3), |
| 61 | __memmove_chk_ssse3_back) |
| 62 | IFUNC_IMPL_ADD (array, i, __memmove_chk, |
| 63 | HAS_CPU_FEATURE (SSSE3), |
| 64 | __memmove_chk_ssse3) |
| 65 | IFUNC_IMPL_ADD (array, i, __memmove_chk, 1, |
| 66 | __memmove_chk_sse2)) |
| 67 | |
| 68 | /* Support sysdeps/x86_64/multiarch/memmove.S. */ |
| 69 | IFUNC_IMPL (i, name, memmove, |
| 70 | IFUNC_IMPL_ADD (array, i, memmove, |
| 71 | HAS_ARCH_FEATURE (AVX_Usable), |
| 72 | __memmove_avx_unaligned) |
| 73 | #ifdef HAVE_AVX512_ASM_SUPPORT |
| 74 | IFUNC_IMPL_ADD (array, i, memmove, |
| 75 | HAS_ARCH_FEATURE (AVX512F_Usable), |
| 76 | __memmove_avx512_no_vzeroupper) |
| 77 | #endif |
| 78 | IFUNC_IMPL_ADD (array, i, memmove, HAS_CPU_FEATURE (SSSE3), |
| 79 | __memmove_ssse3_back) |
| 80 | IFUNC_IMPL_ADD (array, i, memmove, HAS_CPU_FEATURE (SSSE3), |
| 81 | __memmove_ssse3) |
| 82 | IFUNC_IMPL_ADD (array, i, memmove, 1, __memmove_sse2)) |
| 83 | |
| 84 | /* Support sysdeps/x86_64/multiarch/memset_chk.S. */ |
| 85 | IFUNC_IMPL (i, name, __memset_chk, |
| 86 | IFUNC_IMPL_ADD (array, i, __memset_chk, 1, |
| 87 | __memset_chk_sse2) |
| 88 | IFUNC_IMPL_ADD (array, i, __memset_chk, |
| 89 | HAS_ARCH_FEATURE (AVX2_Usable), |
| 90 | __memset_chk_avx2) |
| 91 | #ifdef HAVE_AVX512_ASM_SUPPORT |
| 92 | IFUNC_IMPL_ADD (array, i, __memset_chk, |
| 93 | HAS_ARCH_FEATURE (AVX512F_Usable), |
| 94 | __memset_chk_avx512_no_vzeroupper) |
| 95 | #endif |
| 96 | ) |
| 97 | |
| 98 | /* Support sysdeps/x86_64/multiarch/memset.S. */ |
| 99 | IFUNC_IMPL (i, name, memset, |
| 100 | IFUNC_IMPL_ADD (array, i, memset, 1, __memset_sse2) |
| 101 | IFUNC_IMPL_ADD (array, i, memset, |
| 102 | HAS_ARCH_FEATURE (AVX2_Usable), |
| 103 | __memset_avx2) |
| 104 | #ifdef HAVE_AVX512_ASM_SUPPORT |
| 105 | IFUNC_IMPL_ADD (array, i, memset, |
| 106 | HAS_ARCH_FEATURE (AVX512F_Usable), |
| 107 | __memset_avx512_no_vzeroupper) |
| 108 | #endif |
| 109 | ) |
| 110 | |
| 111 | /* Support sysdeps/x86_64/multiarch/stpncpy.S. */ |
| 112 | IFUNC_IMPL (i, name, stpncpy, |
| 113 | IFUNC_IMPL_ADD (array, i, stpncpy, HAS_CPU_FEATURE (SSSE3), |
| 114 | __stpncpy_ssse3) |
| 115 | IFUNC_IMPL_ADD (array, i, stpncpy, 1, |
| 116 | __stpncpy_sse2_unaligned) |
| 117 | IFUNC_IMPL_ADD (array, i, stpncpy, 1, __stpncpy_sse2)) |
| 118 | |
| 119 | /* Support sysdeps/x86_64/multiarch/stpcpy.S. */ |
| 120 | IFUNC_IMPL (i, name, stpcpy, |
| 121 | IFUNC_IMPL_ADD (array, i, stpcpy, HAS_CPU_FEATURE (SSSE3), |
| 122 | __stpcpy_ssse3) |
| 123 | IFUNC_IMPL_ADD (array, i, stpcpy, 1, __stpcpy_sse2_unaligned) |
| 124 | IFUNC_IMPL_ADD (array, i, stpcpy, 1, __stpcpy_sse2)) |
| 125 | |
| 126 | /* Support sysdeps/x86_64/multiarch/strcasecmp_l.S. */ |
| 127 | IFUNC_IMPL (i, name, strcasecmp, |
| 128 | IFUNC_IMPL_ADD (array, i, strcasecmp, |
| 129 | HAS_ARCH_FEATURE (AVX_Usable), |
| 130 | __strcasecmp_avx) |
| 131 | IFUNC_IMPL_ADD (array, i, strcasecmp, |
| 132 | HAS_CPU_FEATURE (SSE4_2), |
| 133 | __strcasecmp_sse42) |
| 134 | IFUNC_IMPL_ADD (array, i, strcasecmp, |
| 135 | HAS_CPU_FEATURE (SSSE3), |
| 136 | __strcasecmp_ssse3) |
| 137 | IFUNC_IMPL_ADD (array, i, strcasecmp, 1, __strcasecmp_sse2)) |
| 138 | |
| 139 | /* Support sysdeps/x86_64/multiarch/strcasecmp_l.S. */ |
| 140 | IFUNC_IMPL (i, name, strcasecmp_l, |
| 141 | IFUNC_IMPL_ADD (array, i, strcasecmp_l, |
| 142 | HAS_ARCH_FEATURE (AVX_Usable), |
| 143 | __strcasecmp_l_avx) |
| 144 | IFUNC_IMPL_ADD (array, i, strcasecmp_l, |
| 145 | HAS_CPU_FEATURE (SSE4_2), |
| 146 | __strcasecmp_l_sse42) |
| 147 | IFUNC_IMPL_ADD (array, i, strcasecmp_l, |
| 148 | HAS_CPU_FEATURE (SSSE3), |
| 149 | __strcasecmp_l_ssse3) |
| 150 | IFUNC_IMPL_ADD (array, i, strcasecmp_l, 1, |
| 151 | __strcasecmp_l_sse2)) |
| 152 | |
| 153 | /* Support sysdeps/x86_64/multiarch/strcat.S. */ |
| 154 | IFUNC_IMPL (i, name, strcat, |
| 155 | IFUNC_IMPL_ADD (array, i, strcat, HAS_CPU_FEATURE (SSSE3), |
| 156 | __strcat_ssse3) |
| 157 | IFUNC_IMPL_ADD (array, i, strcat, 1, __strcat_sse2_unaligned) |
| 158 | IFUNC_IMPL_ADD (array, i, strcat, 1, __strcat_sse2)) |
| 159 | |
| 160 | /* Support sysdeps/x86_64/multiarch/strchr.S. */ |
| 161 | IFUNC_IMPL (i, name, strchr, |
| 162 | IFUNC_IMPL_ADD (array, i, strchr, 1, __strchr_sse2_no_bsf) |
| 163 | IFUNC_IMPL_ADD (array, i, strchr, 1, __strchr_sse2)) |
| 164 | |
| 165 | /* Support sysdeps/x86_64/multiarch/strcmp.S. */ |
| 166 | IFUNC_IMPL (i, name, strcmp, |
| 167 | IFUNC_IMPL_ADD (array, i, strcmp, HAS_CPU_FEATURE (SSE4_2), |
| 168 | __strcmp_sse42) |
| 169 | IFUNC_IMPL_ADD (array, i, strcmp, HAS_CPU_FEATURE (SSSE3), |
| 170 | __strcmp_ssse3) |
| 171 | IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_sse2_unaligned) |
| 172 | IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_sse2)) |
| 173 | |
| 174 | /* Support sysdeps/x86_64/multiarch/strcpy.S. */ |
| 175 | IFUNC_IMPL (i, name, strcpy, |
| 176 | IFUNC_IMPL_ADD (array, i, strcpy, HAS_CPU_FEATURE (SSSE3), |
| 177 | __strcpy_ssse3) |
| 178 | IFUNC_IMPL_ADD (array, i, strcpy, 1, __strcpy_sse2_unaligned) |
| 179 | IFUNC_IMPL_ADD (array, i, strcpy, 1, __strcpy_sse2)) |
| 180 | |
| 181 | /* Support sysdeps/x86_64/multiarch/strcspn.S. */ |
| 182 | IFUNC_IMPL (i, name, strcspn, |
| 183 | IFUNC_IMPL_ADD (array, i, strcspn, HAS_CPU_FEATURE (SSE4_2), |
| 184 | __strcspn_sse42) |
| 185 | IFUNC_IMPL_ADD (array, i, strcspn, 1, __strcspn_sse2)) |
| 186 | |
| 187 | /* Support sysdeps/x86_64/multiarch/strncase_l.S. */ |
| 188 | IFUNC_IMPL (i, name, strncasecmp, |
| 189 | IFUNC_IMPL_ADD (array, i, strncasecmp, |
| 190 | HAS_ARCH_FEATURE (AVX_Usable), |
| 191 | __strncasecmp_avx) |
| 192 | IFUNC_IMPL_ADD (array, i, strncasecmp, |
| 193 | HAS_CPU_FEATURE (SSE4_2), |
| 194 | __strncasecmp_sse42) |
| 195 | IFUNC_IMPL_ADD (array, i, strncasecmp, |
| 196 | HAS_CPU_FEATURE (SSSE3), |
| 197 | __strncasecmp_ssse3) |
| 198 | IFUNC_IMPL_ADD (array, i, strncasecmp, 1, |
| 199 | __strncasecmp_sse2)) |
| 200 | |
| 201 | /* Support sysdeps/x86_64/multiarch/strncase_l.S. */ |
| 202 | IFUNC_IMPL (i, name, strncasecmp_l, |
| 203 | IFUNC_IMPL_ADD (array, i, strncasecmp_l, |
| 204 | HAS_ARCH_FEATURE (AVX_Usable), |
| 205 | __strncasecmp_l_avx) |
| 206 | IFUNC_IMPL_ADD (array, i, strncasecmp_l, |
| 207 | HAS_CPU_FEATURE (SSE4_2), |
| 208 | __strncasecmp_l_sse42) |
| 209 | IFUNC_IMPL_ADD (array, i, strncasecmp_l, |
| 210 | HAS_CPU_FEATURE (SSSE3), |
| 211 | __strncasecmp_l_ssse3) |
| 212 | IFUNC_IMPL_ADD (array, i, strncasecmp_l, 1, |
| 213 | __strncasecmp_l_sse2)) |
| 214 | |
| 215 | /* Support sysdeps/x86_64/multiarch/strncat.S. */ |
| 216 | IFUNC_IMPL (i, name, strncat, |
| 217 | IFUNC_IMPL_ADD (array, i, strncat, HAS_CPU_FEATURE (SSSE3), |
| 218 | __strncat_ssse3) |
| 219 | IFUNC_IMPL_ADD (array, i, strncat, 1, |
| 220 | __strncat_sse2_unaligned) |
| 221 | IFUNC_IMPL_ADD (array, i, strncat, 1, __strncat_sse2)) |
| 222 | |
| 223 | /* Support sysdeps/x86_64/multiarch/strncpy.S. */ |
| 224 | IFUNC_IMPL (i, name, strncpy, |
| 225 | IFUNC_IMPL_ADD (array, i, strncpy, HAS_CPU_FEATURE (SSSE3), |
| 226 | __strncpy_ssse3) |
| 227 | IFUNC_IMPL_ADD (array, i, strncpy, 1, |
| 228 | __strncpy_sse2_unaligned) |
| 229 | IFUNC_IMPL_ADD (array, i, strncpy, 1, __strncpy_sse2)) |
| 230 | |
| 231 | /* Support sysdeps/x86_64/multiarch/strpbrk.S. */ |
| 232 | IFUNC_IMPL (i, name, strpbrk, |
| 233 | IFUNC_IMPL_ADD (array, i, strpbrk, HAS_CPU_FEATURE (SSE4_2), |
| 234 | __strpbrk_sse42) |
| 235 | IFUNC_IMPL_ADD (array, i, strpbrk, 1, __strpbrk_sse2)) |
| 236 | |
| 237 | |
| 238 | /* Support sysdeps/x86_64/multiarch/strspn.S. */ |
| 239 | IFUNC_IMPL (i, name, strspn, |
| 240 | IFUNC_IMPL_ADD (array, i, strspn, HAS_CPU_FEATURE (SSE4_2), |
| 241 | __strspn_sse42) |
| 242 | IFUNC_IMPL_ADD (array, i, strspn, 1, __strspn_sse2)) |
| 243 | |
| 244 | /* Support sysdeps/x86_64/multiarch/strstr.c. */ |
| 245 | IFUNC_IMPL (i, name, strstr, |
| 246 | IFUNC_IMPL_ADD (array, i, strstr, 1, __strstr_sse2_unaligned) |
| 247 | IFUNC_IMPL_ADD (array, i, strstr, 1, __strstr_sse2)) |
| 248 | |
| 249 | /* Support sysdeps/x86_64/multiarch/wcscpy.S. */ |
| 250 | IFUNC_IMPL (i, name, wcscpy, |
| 251 | IFUNC_IMPL_ADD (array, i, wcscpy, HAS_CPU_FEATURE (SSSE3), |
| 252 | __wcscpy_ssse3) |
| 253 | IFUNC_IMPL_ADD (array, i, wcscpy, 1, __wcscpy_sse2)) |
| 254 | |
| 255 | /* Support sysdeps/x86_64/multiarch/wmemcmp.S. */ |
| 256 | IFUNC_IMPL (i, name, wmemcmp, |
| 257 | IFUNC_IMPL_ADD (array, i, wmemcmp, HAS_CPU_FEATURE (SSE4_1), |
| 258 | __wmemcmp_sse4_1) |
| 259 | IFUNC_IMPL_ADD (array, i, wmemcmp, HAS_CPU_FEATURE (SSSE3), |
| 260 | __wmemcmp_ssse3) |
| 261 | IFUNC_IMPL_ADD (array, i, wmemcmp, 1, __wmemcmp_sse2)) |
| 262 | |
| 263 | #ifdef SHARED |
| 264 | /* Support sysdeps/x86_64/multiarch/memcpy_chk.S. */ |
| 265 | IFUNC_IMPL (i, name, __memcpy_chk, |
| 266 | #ifdef HAVE_AVX512_ASM_SUPPORT |
| 267 | IFUNC_IMPL_ADD (array, i, __memcpy_chk, |
| 268 | HAS_ARCH_FEATURE (AVX512F_Usable), |
| 269 | __memcpy_chk_avx512_no_vzeroupper) |
| 270 | #endif |
| 271 | IFUNC_IMPL_ADD (array, i, __memcpy_chk, |
| 272 | HAS_ARCH_FEATURE (AVX_Usable), |
| 273 | __memcpy_chk_avx_unaligned) |
| 274 | IFUNC_IMPL_ADD (array, i, __memcpy_chk, |
| 275 | HAS_CPU_FEATURE (SSSE3), |
| 276 | __memcpy_chk_ssse3_back) |
| 277 | IFUNC_IMPL_ADD (array, i, __memcpy_chk, |
| 278 | HAS_CPU_FEATURE (SSSE3), |
| 279 | __memcpy_chk_ssse3) |
| 280 | IFUNC_IMPL_ADD (array, i, __memcpy_chk, 1, |
| 281 | __memcpy_chk_sse2)) |
| 282 | |
| 283 | /* Support sysdeps/x86_64/multiarch/memcpy.S. */ |
| 284 | IFUNC_IMPL (i, name, memcpy, |
| 285 | IFUNC_IMPL_ADD (array, i, memcpy, |
| 286 | HAS_ARCH_FEATURE (AVX_Usable), |
| 287 | __memcpy_avx_unaligned) |
| 288 | IFUNC_IMPL_ADD (array, i, memcpy, HAS_CPU_FEATURE (SSSE3), |
| 289 | __memcpy_ssse3_back) |
| 290 | IFUNC_IMPL_ADD (array, i, memcpy, HAS_CPU_FEATURE (SSSE3), |
| 291 | __memcpy_ssse3) |
| 292 | #ifdef HAVE_AVX512_ASM_SUPPORT |
| 293 | IFUNC_IMPL_ADD (array, i, memcpy, |
| 294 | HAS_ARCH_FEATURE (AVX512F_Usable), |
| 295 | __memcpy_avx512_no_vzeroupper) |
| 296 | #endif |
| 297 | IFUNC_IMPL_ADD (array, i, memcpy, 1, __memcpy_sse2_unaligned) |
| 298 | IFUNC_IMPL_ADD (array, i, memcpy, 1, __memcpy_sse2)) |
| 299 | |
| 300 | /* Support sysdeps/x86_64/multiarch/mempcpy_chk.S. */ |
| 301 | IFUNC_IMPL (i, name, __mempcpy_chk, |
| 302 | #ifdef HAVE_AVX512_ASM_SUPPORT |
| 303 | IFUNC_IMPL_ADD (array, i, __mempcpy_chk, |
| 304 | HAS_ARCH_FEATURE (AVX512F_Usable), |
| 305 | __mempcpy_chk_avx512_no_vzeroupper) |
| 306 | #endif |
| 307 | IFUNC_IMPL_ADD (array, i, __mempcpy_chk, |
| 308 | HAS_ARCH_FEATURE (AVX_Usable), |
| 309 | __mempcpy_chk_avx_unaligned) |
| 310 | IFUNC_IMPL_ADD (array, i, __mempcpy_chk, |
| 311 | HAS_CPU_FEATURE (SSSE3), |
| 312 | __mempcpy_chk_ssse3_back) |
| 313 | IFUNC_IMPL_ADD (array, i, __mempcpy_chk, |
| 314 | HAS_CPU_FEATURE (SSSE3), |
| 315 | __mempcpy_chk_ssse3) |
| 316 | IFUNC_IMPL_ADD (array, i, __mempcpy_chk, 1, |
| 317 | __mempcpy_chk_sse2)) |
| 318 | |
| 319 | /* Support sysdeps/x86_64/multiarch/mempcpy.S. */ |
| 320 | IFUNC_IMPL (i, name, mempcpy, |
| 321 | #ifdef HAVE_AVX512_ASM_SUPPORT |
| 322 | IFUNC_IMPL_ADD (array, i, mempcpy, |
| 323 | HAS_ARCH_FEATURE (AVX512F_Usable), |
| 324 | __mempcpy_avx512_no_vzeroupper) |
| 325 | #endif |
| 326 | IFUNC_IMPL_ADD (array, i, mempcpy, |
| 327 | HAS_ARCH_FEATURE (AVX_Usable), |
| 328 | __mempcpy_avx_unaligned) |
| 329 | IFUNC_IMPL_ADD (array, i, mempcpy, HAS_CPU_FEATURE (SSSE3), |
| 330 | __mempcpy_ssse3_back) |
| 331 | IFUNC_IMPL_ADD (array, i, mempcpy, HAS_CPU_FEATURE (SSSE3), |
| 332 | __mempcpy_ssse3) |
| 333 | IFUNC_IMPL_ADD (array, i, mempcpy, 1, __mempcpy_sse2)) |
| 334 | |
| 335 | /* Support sysdeps/x86_64/multiarch/strncmp.S. */ |
| 336 | IFUNC_IMPL (i, name, strncmp, |
| 337 | IFUNC_IMPL_ADD (array, i, strncmp, HAS_CPU_FEATURE (SSE4_2), |
| 338 | __strncmp_sse42) |
| 339 | IFUNC_IMPL_ADD (array, i, strncmp, HAS_CPU_FEATURE (SSSE3), |
| 340 | __strncmp_ssse3) |
| 341 | IFUNC_IMPL_ADD (array, i, strncmp, 1, __strncmp_sse2)) |
| 342 | #endif |
| 343 | |
| 344 | return i; |
| 345 | } |
| 346 | |