Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / s390 / s390-64 / multiarch / ifunc-resolve.c
blobf8c69ffbb8476c3f94a4a9bc2daa0da3dd85e711
1 /* IFUNC resolver function for CPU specific functions.
2 64 bit S/390 version.
3 Copyright (C) 2012-2014 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <unistd.h>
21 #include <dl-procinfo.h>
23 #define STFLE_BITS_Z10 34 /* General instructions extension */
24 #define STFLE_BITS_Z196 45 /* Distinct operands, pop ... */
26 #ifndef NOT_IN_libc
28 #define IFUNC_RESOLVE(FUNC) \
29 asm (".globl " #FUNC "\n\t" \
30 ".type " #FUNC ",@gnu_indirect_function\n\t" \
31 ".set " #FUNC ",resolve_" #FUNC "\n\t" \
32 ".globl __GI_" #FUNC "\n\t" \
33 ".set __GI_" #FUNC "," #FUNC "\n"); \
35 /* Make the declarations of the optimized functions hidden in order
36 to prevent GOT slots being generated for them. */ \
37 extern void *FUNC##_z196 attribute_hidden; \
38 extern void *FUNC##_z10 attribute_hidden; \
39 extern void *FUNC##_z900 attribute_hidden; \
41 void *resolve_##FUNC (unsigned long int dl_hwcap) \
42 { \
43 if (dl_hwcap & HWCAP_S390_STFLE) \
44 { \
45 /* We want just 1 double word to be returned. */ \
46 register unsigned long reg0 asm("0") = 0; \
47 unsigned long stfle_bits; \
49 asm volatile(".machine push" "\n\t" \
50 ".machine \"z9-109\"" "\n\t" \
51 "stfle %0" "\n\t" \
52 ".machine pop" "\n" \
53 : "=QS" (stfle_bits), "+d" (reg0) \
54 : : "cc"); \
56 if ((stfle_bits & (1UL << (63 - STFLE_BITS_Z196))) != 0) \
57 return &FUNC##_z196; \
58 else if ((stfle_bits & (1UL << (63 - STFLE_BITS_Z10))) != 0) \
59 return &FUNC##_z10; \
60 else \
61 return &FUNC##_z900; \
62 } \
63 else \
64 return &FUNC##_z900; \
67 IFUNC_RESOLVE(memset)
68 IFUNC_RESOLVE(memcmp)
69 asm(".weak bcmp ; bcmp = memcmp");
71 /* In the static lib memcpy is needed before the reloc is resolved. */
72 #ifdef SHARED
73 IFUNC_RESOLVE(memcpy)
74 #endif
76 #endif