* [PATCH] x86: Add __cpuidex and include guard to <cpuid.h>
@ 2020-07-18 11:52 H.J. Lu
0 siblings, 0 replies; 3+ messages in thread
From: H.J. Lu @ 2020-07-18 11:52 UTC (permalink / raw)
To: gcc-patches
Add
void __cpuidex (int __cpuid_info[4], int __leaf, int __subleaf);
as well as include guard to <cpuid.h>.
gcc/
PR target/95973
PR target/96238
* config/i386/cpuid.h: Add include guard.
(__cpuidex): New.
gcc/testsuite/
PR target/95973
PR target/96238
* gcc.target/i386/pr95973.c: New test.
---
gcc/config/i386/cpuid.h | 12 ++++++++++++
gcc/testsuite/gcc.target/i386/pr95973.c | 26 +++++++++++++++++++++++++
2 files changed, 38 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/i386/pr95973.c
diff --git a/gcc/config/i386/cpuid.h b/gcc/config/i386/cpuid.h
index 94af4910d3c..bca61d620db 100644
--- a/gcc/config/i386/cpuid.h
+++ b/gcc/config/i386/cpuid.h
@@ -21,6 +21,9 @@
* <http://www.gnu.org/licenses/>.
*/
+#ifndef _CPUID_H_INCLUDED
+#define _CPUID_H_INCLUDED
+
/* %eax */
#define bit_AVX512BF16 (1 << 5)
@@ -313,3 +316,12 @@ __get_cpuid_count (unsigned int __leaf, unsigned int __subleaf,
__cpuid_count (__leaf, __subleaf, *__eax, *__ebx, *__ecx, *__edx);
return 1;
}
+
+static __inline void
+__cpuidex (int __cpuid_info[4], int __leaf, int __subleaf)
+{
+ __cpuid_count (__leaf, __subleaf, __cpuid_info[0], __cpuid_info[1],
+ __cpuid_info[2], __cpuid_info[3]);
+}
+
+#endif /* _CPUID_H_INCLUDED */
diff --git a/gcc/testsuite/gcc.target/i386/pr95973.c b/gcc/testsuite/gcc.target/i386/pr95973.c
new file mode 100644
index 00000000000..6d8e8f12f64
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr95973.c
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -Wall" } */
+
+#include <stdlib.h>
+#include <cpuid.h>
+#include <cpuid.h>
+
+int
+main ()
+{
+ unsigned int eax, ebx, ecx, edx;
+ int cpuid_info[4];
+
+ if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
+ return 0;
+
+ __cpuidex (cpuid_info, 7, 0);
+
+ if (cpuid_info[0] != eax
+ || cpuid_info[1] != ebx
+ || cpuid_info[2] != ecx
+ || cpuid_info[3] != edx)
+ abort ();
+
+ return 0;
+}
--
2.26.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86: Add __cpuidex and include guard to <cpuid.h>
2020-07-19 7:19 Uros Bizjak
@ 2020-07-19 11:09 ` H.J. Lu
0 siblings, 0 replies; 3+ messages in thread
From: H.J. Lu @ 2020-07-19 11:09 UTC (permalink / raw)
To: Uros Bizjak; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 727 bytes --]
On Sun, Jul 19, 2020 at 12:19 AM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> > Add
> >
> > void __cpuidex (int __cpuid_info[4], int __leaf, int __subleaf);
> >
> > as well as include guard to <cpuid.h>.
> >
> > gcc/
> >
> > PR target/95973
> > PR target/96238
> > * config/i386/cpuid.h: Add include guard.
> > (__cpuidex): New.
> >
> > gcc/testsuite/
> >
> > PR target/95973
> > PR target/96238
> > * gcc.target/i386/pr95973.c: New test.
>
> OK.
>
> + if (cpuid_info[0] != eax
> + || cpuid_info[1] != ebx
> + || cpuid_info[2] != ecx
> + || cpuid_info[3] != edx)
> + abort ();
>
> You can use __builtin_abort here to avoid inclusion of stdlib.h.
Fixed.
This is the patch I am checking in.
Thanks.
--
H.J.
[-- Attachment #2: 0001-x86-Add-__cpuidex-and-include-guard-to-cpuid.h.patch --]
[-- Type: text/x-patch, Size: 2167 bytes --]
From 56633350c6438a3a64bd84af809b4663ea627208 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Sat, 18 Jul 2020 04:43:10 -0700
Subject: [PATCH] x86: Add __cpuidex and include guard to <cpuid.h>
Add
void __cpuidex (int __cpuid_info[4], int __leaf, int __subleaf);
as well as include guard to <cpuid.h>.
gcc/
PR target/95973
PR target/96238
* config/i386/cpuid.h: Add include guard.
(__cpuidex): New.
gcc/testsuite/
PR target/95973
PR target/96238
* gcc.target/i386/pr95973.c: New test.
---
gcc/config/i386/cpuid.h | 12 ++++++++++++
gcc/testsuite/gcc.target/i386/pr95973.c | 25 +++++++++++++++++++++++++
2 files changed, 37 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/i386/pr95973.c
diff --git a/gcc/config/i386/cpuid.h b/gcc/config/i386/cpuid.h
index 94af4910d3c..bca61d620db 100644
--- a/gcc/config/i386/cpuid.h
+++ b/gcc/config/i386/cpuid.h
@@ -21,6 +21,9 @@
* <http://www.gnu.org/licenses/>.
*/
+#ifndef _CPUID_H_INCLUDED
+#define _CPUID_H_INCLUDED
+
/* %eax */
#define bit_AVX512BF16 (1 << 5)
@@ -313,3 +316,12 @@ __get_cpuid_count (unsigned int __leaf, unsigned int __subleaf,
__cpuid_count (__leaf, __subleaf, *__eax, *__ebx, *__ecx, *__edx);
return 1;
}
+
+static __inline void
+__cpuidex (int __cpuid_info[4], int __leaf, int __subleaf)
+{
+ __cpuid_count (__leaf, __subleaf, __cpuid_info[0], __cpuid_info[1],
+ __cpuid_info[2], __cpuid_info[3]);
+}
+
+#endif /* _CPUID_H_INCLUDED */
diff --git a/gcc/testsuite/gcc.target/i386/pr95973.c b/gcc/testsuite/gcc.target/i386/pr95973.c
new file mode 100644
index 00000000000..08c7dba8f46
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr95973.c
@@ -0,0 +1,25 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -Wall" } */
+
+#include <cpuid.h>
+#include <cpuid.h>
+
+int
+main ()
+{
+ unsigned int eax, ebx, ecx, edx;
+ int cpuid_info[4];
+
+ if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
+ return 0;
+
+ __cpuidex (cpuid_info, 7, 0);
+
+ if (cpuid_info[0] != eax
+ || cpuid_info[1] != ebx
+ || cpuid_info[2] != ecx
+ || cpuid_info[3] != edx)
+ __builtin_abort ();
+
+ return 0;
+}
--
2.26.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86: Add __cpuidex and include guard to <cpuid.h>
@ 2020-07-19 7:19 Uros Bizjak
2020-07-19 11:09 ` H.J. Lu
0 siblings, 1 reply; 3+ messages in thread
From: Uros Bizjak @ 2020-07-19 7:19 UTC (permalink / raw)
To: gcc-patches
> Add
>
> void __cpuidex (int __cpuid_info[4], int __leaf, int __subleaf);
>
> as well as include guard to <cpuid.h>.
>
> gcc/
>
> PR target/95973
> PR target/96238
> * config/i386/cpuid.h: Add include guard.
> (__cpuidex): New.
>
> gcc/testsuite/
>
> PR target/95973
> PR target/96238
> * gcc.target/i386/pr95973.c: New test.
OK.
+ if (cpuid_info[0] != eax
+ || cpuid_info[1] != ebx
+ || cpuid_info[2] != ecx
+ || cpuid_info[3] != edx)
+ abort ();
You can use __builtin_abort here to avoid inclusion of stdlib.h.
Thanks,
Uros.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-19 11:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-18 11:52 [PATCH] x86: Add __cpuidex and include guard to <cpuid.h> H.J. Lu
2020-07-19 7:19 Uros Bizjak
2020-07-19 11:09 ` H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).