mbox series

[00/10] aarch64: Enable C/C++ operations on SVE ACLE types.

Message ID 20241106114613.2972987-1-tejas.belagod@arm.com
Headers show
Series aarch64: Enable C/C++ operations on SVE ACLE types. | expand

Message

Tejas Belagod Nov. 6, 2024, 11:46 a.m. UTC
Hi,

This patchset enables C/C++ operations on SVE ACLE types.  The changes enable
operations on SVE ACLE types to have the same semantics as GNU vector types.
These operations like (+, -, &, | etc) behave exactly as they would behave on
GNU vector types. The operations are self-contained as in we still don't allow
mixing GNU and SVE vector types in, for eg, binary operations because the 
typeof the expression is ambiguous and this causes PCS issues.

Other operations like implicit conversions behave as they would with GNU
vectors i.e.

gnu_uv = sv_uv; // This is possible as long as the size, shape and element-
                // signedness of both vectors are the same.
gnu_uv = sv_sv; // Error as implicit conversion from signed to unsigned is not
                // possible even though size and shape may be similar.

Such assignments would have to go through an explicit cast

gnu_uv = (gnu_uv)sv_sv;

Following unary operations are supported:
  
  sve_type_var[0];
  &sve_type_var[0];
  sve_type_var[n];
  &sve_type_var[n];
  +sve_type_var;
  -sve_type_var;
  ~sve_type_var;
  !sve_type_var; /* Allowed in C++ */
  *sve_type_var; /* Error! */
  __real sve_type_var; /* Error! */
  __imag sve_type_var; /* Error! */
  ++sve_type_var;
  --sve_type_var;
  sve_type_var++;
  sve_type_var--;

Following binary ops are supported:

  sve_type_var + sve_type_var;
  sve_type_var - sve_type_var;
  sve_type_var * sve_type_var;
  sve_type_var / sve_type_var;
  sve_type_var % sve_type_var;
  sve_type_var & sve_type_var;
  sve_type_var | sve_type_var;
  sve_type_var ^ sve_type_var;
  sve_type_var == sve_type_var;
  sve_type_var != sve_type_var;
  sve_type_var <= sve_type_var;
  sve_type_var < sve_type_var;
  sve_type_var > sve_type_var;
  sve_type_var >= sve_type_var;
  sve_type_var << sve_type_var;
  sve_type_var >> sve_type_var;
  sve_type_var && sve_type_var; /* Allowed in C++ */
  sve_type_var || sve_type_var; /* Allowed in C++ */

/* Vector-scalar binary arithmetic. The reverse is also supported
   eg. <const_scalar> + sve_type_var  */  

  sve_type_var + <const_scalar>;
  sve_type_var - <const_scalar>;
  sve_type_var * <const_scalar>;
  sve_type_var / <const_scalar>;
  sve_type_var % <const_scalar>;
  sve_type_var & <const_scalar>;
  sve_type_var | <const_scalar>;
  sve_type_var ^ <const_scalar>;
  sve_type_var == <const_scalar>;
  sve_type_var != <const_scalar>;
  sve_type_var <= <const_scalar>;
  sve_type_var < <const_scalar>;
  sve_type_var > <const_scalar>;
  sve_type_var >= <const_scalar>;
  sve_type_var << <const_scalar>;
  sve_type_var >> <const_scalar>;
  sve_type_var && <const_scalar>; /* Allowed in C++ */
  sve_type_var || <const_scalar>; /* Allowed in C++ */
  sve_type_var + <var_scalar>;
  sve_type_var - <var_scalar>;
  sve_type_var * <var_scalar>;
  sve_type_var / <var_scalar>;
  sve_type_var % <var_scalar>;
  sve_type_var & <var_scalar>;
  sve_type_var | <var_scalar>;
  sve_type_var ^ <var_scalar>;
  sve_type_var == <var_scalar>;
  sve_type_var != <var_scalar>;
  sve_type_var <= <var_scalar>;
  sve_type_var < <var_scalar>;
  sve_type_var > <var_scalar>;
  sve_type_var >= <var_scalar>;
  sve_type_var << <var_scalar>;
  sve_type_var >> <var_scalar>;
  sve_type_var && <var_scalar>; /* Allowed in C++ */
  sve_type_var || <var_scalar>; /* Allowed in C++ */

Ternary operations:

  <scalar> ? sve_type_var : sve_type_var;

  sve_type_var ? sve_type_var : sve_type_var; /* Allowed in C++ */

Builtins:

  /* Vector built-ins.  */

  __builtin_shuffle (sve_type_var, sve_type_var, sve_type_var);
  __builtin_convertvector (sve_type_var, <sve_type>);

These operations are supported for both fixed length and variable length
vectors.

There is one feature yet to be supported:
* Constructors with variable (non-constant) elements are currently not
  supported for VLA vectors - it is WIP.

One outstanding fail
PASS->FAIL: g++.dg/ext/sve-sizeless-1.C  -std=gnu++11  (test for errors, line 163)

I've left another outstanding fail as is - the test where an address is taken
of an SVE vector element. I'm not sure what the behaviour should be here.

Otherwise regression tested and bootstrapped on aarch64-linux-gnu.
Bootstrapped on x86-linux-gnu.

OK for trunk?

Thanks,
Tejas.

Tejas Belagod (10):
  aarch64: Fix ACLE macro __ARM_FEATURE_SVE_VECTOR_OPERATORS
  aarch64: Make C/C++ operations possible on SVE ACLE types.
  c: Range-check indexing of SVE ACLE vectors
  gimple: Disallow sizeless types in BIT_FIELD_REFs.
  c: Fix an assumption that vectors sizes are known at compile-time.
  rtl: Validate subreg info when optimizing vec_select.
  aarch64: Add testcase for C/C++ ops on SVE ACLE types.
  aarch64: Update SVE ACLE tests
  c: Fix bounds checking for VLA and construct VLA vector constants
  cp: Fix another assumption in the FE about constant vector indices.

 gcc/c-family/c-common.cc                      |  10 +-
 gcc/c/c-typeck.cc                             |  16 +-
 gcc/config/aarch64/aarch64-c.cc               |  10 +-
 gcc/config/aarch64/aarch64-sve-builtins.cc    |   5 +-
 gcc/cp/decl.cc                                |  11 +-
 gcc/gimple-fold.cc                            |   3 +-
 gcc/rtlanal.cc                                |   1 +
 gcc/testsuite/g++.dg/ext/sve-sizeless-1.C     |   1 +
 gcc/testsuite/g++.dg/ext/sve-sizeless-2.C     |   1 +
 .../sve/acle/general-c++/gnu_vectors_1.C      | 438 +++++++-------
 .../sve/acle/general-c++/gnu_vectors_2.C      | 434 ++++++-------
 .../sve/acle/general-c/gnu_vectors_1.c        | 349 +++++------
 .../sve/acle/general-c/gnu_vectors_2.c        | 346 +++++------
 .../aarch64/sve/acle/general-c/sizeless-1.c   |   3 +-
 .../aarch64/sve/acle/general-c/sizeless-2.c   |   3 +-
 .../aarch64/sve/acle/general/attributes_7.c   |  30 +-
 .../aarch64/sve/acle/general/cops.c           | 570 ++++++++++++++++++
 gcc/tree.cc                                   |  16 +-
 18 files changed, 1425 insertions(+), 822 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/acle/general/cops.c

Comments

Richard Sandiford Nov. 7, 2024, 11:24 a.m. UTC | #1
Tejas Belagod <tejas.belagod@arm.com> writes:
> Hi,
>
> This patchset enables C/C++ operations on SVE ACLE types.

I've replied to some of the individual patches, but otherwise the
AArch64 parts look good to me.

Thanks,
Richard