diff --git a/gcc/config/nvptx/nvptx-c.cc b/gcc/config/nvptx/nvptx-c.cc index 02f756250646e7ea4ca3d5e1f53d4cc106bd779c..f060a8ab1d411a4ed6397206a46c11c7a425386b 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 ca0a87ee4bd68a4e2928cd0d49d2a02f37aa2e60..dfa08ec83190d202feab37c7b041dbad18229d0f 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 87efc23bd96a5a9c3d9476c528ae1d3ed76b81a2..e4297e2d6c33645809576997cfe28aeffea5cd8a 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 0000000000000000000000000000000000000000..46b5e1ba4054f0f4759459fe09a52156012a9c96 --- /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 0000000000000000000000000000000000000000..267a9c64f1e93fb7e3777fd69ffd00069bd34c06 --- /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 0000000000000000000000000000000000000000..13d02e132aea41eeb301681609d34f5b68c6fbe5 --- /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 0000000000000000000000000000000000000000..15df13604bd65dc34542240bb6752bf4f9428215 --- /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