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