This is a follow-up to a series posted in August:
https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692734.html
This version fixes comments from Jason to eliminate the need for looking up
boolean vector type and just reuses one of the types when building binary op
trees in the front end.
This patch series implements C/C++ operators on SVE's svbool_t ACLE type.
Following is a spec
that describes the semantics when operators are applied to svbool_t.
svbool_t is an SVE ACLE type that is a vector of non-standard booleans.
svbool_t[i] is a boolean type.
Initialization:
svbool_t pg = {c0, c1, c2, ..., cn}; // ci is either a compile-time constant
or a runtime expression.
This is equivalent to
pg[0] = c0;
pg[1] = c1;
..
pg[n] = cn;
etc.
This is similar to writing:
_Bool p[4] = {1, 4.2, 0, ..., 'a'};
Eg.
svbool_t pg = {1, 4.2, 0, ..., 'a'};
will be translated to:
pg[0] = 1;
pg[1] = 1;
pg[2] = 0;
...
pg[n] = 1;
IoW, ci implicitly converts to boolean.
For SVE sizeless types, num of elements in the initializer cannot exceed
minimum vector length (16bits).
Bitwise ops: &, |, ~, ^
svbool_t = svbool_t <op> svbool_t
svbool_t = svbool_t <op> c // c is a scalar
svbool_t temp = {c, c, ..., c}
svbool_t = svbool_t <op> temp
Logical Ops: ==, !=
The result of a logical operation between 2 svbool_t is another vector svbool_t
i.e.
svbool_t = svbool_t <op> svbool_t
svbool_t <op> scalar eg. svbool_t != <constant> is equiv to:
_Bool temp1 = <constant> != 0 // Compile-time constant.
_Bool temp2 = temp1
svbool_t temp3 = {temp2, temp2, ... }
svbool_t = svbool_t <op> temp3
Ternary op:
svbool_t_expr ? svbool_t : svbool_t;
c ? svbool_t : svbool_t; // c is a scalar
The operation is similar to the GNU vector ternary op:
res = {svbool_t[0] != 0 ? v1[0] : v2[0], svbool_t[1] != 0 ? v1[1] : v2[1], ..}
svbool_t_expr ? t1 : t2; // Here, even if t1, t2 and svbool_t_expr have the
same
number of elements, it will be diagnosed as error if t1 and t2 sizes are
different
from svbool_t.
Conditional ops:
Result of svbool_t conditional ops is a vector of type svbool_t just like in the
case of a GNU vector.
!svbool_t is equivalent to
svbool_t == 0
svbool_t && svbool_t is equivalent to:
svbool_t != 0 & svbool_t != 0
svbool_t || svbool_t is equiv to:
svbool_t != 0 | svbool_t != 0
Address-of: & on svbool_t[i] is not allowed.
sizeof(): sizeof (svbool_t[i]) is precision / 8 + 1
Tejas Belagod (3):
AArch64: Support C/C++ operations on svbool_t
AArch64: Update existing test with svbool_t operations
AArch64: Update test to reflect new message
gcc/c-family/c-common.cc | 4 +-
gcc/c/c-typeck.cc | 25 +-
gcc/config/aarch64/aarch64-sve-builtins.cc | 5 +-
gcc/config/aarch64/aarch64-sve.md | 62 ++++
gcc/config/aarch64/aarch64.cc | 94 +++++-
gcc/cp/call.cc | 3 +-
gcc/cp/cvt.cc | 11 +-
gcc/cp/typeck.cc | 26 +-
gcc/testsuite/g++.dg/ext/sve-sizeless-1.C | 10 +
gcc/testsuite/g++.dg/ext/sve-sizeless-2.C | 21 ++
.../sve/acle/general-c++/gnu_vectors_1.C | 133 +++++++-
.../sve/acle/general-c++/gnu_vectors_2.C | 133 +++++++-
.../sve/acle/general-c/gnu_vectors_1.c | 128 +++++++-
.../sve/acle/general-c/gnu_vectors_2.c | 128 +++++++-
.../aarch64/sve/acle/general-c/sizeless-1.c | 14 +-
.../aarch64/sve/acle/general-c/sizeless-2.c | 32 ++
.../aarch64/sve/acle/general-c/svcount_1.c | 2 +-
.../aarch64/sve/acle/general/cops_bool.c | 301 ++++++++++++++++++
18 files changed, 1088 insertions(+), 44 deletions(-)
create mode 100644
gcc/testsuite/gcc.target/aarch64/sve/acle/general/cops_bool.c
--
2.34.1