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