Skip to content

Commit e38566a

Browse files
author
Christophe Lyon
committed
arm: [MVE intrinsics] add viddup shape
This patch adds the viddup shape description for vidup and vddup. This requires the addition of report_not_one_of and function_checker::require_immediate_one_of to gcc/config/arm/arm-mve-builtins.cc (they are copies of the aarch64 SVE counterpart). This patch also introduces MODE_wb. 2024-08-21 Christophe Lyon <christophe.lyon@linaro.org> gcc/ * config/arm/arm-mve-builtins-shapes.cc (viddup): New. * config/arm/arm-mve-builtins-shapes.h (viddup): New. * config/arm/arm-mve-builtins.cc (report_not_one_of): New. (function_checker::require_immediate_one_of): New. * config/arm/arm-mve-builtins.def (wb): New mode. * config/arm/arm-mve-builtins.h (function_checker) Add require_immediate_one_of.
1 parent 387b121 commit e38566a

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

gcc/config/arm/arm-mve-builtins-shapes.cc

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,91 @@ struct vcvtx_def : public overloaded_base<0>
21912191
};
21922192
SHAPE (vcvtx)
21932193

2194+
/* <T0>_t vfoo[_n]_t0(uint32_t, const int)
2195+
<T0>_t vfoo[_wb]_t0(uint32_t *, const int)
2196+
2197+
Shape for vector increment or decrement and duplicate operations that take
2198+
an integer or pointer to integer first argument and an immediate, and
2199+
produce a vector.
2200+
2201+
Check that 'imm' is one of 1, 2, 4 or 8.
2202+
2203+
Example: vddupq.
2204+
uint8x16_t [__arm_]vddupq[_n]_u8(uint32_t a, const int imm)
2205+
uint8x16_t [__arm_]vddupq[_wb]_u8(uint32_t *a, const int imm)
2206+
uint8x16_t [__arm_]vddupq_m[_n_u8](uint8x16_t inactive, uint32_t a, const int imm, mve_pred16_t p)
2207+
uint8x16_t [__arm_]vddupq_m[_wb_u8](uint8x16_t inactive, uint32_t *a, const int imm, mve_pred16_t p)
2208+
uint8x16_t [__arm_]vddupq_x[_n]_u8(uint32_t a, const int imm, mve_pred16_t p)
2209+
uint8x16_t [__arm_]vddupq_x[_wb]_u8(uint32_t *a, const int imm, mve_pred16_t p) */
2210+
struct viddup_def : public overloaded_base<0>
2211+
{
2212+
bool
2213+
explicit_type_suffix_p (unsigned int i, enum predication_index pred,
2214+
enum mode_suffix_index,
2215+
type_suffix_info) const override
2216+
{
2217+
return ((i == 0) && (pred != PRED_m));
2218+
}
2219+
2220+
bool
2221+
skip_overload_p (enum predication_index, enum mode_suffix_index mode) const override
2222+
{
2223+
/* For MODE_wb, share the overloaded instance with MODE_n. */
2224+
if (mode == MODE_wb)
2225+
return true;
2226+
2227+
return false;
2228+
}
2229+
2230+
void
2231+
build (function_builder &b, const function_group_info &group,
2232+
bool preserve_user_namespace) const override
2233+
{
2234+
b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
2235+
build_all (b, "v0,su32,su64", group, MODE_n, preserve_user_namespace);
2236+
build_all (b, "v0,as,su64", group, MODE_wb, preserve_user_namespace);
2237+
}
2238+
2239+
tree
2240+
resolve (function_resolver &r) const override
2241+
{
2242+
unsigned int i, nargs;
2243+
type_suffix_index type_suffix = NUM_TYPE_SUFFIXES;
2244+
if (!r.check_gp_argument (2, i, nargs))
2245+
return error_mark_node;
2246+
2247+
type_suffix = r.type_suffix_ids[0];
2248+
/* With PRED_m, ther is no type suffix, so infer it from the first (inactive)
2249+
argument. */
2250+
if (type_suffix == NUM_TYPE_SUFFIXES)
2251+
type_suffix = r.infer_vector_type (0);
2252+
2253+
unsigned int last_arg = i - 1;
2254+
/* Check that last_arg is either scalar or pointer. */
2255+
if (!r.scalar_argument_p (last_arg))
2256+
return error_mark_node;
2257+
2258+
if (!r.require_integer_immediate (last_arg + 1))
2259+
return error_mark_node;
2260+
2261+
/* With MODE_n we expect a scalar, with MODE_wb we expect a pointer. */
2262+
mode_suffix_index mode_suffix;
2263+
if (POINTER_TYPE_P (r.get_argument_type (last_arg)))
2264+
mode_suffix = MODE_wb;
2265+
else
2266+
mode_suffix = MODE_n;
2267+
2268+
return r.resolve_to (mode_suffix, type_suffix);
2269+
}
2270+
2271+
bool
2272+
check (function_checker &c) const override
2273+
{
2274+
return c.require_immediate_one_of (1, 1, 2, 4, 8);
2275+
}
2276+
};
2277+
SHAPE (viddup)
2278+
21942279
/* <T0>_t vfoo[_t0](<T0>_t, <T0>_t, mve_pred16_t)
21952280
21962281
i.e. a version of the standard ternary shape in which

gcc/config/arm/arm-mve-builtins-shapes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ namespace arm_mve
8282
extern const function_shape *const vcvt_f16_f32;
8383
extern const function_shape *const vcvt_f32_f16;
8484
extern const function_shape *const vcvtx;
85+
extern const function_shape *const viddup;
8586
extern const function_shape *const vpsel;
8687

8788
} /* end namespace arm_mve::shapes */

gcc/config/arm/arm-mve-builtins.cc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,20 @@ report_not_enum (location_t location, tree fndecl, unsigned int argno,
630630
" a valid %qT value", actual, argno + 1, fndecl, enumtype);
631631
}
632632

633+
/* Report that LOCATION has a call to FNDECL in which argument ARGNO has
634+
the value ACTUAL, whereas the function requires one of VALUE0..3.
635+
ARGNO counts from zero. */
636+
static void
637+
report_not_one_of (location_t location, tree fndecl, unsigned int argno,
638+
HOST_WIDE_INT actual, HOST_WIDE_INT value0,
639+
HOST_WIDE_INT value1, HOST_WIDE_INT value2,
640+
HOST_WIDE_INT value3)
641+
{
642+
error_at (location, "passing %wd to argument %d of %qE, which expects"
643+
" %wd, %wd, %wd or %wd", actual, argno + 1, fndecl, value0, value1,
644+
value2, value3);
645+
}
646+
633647
/* Checks that the mve.fp extension is enabled, given that REQUIRES_FLOAT
634648
indicates whether it is required or not for function FNDECL.
635649
Report an error against LOCATION if not. */
@@ -1969,6 +1983,36 @@ function_checker::require_immediate_enum (unsigned int rel_argno, tree type)
19691983
return false;
19701984
}
19711985

1986+
/* Check that argument REL_ARGNO is an integer constant expression that
1987+
has one of the given values. */
1988+
bool
1989+
function_checker::require_immediate_one_of (unsigned int rel_argno,
1990+
HOST_WIDE_INT value0,
1991+
HOST_WIDE_INT value1,
1992+
HOST_WIDE_INT value2,
1993+
HOST_WIDE_INT value3)
1994+
{
1995+
unsigned int argno = m_base_arg + rel_argno;
1996+
if (!argument_exists_p (argno))
1997+
return true;
1998+
1999+
HOST_WIDE_INT actual;
2000+
if (!require_immediate (argno, actual))
2001+
return false;
2002+
2003+
if (actual != value0
2004+
&& actual != value1
2005+
&& actual != value2
2006+
&& actual != value3)
2007+
{
2008+
report_not_one_of (location, fndecl, argno, actual,
2009+
value0, value1, value2, value3);
2010+
return false;
2011+
}
2012+
2013+
return true;
2014+
}
2015+
19722016
/* Check that argument REL_ARGNO is an integer constant expression in the
19732017
range [MIN, MAX]. REL_ARGNO counts from the end of the predication
19742018
arguments. */

gcc/config/arm/arm-mve-builtins.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
DEF_MVE_MODE (n, none, none, none)
3737
DEF_MVE_MODE (offset, none, none, bytes)
3838
DEF_MVE_MODE (r, none, none, none)
39+
DEF_MVE_MODE (wb, none, none, none)
3940

4041
#define REQUIRES_FLOAT false
4142
DEF_MVE_TYPE (mve_pred16_t, boolean_type_node)

gcc/config/arm/arm-mve-builtins.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ class function_checker : public function_call_info
433433

434434
bool require_immediate_enum (unsigned int, tree);
435435
bool require_immediate_lane_index (unsigned int, unsigned int = 1);
436+
bool require_immediate_one_of (unsigned int, HOST_WIDE_INT, HOST_WIDE_INT,
437+
HOST_WIDE_INT, HOST_WIDE_INT);
436438
bool require_immediate_range (unsigned int, HOST_WIDE_INT, HOST_WIDE_INT);
437439

438440
bool check ();

0 commit comments

Comments
 (0)