Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / s390 / s390-32 / multiarch / ifunc-resolve.c
blob2ccfc9c105ed0352fb5a710b20c766f7c3d2eab1
1 /* IFUNC resolver function for CPU specific functions.
2 32 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##_g5 attribute_hidden; \
41 void *resolve_##FUNC (unsigned long int dl_hwcap) \
42 { \
43 if ((dl_hwcap & HWCAP_S390_STFLE) \
44 && (dl_hwcap & HWCAP_S390_ZARCH) \
45 && (dl_hwcap & HWCAP_S390_HIGH_GPRS)) \
46 { \
47 /* We want just 1 double word to be returned. */ \
48 register unsigned long reg0 asm("0") = 0; \
49 unsigned long long stfle_bits; \
51 asm volatile(".insn s,0xb2b00000,%0" "\n\t" /* stfle */ \
52 : "=QS" (stfle_bits), "+d" (reg0) \
53 : : "cc"); \
55 if ((stfle_bits & (1ULL << (63 - STFLE_BITS_Z196))) != 0) \
56 return &FUNC##_z196; \
57 else if ((stfle_bits & (1ULL << (63 - STFLE_BITS_Z10))) != 0) \
58 return &FUNC##_z10; \
59 } \
60 return &FUNC##_g5; \
63 IFUNC_RESOLVE(memset)
64 IFUNC_RESOLVE(memcmp)
65 asm(".weak bcmp ; bcmp = memcmp");
67 /* In the static lib memcpy is needed before the reloc is resolved. */
68 #ifdef SHARED
69 IFUNC_RESOLVE(memcpy)
70 #endif
72 #endif