chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / debian / patches / amd64 / cvs-avx-detection.diff
1 2011-07-23  Ulrich Drepper  <drepper@gmail.com>
2
3         * sysdeps/x86_64/dl-trampoline.S (_dl_runtime_profile): Fix one more
4         typo.
5         (_dl_x86_64_save_sse): Likewise.
6
7 2011-07-22  Ulrich Drepper  <drepper@gmail.com>
8  
9         * sysdeps/x86_64/dl-trampoline.S (_dl_runtime_profile): Fix test for
10         OSXSAVE.
11         (_dl_x86_64_save_sse): Likewise.
12
13 2011-07-21  Andreas Schwab  <schwab@redhat.com>
14
15         * sysdeps/x86_64/dl-trampoline.S (_dl_runtime_profile): Fix last
16         change.
17         (_dl_x86_64_save_sse): Use correct AVX check.
18
19 2011-07-20  Ulrich Drepper  <drepper@gmail.com>
20  
21         [BZ #13007]
22         * sysdeps/x86_64/dl-trampoline.S (_dl_runtime_profile): More complete
23         check for AVX enablement so that we don't crash with old kernels and
24         new hardware.
25         * elf/tst-audit4.c: Add same checks here.
26         * elf/tst-audit6.c: Likewise.
27
28 ---
29  elf/tst-audit4.c               |   22 ++++++++++++++++++----
30  elf/tst-audit6.c               |   22 ++++++++++++++++++----
31  sysdeps/x86_64/dl-trampoline.S |   36 +++++++++++++++++++++++++++---------
32  3 files changed, 63 insertions(+), 17 deletions(-)
33
34 --- a/elf/tst-audit4.c
35 +++ b/elf/tst-audit4.c
36 @@ -6,16 +6,30 @@
37  #include <cpuid.h>
38  #include <immintrin.h>
39  
40 +
41 +static int
42 +avx_enabled (void)
43 +{
44 +  unsigned int eax, ebx, ecx, edx;
45 +
46 +  if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0
47 +      || (ecx & (bit_AVX | bit_OSXSAVE)) != (bit_AVX | bit_OSXSAVE))
48 +    return 0;
49 +
50 +  /* Check the OS has AVX and SSE saving enabled.  */
51 +  asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
52 +
53 +  return (eax & 6) == 6;
54 +}
55 +
56 +
57  extern __m256i audit_test (__m256i, __m256i, __m256i, __m256i,
58                            __m256i, __m256i, __m256i, __m256i);
59  int
60  main (void)
61  {
62 -  unsigned int eax, ebx, ecx, edx;
63 -
64    /* Run AVX test only if AVX is supported.  */
65 -  if (__get_cpuid (1, &eax, &ebx, &ecx, &edx)
66 -      && (ecx & bit_AVX))
67 +  if (avx_enabled ())
68      {
69        __m256i ymm = _mm256_setzero_si256 ();
70        __m256i ret = audit_test (ymm, ymm, ymm, ymm, ymm, ymm, ymm, ymm);
71 --- a/elf/tst-audit6.c
72 +++ b/elf/tst-audit6.c
73 @@ -9,14 +9,28 @@
74  extern __m128i audit_test (__m128i, __m128i, __m128i, __m128i,
75                            __m128i, __m128i, __m128i, __m128i);
76  
77 -int
78 -main (void)
79 +
80 +static int
81 +avx_enabled (void)
82  {
83    unsigned int eax, ebx, ecx, edx;
84  
85 +  if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0
86 +      || (ecx & (bit_AVX | bit_OSXSAVE)) != (bit_AVX | bit_OSXSAVE))
87 +    return 0;
88 +
89 +  /* Check the OS has AVX and SSE saving enabled.  */
90 +  asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
91 +
92 +  return (eax & 6) == 6;
93 +}
94 +
95 +
96 +int
97 +main (void)
98 +{
99    /* Run AVX test only if AVX is supported.  */
100 -  if (__get_cpuid (1, &eax, &ebx, &ecx, &edx)
101 -      && (ecx & bit_AVX))
102 +  if (avx_enabled ())
103      {
104        __m128i xmm = _mm_setzero_si128 ();
105        __m128i ret = audit_test (xmm, xmm, xmm, xmm, xmm, xmm, xmm, xmm);
106 --- a/sysdeps/x86_64/dl-trampoline.S
107 +++ b/sysdeps/x86_64/dl-trampoline.S
108 @@ -1,5 +1,5 @@
109  /* PLT trampolines.  x86-64 version.
110 -   Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc.
111 +   Copyright (C) 2004, 2005, 2007, 2009, 2011 Free Software Foundation, Inc.
112     This file is part of the GNU C Library.
113  
114     The GNU C Library is free software; you can redistribute it and/or
115 @@ -139,11 +139,20 @@
116         movl    $1, %eax
117         cpuid
118         movq    %r11,%rbx               # Restore rbx
119 -       movl    $1, %eax
120 -       testl   $(1 << 28), %ecx
121 +       xorl    %eax, %eax
122 +       // AVX and XSAVE supported?
123 +       andl    $((1 << 28) | (1 << 27)), %ecx
124 +       cmpl    $((1 << 28) | (1 << 27)), %ecx
125         jne     2f
126 -       negl    %eax
127 -2:     movl    %eax, L(have_avx)(%rip)
128 +       xorl    %ecx, %ecx
129 +       // Get XFEATURE_ENABLED_MASK
130 +       xgetbv
131 +       andl    $0x6, %eax
132 +       cmpl    $0x6, %eax
133 +       // Nonzero if SSE and AVX state saving is enabled.
134 +       sete    %al
135 +2:     leal    -1(%eax,%eax), %eax
136 +       movl    %eax, L(have_avx)(%rip)
137         cmpl    $0, %eax
138  
139  1:     js      L(no_avx)
140 @@ -176,11 +185,20 @@
141         movl    $1, %eax
142         cpuid
143         movq    %r11,%rbx               # Restore rbx
144 -       movl    $1, %eax
145 -       testl   $(1 << 28), %ecx
146 +       xorl    %eax, %eax
147 +       // AVX and XSAVE supported?
148 +       andl    $((1 << 28) | (1 << 27)), %ecx
149 +       cmpl    $((1 << 28) | (1 << 27)), %ecx
150         jne     2f
151 -       negl    %eax
152 -2:     movl    %eax, L(have_avx)(%rip)
153 +       xorl    %ecx, %ecx
154 +       // Get XFEATURE_ENABLED_MASK
155 +       xgetbv
156 +       andl    $0x6, %eax
157 +       cmpl    $0x6, %eax
158 +       // Nonzero if SSE and AVX state saving is enabled.
159 +       sete    %al
160 +2:     leal    -1(%eax,%eax), %eax
161 +       movl    %eax, L(have_avx)(%rip)
162         cmpl    $0, %eax
163  
164  1:     js      L(no_avx5)