Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / x86_64 / multiarch / test-multiarch.c
blob0b144bc06d56fe83a0bb86b360e852c99392b280
1 /* Test CPU feature data.
2 This file is part of the GNU C Library.
3 Copyright (C) 2012-2014 Free Software Foundation, Inc.
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.
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.
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/>. */
19 #include <init-arch.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
24 static char *cpu_flags;
26 /* Search for flags in /proc/cpuinfo and store line
27 in cpu_flags. */
28 void
29 get_cpuinfo (void)
31 FILE *f;
32 char *line = NULL;
33 size_t len = 0;
34 ssize_t read;
36 f = fopen ("/proc/cpuinfo", "r");
37 if (f == NULL)
39 printf ("cannot open /proc/cpuinfo\n");
40 exit (1);
43 while ((read = getline (&line, &len, f)) != -1)
45 if (strncmp (line, "flags", 5) == 0)
47 cpu_flags = strdup (line);
48 break;
51 fclose (f);
52 free (line);
55 int
56 check_proc (const char *proc_name, int flag, const char *name)
58 int found = 0;
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);
66 if (found != flag)
67 printf (" *** failure ***\n");
69 return (found != flag);
72 static int
73 do_test (int argc, char **argv)
75 int fails;
77 get_cpuinfo ();
78 fails = check_proc ("avx", HAS_AVX, "HAS_AVX");
79 fails += check_proc ("fma4", HAS_FMA4, "HAS_FMA4");
80 fails += check_proc ("sse4_2", HAS_SSE4_2, "HAS_SSE4_2");
81 fails += check_proc ("sse4_1", HAS_SSE4_1, "HAS_SSE4_1");
82 fails += check_proc ("ssse3", HAS_SSSE3, "HAS_SSSE3");
83 fails += check_proc ("popcnt", HAS_POPCOUNT, "HAS_POPCOUNT");
85 printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails);
87 return (fails != 0);
90 #include "../../../test-skeleton.c"