[PATCH v3] Extend the simd function attribute

Szabolcs Nagy Szabolcs.Nagy@arm.com
Thu Nov 14 20:23:00 GMT 2019


Sorry v2 had a bug.

v2: added documentation and tests.
v3: fixed expand_simd_clones so different isa variants are actually
    generated.

GCC currently supports two ways to declare the availability of vector
variants of a scalar function:

  #pragma omp declare simd
  void f (void);

and

  __attribute__ ((simd))
  void f (void);

However these declare a set of symbols that are different simd variants
of f, so a library either provides definitions for all those symbols or
it cannot use these declarations. (The set of declared symbols can be
narrowed down with additional omp clauses, but not enough to allow
declaring a single symbol. OpenMP 5 has a declare variant feature that
allows declaring more specific simd variants, but it is complicated and
still requires gcc or vendor extension for unambiguous declarations.)

This patch extends the gcc specific simd attribute such that it can
specify a single vector variant of simple scalar functions (functions
that only take and return scalar integer or floating type values):

  __attribute__ ((simd (mask, simdlen, simdabi, name))))

where mask is "inbranch" or "notinbranch" like now, simdlen is an int
with the same meaning as in omp declare simd and simdabi is a string
specifying the call ABI (which the intel vector ABI calls ISA). The
name is optional and allows a library to use a different symbol name
than what the vector ABI specifies.

The simd attribute currently can be used for both declarations and
definitions, in the latter case the simd varaints of the function are
generated, which should work with the extended simd attribute too.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.

gcc/ChangeLog:

2019-11-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* cgraph.h (struct cgraph_simd_clone): Add simdname field.
	* doc/extend.texi: Update the simd attribute documentation.
	* tree.h (OMP_CLAUSE__SIMDABI__EXPR): Define.
	(OMP_CLAUSE__SIMDNAME__EXPR): Define.
	* tree.c (walk_tree_1): Handle new omp clauses.
	* tree-core.h (enum omp_clause_code): Likewise.
	* tree-nested.c (convert_nonlocal_omp_clauses): Likewise.
	* tree-pretty-print.c (dump_omp_clause): Likewise.
	* omp-low.c (scan_sharing_clauses): Likewise.
	* omp-simd-clone.c (simd_clone_clauses_extract): Likewise.
	(simd_clone_mangle): Handle simdname.
	(expand_simd_clones): Reset vecsize_mangle when generating clones.
	* config/aarch64/aarch64.c
	(aarch64_simd_clone_compute_vecsize_and_simdlen): Warn about
	unsupported SIMD ABI.
	* config/i386/i386.c
	(ix86_simd_clone_compute_vecsize_and_simdlen): Likewise.

gcc/c-family/ChangeLog:

2019-11-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* c-attribs.c (handle_simd_attribute): Handle 4 arguments.

gcc/testsuite/ChangeLog:

2019-11-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* c-c++-common/attr-simd-5.c: Update.
	* c-c++-common/attr-simd-6.c: New test.
	* c-c++-common/attr-simd-7.c: New test.
	* c-c++-common/attr-simd-8.c: New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simd.diff
Type: text/x-patch
Size: 18396 bytes
Desc: simd.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20191114/8d124259/attachment.bin>


More information about the Gcc-patches mailing list