This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] BZ #14059 - HAS_FMA4 check needs to also check for AVX


Btw. here's a small test program to show that the values are setup correctly.

Currently it fails on my system (/proc/cpuinfo contains avx but
glibc test reports it does not).

Hope it's usefull,
Andreas

2012-05-14  Andreas Jaeger  <aj@suse.de>

	* sysdeps/x86_64/multiarch/Makefile (tests) [subdir=csu]: Add
	test-multiarch.

	* sysdeps/x86_64/multiarch/test-multiarch.c: New file.

commit 145434c41101965bf8f985ee1350f8ba40225778
Author: Andreas Jaeger <aj@suse.de>
Date:   Mon May 14 09:51:08 2012 +0200

    Add test for cpu feature flags

diff --git a/sysdeps/x86_64/multiarch/Makefile b/sysdeps/x86_64/multiarch/Makefile
index 9a183f0..dd6c27d 100644
--- a/sysdeps/x86_64/multiarch/Makefile
+++ b/sysdeps/x86_64/multiarch/Makefile
@@ -1,5 +1,6 @@
 ifeq ($(subdir),csu)
 aux += init-arch
+tests += test-multiarch
 gen-as-const-headers += ifunc-defines.sym
 endif
 
diff --git a/sysdeps/x86_64/multiarch/test-multiarch.c b/sysdeps/x86_64/multiarch/test-multiarch.c
new file mode 100644
index 0000000..09acf16
--- /dev/null
+++ b/sysdeps/x86_64/multiarch/test-multiarch.c
@@ -0,0 +1,88 @@
+/* Test CPU feature data.
+   This file is part of the GNU C Library.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <init-arch.h>
+#include <stdio.h>
+#include <string.h>
+
+static char *cpu_flags;
+
+/* Search for flags in /proc/cpuinfo and store line
+   in cpu_flags.  */
+void
+get_cpuinfo (void)
+{
+  FILE *f;
+  char *line = NULL;
+  size_t len = 0;
+  ssize_t read;
+
+  f = fopen ("/proc/cpuinfo", "r");
+  if (f == NULL)
+    {
+      printf ("cannot open /proc/cpuinfo");
+      exit (1);
+    }
+
+  while ((read = getline (&line, &len, f)) != -1)
+    {
+      if (strncmp (line, "flags", 5) == 0)
+	{
+	  cpu_flags = strdup (line);
+	  break;
+	}
+    }
+  fclose (f);
+  free (line);
+}
+
+int
+check_proc (const char *proc_name, int flag, const char *name)
+{
+  char *s;
+  int found = 0;
+
+  printf ("Checking %s:\n", name);
+  printf ("  init-arch %d\n", flag);
+  if (strstr (cpu_flags, proc_name) != NULL)
+    found = 1;
+  printf ("  cpuinfo (%s) %d\n", proc_name, found);
+
+  if (found != flag)
+    printf (" *** failure ***\n");
+
+  return (found != flag);
+}
+
+int
+main (void)
+{
+  int fails;
+
+  get_cpuinfo ();
+  fails = check_proc ("avx", HAS_AVX, "HAS_AVX");
+  fails += check_proc ("fma4", HAS_FMA4, "HAS_FMA4");
+  fails += check_proc ("sse4_2", HAS_SSE4_2, "HAS_SSE4_2");
+  fails += check_proc ("sse4_1", HAS_SSE4_1, "HAS_SSE4_1");
+  fails += check_proc ("ssse3", HAS_SSSE3, "HAS_SSSE3");
+  fails += check_proc ("popcnt", HAS_POPCOUNT, "HAS_POPCOUNT");
+
+  printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails);
+
+  return (fails != 0);
+}

-- 
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]