446cf2
commit 72771e53753647111d31c5c4bf43d8901e6baf7e
446cf2
Author: H.J. Lu <hjl.tools@gmail.com>
446cf2
Date:   Wed Oct 17 15:16:38 2018 -0700
446cf2
446cf2
    x86: Use _rdtsc intrinsic for HP_TIMING_NOW
446cf2
    
446cf2
    Since _rdtsc intrinsic is supported in GCC 4.9, we can use it for
446cf2
    HP_TIMING_NOW.  This patch
446cf2
    
446cf2
    1. Create x86 hp-timing.h to replace i686 and x86_64 hp-timing.h.
446cf2
    2. Move MINIMUM_ISA from init-arch.h to isa.h so that x86 hp-timing.h
446cf2
    can check minimum x86 ISA to decide if _rdtsc can be used.
446cf2
    
446cf2
    NB: Checking if __i686__ isn't sufficient since __i686__ may not be
446cf2
    defined when building for i686 class processors.
446cf2
    
446cf2
            * sysdeps/i386/init-arch.h: Removed.
446cf2
            * sysdeps/i386/i586/init-arch.h: Likewise.
446cf2
            * sysdeps/i386/i686/init-arch.h: Likewise.
446cf2
            * sysdeps/i386/i686/hp-timing.h: Likewise.
446cf2
            * sysdeps/x86_64/hp-timing.h: Likewise.
446cf2
            * sysdeps/i386/isa.h: New file.
446cf2
            * sysdeps/i386/i586/isa.h: Likewise.
446cf2
            * sysdeps/i386/i686/isa.h: Likewise.
446cf2
            * sysdeps/x86_64/isa.h: Likewise.
446cf2
            * sysdeps/x86/hp-timing.h: New file.
446cf2
            * sysdeps/x86/init-arch.h: Include <isa.h>.
446cf2
446cf2
diff --git a/sysdeps/i386/i586/init-arch.h b/sysdeps/i386/i586/isa.h
446cf2
similarity index 85%
446cf2
rename from sysdeps/i386/i586/init-arch.h
446cf2
rename to sysdeps/i386/i586/isa.h
446cf2
index 72fb46c61e4c5f34..79481ce68033e58c 100644
446cf2
--- a/sysdeps/i386/i586/init-arch.h
446cf2
+++ b/sysdeps/i386/i586/isa.h
446cf2
@@ -1,4 +1,5 @@
446cf2
-/* Copyright (C) 2015-2018 Free Software Foundation, Inc.
446cf2
+/* x86 ISA info.  i586 version.
446cf2
+   Copyright (C) 2018 Free Software Foundation, Inc.
446cf2
    This file is part of the GNU C Library.
446cf2
 
446cf2
    The GNU C Library is free software; you can redistribute it and/or
446cf2
@@ -15,5 +16,9 @@
446cf2
    License along with the GNU C Library; if not, see
446cf2
    <http://www.gnu.org/licenses/>.  */
446cf2
 
446cf2
+#ifndef _ISA_H
446cf2
+#define _ISA_H
446cf2
+
446cf2
 #define MINIMUM_ISA 586
446cf2
-#include <sysdeps/x86/init-arch.h>
446cf2
+
446cf2
+#endif
446cf2
diff --git a/sysdeps/i386/i686/init-arch.h b/sysdeps/i386/i686/isa.h
446cf2
similarity index 85%
446cf2
rename from sysdeps/i386/i686/init-arch.h
446cf2
rename to sysdeps/i386/i686/isa.h
446cf2
index ab99392b586b1e2d..584e26bd4f928021 100644
446cf2
--- a/sysdeps/i386/i686/init-arch.h
446cf2
+++ b/sysdeps/i386/i686/isa.h
446cf2
@@ -1,4 +1,5 @@
446cf2
-/* Copyright (C) 2015-2018 Free Software Foundation, Inc.
446cf2
+/* x86 ISA info.  i686 version.
446cf2
+   Copyright (C) 2018 Free Software Foundation, Inc.
446cf2
    This file is part of the GNU C Library.
446cf2
 
446cf2
    The GNU C Library is free software; you can redistribute it and/or
446cf2
@@ -15,5 +16,9 @@
446cf2
    License along with the GNU C Library; if not, see
446cf2
    <http://www.gnu.org/licenses/>.  */
446cf2
 
446cf2
+#ifndef _ISA_H
446cf2
+#define _ISA_H
446cf2
+
446cf2
 #define MINIMUM_ISA 686
446cf2
-#include <sysdeps/x86/init-arch.h>
446cf2
+
446cf2
+#endif
446cf2
diff --git a/sysdeps/i386/init-arch.h b/sysdeps/i386/isa.h
446cf2
similarity index 85%
446cf2
rename from sysdeps/i386/init-arch.h
446cf2
rename to sysdeps/i386/isa.h
446cf2
index 043089ceb99db33f..e0a1e9c84fd37efb 100644
446cf2
--- a/sysdeps/i386/init-arch.h
446cf2
+++ b/sysdeps/i386/isa.h
446cf2
@@ -1,4 +1,5 @@
446cf2
-/* Copyright (C) 2015-2018 Free Software Foundation, Inc.
446cf2
+/* x86 ISA info.  i486 version.
446cf2
+   Copyright (C) 2018 Free Software Foundation, Inc.
446cf2
    This file is part of the GNU C Library.
446cf2
 
446cf2
    The GNU C Library is free software; you can redistribute it and/or
446cf2
@@ -15,5 +16,9 @@
446cf2
    License along with the GNU C Library; if not, see
446cf2
    <http://www.gnu.org/licenses/>.  */
446cf2
 
446cf2
+#ifndef _ISA_H
446cf2
+#define _ISA_H
446cf2
+
446cf2
 #define MINIMUM_ISA 486
446cf2
-#include <sysdeps/x86/init-arch.h>
446cf2
+
446cf2
+#endif
446cf2
diff --git a/sysdeps/i386/i686/hp-timing.h b/sysdeps/x86/hp-timing.h
446cf2
similarity index 69%
446cf2
rename from sysdeps/i386/i686/hp-timing.h
446cf2
rename to sysdeps/x86/hp-timing.h
446cf2
index 59af526fdba0b6f5..1c20e9d8289cc15b 100644
446cf2
--- a/sysdeps/i386/i686/hp-timing.h
446cf2
+++ b/sysdeps/x86/hp-timing.h
446cf2
@@ -1,7 +1,6 @@
446cf2
-/* High precision, low overhead timing functions.  i686 version.
446cf2
-   Copyright (C) 1998-2018 Free Software Foundation, Inc.
446cf2
+/* High precision, low overhead timing functions.  x86 version.
446cf2
+   Copyright (C) 2018 Free Software Foundation, Inc.
446cf2
    This file is part of the GNU C Library.
446cf2
-   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
446cf2
 
446cf2
    The GNU C Library is free software; you can redistribute it and/or
446cf2
    modify it under the terms of the GNU Lesser General Public
446cf2
@@ -20,12 +19,17 @@
446cf2
 #ifndef _HP_TIMING_H
446cf2
 #define _HP_TIMING_H	1
446cf2
 
446cf2
+#include <isa.h>
446cf2
+
446cf2
+#if MINIMUM_ISA == 686 || MINIMUM_ISA == 8664
446cf2
+# include <x86intrin.h>
446cf2
+
446cf2
 /* We always assume having the timestamp register.  */
446cf2
-#define HP_TIMING_AVAIL		(1)
446cf2
-#define HP_SMALL_TIMING_AVAIL	(1)
446cf2
+# define HP_TIMING_AVAIL	(1)
446cf2
+# define HP_SMALL_TIMING_AVAIL	(1)
446cf2
 
446cf2
 /* We indeed have inlined functions.  */
446cf2
-#define HP_TIMING_INLINE	(1)
446cf2
+# define HP_TIMING_INLINE	(1)
446cf2
 
446cf2
 /* We use 64bit values for the times.  */
446cf2
 typedef unsigned long long int hp_timing_t;
446cf2
@@ -35,8 +39,14 @@ typedef unsigned long long int hp_timing_t;
446cf2
    running in this moment.  This could be changed by using a barrier like
446cf2
    'cpuid' right before the `rdtsc' instruciton.  But we are not interested
446cf2
    in accurate clock cycles here so we don't do this.  */
446cf2
-#define HP_TIMING_NOW(Var)	__asm__ __volatile__ ("rdtsc" : "=A" (Var))
446cf2
+# define HP_TIMING_NOW(Var)	((Var) = _rdtsc ())
446cf2
 
446cf2
-#include <hp-timing-common.h>
446cf2
+# include <hp-timing-common.h>
446cf2
+#else
446cf2
+/* NB: Undefine _HP_TIMING_H so that <sysdeps/generic/hp-timing.h> will
446cf2
+   be included.  */
446cf2
+# undef _HP_TIMING_H
446cf2
+# include <sysdeps/generic/hp-timing.h>
446cf2
+#endif
446cf2
 
446cf2
-#endif	/* hp-timing.h */
446cf2
+#endif /* hp-timing.h */
446cf2
diff --git a/sysdeps/x86/init-arch.h b/sysdeps/x86/init-arch.h
446cf2
index a81ca8a4eb292e72..bc860fcd69a605b3 100644
446cf2
--- a/sysdeps/x86/init-arch.h
446cf2
+++ b/sysdeps/x86/init-arch.h
446cf2
@@ -21,6 +21,7 @@
446cf2
 # include <ldsodefs.h>
446cf2
 #endif
446cf2
 #include <ifunc-init.h>
446cf2
+#include <isa.h>
446cf2
 
446cf2
 #ifndef __x86_64__
446cf2
 /* Due to the reordering and the other nifty extensions in i686, it is
446cf2
diff --git a/sysdeps/x86_64/hp-timing.h b/sysdeps/x86_64/hp-timing.h
446cf2
deleted file mode 100644
446cf2
index ec543bef03b6c2d1..0000000000000000
446cf2
--- a/sysdeps/x86_64/hp-timing.h
446cf2
+++ /dev/null
446cf2
@@ -1,40 +0,0 @@
446cf2
-/* High precision, low overhead timing functions.  x86-64 version.
446cf2
-   Copyright (C) 2002-2018 Free Software Foundation, Inc.
446cf2
-   This file is part of the GNU C Library.
446cf2
-
446cf2
-   The GNU C Library is free software; you can redistribute it and/or
446cf2
-   modify it under the terms of the GNU Lesser General Public
446cf2
-   License as published by the Free Software Foundation; either
446cf2
-   version 2.1 of the License, or (at your option) any later version.
446cf2
-
446cf2
-   The GNU C Library is distributed in the hope that it will be useful,
446cf2
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
-   Lesser General Public License for more details.
446cf2
-
446cf2
-   You should have received a copy of the GNU Lesser General Public
446cf2
-   License along with the GNU C Library; if not, see
446cf2
-   <http://www.gnu.org/licenses/>.  */
446cf2
-
446cf2
-#ifndef _HP_TIMING_H
446cf2
-#define _HP_TIMING_H	1
446cf2
-
446cf2
-/* We always assume having the timestamp register.  */
446cf2
-#define HP_TIMING_AVAIL		(1)
446cf2
-#define HP_SMALL_TIMING_AVAIL	(1)
446cf2
-
446cf2
-/* We indeed have inlined functions.  */
446cf2
-#define HP_TIMING_INLINE	(1)
446cf2
-
446cf2
-/* We use 64bit values for the times.  */
446cf2
-typedef unsigned long long int hp_timing_t;
446cf2
-
446cf2
-/* The "=A" constraint used in 32-bit mode does not work in 64-bit mode.  */
446cf2
-#define HP_TIMING_NOW(Var) \
446cf2
-  ({ unsigned int _hi, _lo; \
446cf2
-     asm volatile ("rdtsc" : "=a" (_lo), "=d" (_hi)); \
446cf2
-     (Var) = ((unsigned long long int) _hi << 32) | _lo; })
446cf2
-
446cf2
-#include <hp-timing-common.h>
446cf2
-
446cf2
-#endif /* hp-timing.h */
446cf2
diff --git a/sysdeps/x86_64/isa.h b/sysdeps/x86_64/isa.h
446cf2
new file mode 100644
446cf2
index 0000000000000000..452bce75eb03a474
446cf2
--- /dev/null
446cf2
+++ b/sysdeps/x86_64/isa.h
446cf2
@@ -0,0 +1,24 @@
446cf2
+/* x86 ISA info.  x86-64 version.
446cf2
+   Copyright (C) 2018 Free Software Foundation, Inc.
446cf2
+   This file is part of the GNU C Library.
446cf2
+
446cf2
+   The GNU C Library is free software; you can redistribute it and/or
446cf2
+   modify it under the terms of the GNU Lesser General Public
446cf2
+   License as published by the Free Software Foundation; either
446cf2
+   version 2.1 of the License, or (at your option) any later version.
446cf2
+
446cf2
+   The GNU C Library is distributed in the hope that it will be useful,
446cf2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
+   Lesser General Public License for more details.
446cf2
+
446cf2
+   You should have received a copy of the GNU Lesser General Public
446cf2
+   License along with the GNU C Library; if not, see
446cf2
+   <http://www.gnu.org/licenses/>.  */
446cf2
+
446cf2
+#ifndef _ISA_H
446cf2
+#define _ISA_H
446cf2
+
446cf2
+#define MINIMUM_ISA 8664
446cf2
+
446cf2
+#endif