]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/x86_64/multiarch/test-multiarch.c
4eb0c16cd845d592ac0c2f705ebe713af21e6239
[thirdparty/glibc.git] / sysdeps / x86_64 / multiarch / test-multiarch.c
1 /* Test CPU feature data.
2 This file is part of the GNU C Library.
3 Copyright (C) 2012-2016 Free Software Foundation, Inc.
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 <init-arch.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 static char *cpu_flags;
25
26 /* Search for flags in /proc/cpuinfo and store line
27 in cpu_flags. */
28 void
29 get_cpuinfo (void)
30 {
31 FILE *f;
32 char *line = NULL;
33 size_t len = 0;
34 ssize_t read;
35
36 f = fopen ("/proc/cpuinfo", "r");
37 if (f == NULL)
38 {
39 printf ("cannot open /proc/cpuinfo\n");
40 exit (1);
41 }
42
43 while ((read = getline (&line, &len, f)) != -1)
44 {
45 if (strncmp (line, "flags", 5) == 0)
46 {
47 cpu_flags = strdup (line);
48 break;
49 }
50 }
51 fclose (f);
52 free (line);
53 }
54
55 int
56 check_proc (const char *proc_name, int flag, const char *name)
57 {
58 int found = 0;
59
60 printf ("Checking %s:\n", name);
61 printf (" init-arch %d\n", flag);
62 if (strstr (cpu_flags, proc_name) != NULL)
63 found = 1;
64 printf (" cpuinfo (%s) %d\n", proc_name, found);
65
66 if (found != flag)
67 printf (" *** failure ***\n");
68
69 return (found != flag);
70 }
71
72 static int
73 do_test (int argc, char **argv)
74 {
75 int fails;
76
77 get_cpuinfo ();
78 fails = check_proc ("avx", HAS_ARCH_FEATURE (AVX_Usable),
79 "HAS_ARCH_FEATURE (AVX_Usable)");
80 fails += check_proc ("fma4", HAS_ARCH_FEATURE (FMA4_Usable),
81 "HAS_ARCH_FEATURE (FMA4_Usable)");
82 fails += check_proc ("sse4_2", HAS_CPU_FEATURE (SSE4_2),
83 "HAS_CPU_FEATURE (SSE4_2)");
84 fails += check_proc ("sse4_1", HAS_CPU_FEATURE (SSE4_1)
85 , "HAS_CPU_FEATURE (SSE4_1)");
86 fails += check_proc ("ssse3", HAS_CPU_FEATURE (SSSE3),
87 "HAS_CPU_FEATURE (SSSE3)");
88 fails += check_proc ("popcnt", HAS_CPU_FEATURE (POPCOUNT),
89 "HAS_CPU_FEATURE (POPCOUNT)");
90
91 printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails);
92
93 return (fails != 0);
94 }
95
96 #include "../../../test-skeleton.c"