public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Tom de Vries <vries@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7893] [nvptx] Add __PTX_ISA_VERSION_{MAJOR,MINOR}__ Date: Tue, 29 Mar 2022 14:17:01 +0000 (GMT) [thread overview] Message-ID: <20220329141701.B5B493858C50@sourceware.org> (raw) https://gcc.gnu.org/g:a2eacdbd4c4a698b3b6f27ef5e1f8dd3d836b2e5 commit r12-7893-ga2eacdbd4c4a698b3b6f27ef5e1f8dd3d836b2e5 Author: Tom de Vries <tdevries@suse.de> Date: Tue Mar 29 16:04:09 2022 +0200 [nvptx] Add __PTX_ISA_VERSION_{MAJOR,MINOR}__ Add preprocessor macros __PTX_ISA_VERSION_MAJOR__ and __PTX_ISA_VERSION_MINOR__. For the default 6.0, we have: ... $ echo | cc1 -E -dD - 2>&1 | grep PTX_ISA_VERSION #define __PTX_ISA_VERSION_MAJOR__ 6 #define __PTX_ISA_VERSION_MINOR__ 0 ... and for 3.1, we have: ... $ echo | cc1 -mptx=3.1 -E -dD - 2>&1 | grep PTX_ISA_VERSION #define __PTX_ISA_VERSION_MAJOR__ 3 #define __PTX_ISA_VERSION_MINOR__ 1 ... These can be used to express things like: ... #if __PTX_ISA_VERSION_MAJOR__ >= 4 && __PTX_ISA_VERSION_MAJOR__ >= 1 /* Code using %dynamic_smem_size. */ #else /* Fallback code. */ #endif ... Tested on nvptx. gcc/ChangeLog: 2022-03-29 Tom de Vries <tdevries@suse.de> PR target/104857 * config/nvptx/nvptx-c.cc (nvptx_cpu_cpp_builtins): Emit __PTX_ISA_VERSION_MAJOR__ and __PTX_ISA_VERSION_MINOR__. * config/nvptx/nvptx.cc (ptx_version_to_number): New function. * config/nvptx/nvptx-protos.h (ptx_version_to_number): Declare. gcc/testsuite/ChangeLog: 2022-03-29 Tom de Vries <tdevries@suse.de> PR target/104857 * gcc.target/nvptx/ptx31.c: New test. * gcc.target/nvptx/ptx60.c: New test. * gcc.target/nvptx/ptx63.c: New test. * gcc.target/nvptx/ptx70.c: New test. Diff: --- gcc/config/nvptx/nvptx-c.cc | 9 +++++++++ gcc/config/nvptx/nvptx-protos.h | 1 + gcc/config/nvptx/nvptx.cc | 22 ++++++++++++++++++++++ gcc/testsuite/gcc.target/nvptx/ptx31.c | 10 ++++++++++ gcc/testsuite/gcc.target/nvptx/ptx60.c | 10 ++++++++++ gcc/testsuite/gcc.target/nvptx/ptx63.c | 10 ++++++++++ gcc/testsuite/gcc.target/nvptx/ptx70.c | 10 ++++++++++ 7 files changed, 72 insertions(+) diff --git a/gcc/config/nvptx/nvptx-c.cc b/gcc/config/nvptx/nvptx-c.cc index 02f75625064..f060a8ab1d4 100644 --- a/gcc/config/nvptx/nvptx-c.cc +++ b/gcc/config/nvptx/nvptx-c.cc @@ -49,5 +49,14 @@ nvptx_cpu_cpp_builtins (void) #include "nvptx-sm.def" #undef NVPTX_SM cpp_define (parse_in, ptx_sm); + + { + unsigned major + = ptx_version_to_number ((ptx_version)ptx_version_option, true); + unsigned minor + = ptx_version_to_number ((ptx_version)ptx_version_option, false); + cpp_define_formatted (parse_in, "__PTX_ISA_VERSION_MAJOR__=%u", major); + cpp_define_formatted (parse_in, "__PTX_ISA_VERSION_MINOR__=%u", minor); + } } diff --git a/gcc/config/nvptx/nvptx-protos.h b/gcc/config/nvptx/nvptx-protos.h index ca0a87ee4bd..dfa08ec8319 100644 --- a/gcc/config/nvptx/nvptx-protos.h +++ b/gcc/config/nvptx/nvptx-protos.h @@ -44,6 +44,7 @@ extern void nvptx_cpu_cpp_builtins (void); extern void nvptx_register_pragmas (void); extern unsigned int nvptx_data_alignment (const_tree, unsigned int); extern void nvptx_asm_output_def_from_decls (FILE *, tree, tree); +extern unsigned int ptx_version_to_number (enum ptx_version, bool); #ifdef RTX_CODE extern void nvptx_expand_oacc_fork (unsigned); diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc index 87efc23bd96..e4297e2d6c3 100644 --- a/gcc/config/nvptx/nvptx.cc +++ b/gcc/config/nvptx/nvptx.cc @@ -272,6 +272,28 @@ ptx_version_to_string (enum ptx_version v) } } +unsigned int +ptx_version_to_number (enum ptx_version v, bool major_p) +{ + switch (v) + { + case PTX_VERSION_3_0: + return major_p ? 3 : 0; + case PTX_VERSION_3_1: + return major_p ? 3 : 1; + case PTX_VERSION_4_2: + return major_p ? 4 : 2; + case PTX_VERSION_6_0: + return major_p ? 6 : 0; + case PTX_VERSION_6_3: + return major_p ? 6 : 3; + case PTX_VERSION_7_0: + return major_p ? 7 : 0; + default: + gcc_unreachable (); + } +} + static const char * sm_version_to_string (enum ptx_isa sm) { diff --git a/gcc/testsuite/gcc.target/nvptx/ptx31.c b/gcc/testsuite/gcc.target/nvptx/ptx31.c new file mode 100644 index 00000000000..46b5e1ba405 --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/ptx31.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-march=sm_30 -mptx=3.1" } */ + +#if __PTX_ISA_VERSION_MAJOR__ != 3 +#error wrong value for __PTX_ISA_VERSION_MAJOR__ +#endif + +#if __PTX_ISA_VERSION_MINOR__ != 1 +#error wrong value for __PTX_ISA_VERSION_MINOR__ +#endif diff --git a/gcc/testsuite/gcc.target/nvptx/ptx60.c b/gcc/testsuite/gcc.target/nvptx/ptx60.c new file mode 100644 index 00000000000..267a9c64f1e --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/ptx60.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-march=sm_30 -mptx=6.0" } */ + +#if __PTX_ISA_VERSION_MAJOR__ != 6 +#error wrong value for __PTX_ISA_VERSION_MAJOR__ +#endif + +#if __PTX_ISA_VERSION_MINOR__ != 0 +#error wrong value for __PTX_ISA_VERSION_MINOR__ +#endif diff --git a/gcc/testsuite/gcc.target/nvptx/ptx63.c b/gcc/testsuite/gcc.target/nvptx/ptx63.c new file mode 100644 index 00000000000..13d02e132ae --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/ptx63.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-march=sm_30 -mptx=6.3" } */ + +#if __PTX_ISA_VERSION_MAJOR__ != 6 +#error wrong value for __PTX_ISA_VERSION_MAJOR__ +#endif + +#if __PTX_ISA_VERSION_MINOR__ != 3 +#error wrong value for __PTX_ISA_VERSION_MINOR__ +#endif diff --git a/gcc/testsuite/gcc.target/nvptx/ptx70.c b/gcc/testsuite/gcc.target/nvptx/ptx70.c new file mode 100644 index 00000000000..15df13604bd --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/ptx70.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-march=sm_30 -mptx=7.0" } */ + +#if __PTX_ISA_VERSION_MAJOR__ != 7 +#error wrong value for __PTX_ISA_VERSION_MAJOR__ +#endif + +#if __PTX_ISA_VERSION_MINOR__ != 0 +#error wrong value for __PTX_ISA_VERSION_MINOR__ +#endif
reply other threads:[~2022-03-29 14:17 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220329141701.B5B493858C50@sourceware.org \ --to=vries@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).