Skip to content

Commit

Permalink
RISC-V: Define __riscv_v_intrinsic [PR109312]
Browse files Browse the repository at this point in the history
RVV intrinsic has defined a macro to identity the version of RVV
intrinsic spec, we missed that before, thanksful we are catch this
before release.

gcc/ChangeLog:

	PR target/109312
	* config/riscv/riscv-c.cc (riscv_ext_version_value): New.
	(riscv_cpu_cpp_builtins): Define __riscv_v_intrinsic and
	minor refactor.

gcc/testsuite/ChangeLog:

	PR target/109312
	* gcc.target/riscv/predef-__riscv_v_intrinsic.c: New test.
  • Loading branch information
kito-cheng committed Mar 28, 2023
1 parent 97383b4 commit 5a92351
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 14 additions & 4 deletions gcc/config/riscv/riscv-c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ along with GCC; see the file COPYING3. If not see

#define builtin_define(TXT) cpp_define (pfile, TXT)

static int
riscv_ext_version_value (unsigned major, unsigned minor)
{
return (major * 1000000) + (minor * 1000);
}

/* Implement TARGET_CPU_CPP_BUILTINS. */

void
Expand Down Expand Up @@ -118,7 +124,11 @@ riscv_cpu_cpp_builtins (cpp_reader *pfile)
builtin_define_with_int_value ("__riscv_v_elen_fp", 0);

if (TARGET_MIN_VLEN)
builtin_define ("__riscv_vector");
{
builtin_define ("__riscv_vector");
builtin_define_with_int_value ("__riscv_v_intrinsic",
riscv_ext_version_value (0, 11));
}

/* Define architecture extension test macros. */
builtin_define_with_int_value ("__riscv_arch_test", 1);
Expand All @@ -141,13 +151,13 @@ riscv_cpu_cpp_builtins (cpp_reader *pfile)
subset != subset_list->end ();
subset = subset->next)
{
int version_value = (subset->major_version * 1000000)
+ (subset->minor_version * 1000);
int version_value = riscv_ext_version_value (subset->major_version,
subset->minor_version);
/* Special rule for zicsr and zifencei, it's used for ISA spec 2.2 or
earlier. */
if ((subset->name == "zicsr" || subset->name == "zifencei")
&& version_value == 0)
version_value = 2000000;
version_value = riscv_ext_version_value (2, 0);

sprintf (buf, "__riscv_%s", subset->name.c_str ());
builtin_define_with_int_value (buf, version_value);
Expand Down
11 changes: 11 additions & 0 deletions gcc/testsuite/gcc.target/riscv/predef-__riscv_v_intrinsic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* { dg-do compile } */
/* { dg-options "-march=rv64imafdcv -mabi=lp64d" } */

int main () {

#if __riscv_v_intrinsic != 11000
#error "__riscv_v_intrinsic"
#endif

return 0;
}

0 comments on commit 5a92351

Please sign in to comment.