* [PATCH v1 2/2] LoongArch: Optimize vector constant extract-{even/odd} permutation.
@ 2023-11-28 7:39 Li Wei
2023-11-29 9:44 ` Xi Ruoyao
0 siblings, 1 reply; 3+ messages in thread
From: Li Wei @ 2023-11-28 7:39 UTC (permalink / raw)
To: gcc-patches; +Cc: xry111, i, xuchenghua, chenglulu, Li Wei
For vector constant extract-{even/odd} permutation replace the default
[x]vshuf instruction combination with [x]vilv{l/h} instruction, which
can reduce instructions and improves performance.
gcc/ChangeLog:
* config/loongarch/loongarch.cc (loongarch_is_odd_extraction):
Supplementary function prototype.
(loongarch_is_even_extraction): Adjust.
(loongarch_try_expand_lsx_vshuf_const): Adjust.
(loongarch_is_extraction_permutation): Adjust.
(loongarch_expand_vec_perm_const_2): Adjust.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/lasx-extract-even_odd-opt.c: New test.
---
gcc/config/loongarch/loongarch.cc | 33 +++++++++++-
| 54 +++++++++++++++++++
2 files changed, 85 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/loongarch/lasx-extract-even_odd-opt.c
diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
index d3896d72bc2..f89c346815d 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -8672,6 +8672,12 @@ loongarch_expand_vec_perm (rtx target, rtx op0, rtx op1, rtx sel)
}
}
+static bool
+loongarch_is_odd_extraction (struct expand_vec_perm_d *);
+
+static bool
+loongarch_is_even_extraction (struct expand_vec_perm_d *);
+
static bool
loongarch_try_expand_lsx_vshuf_const (struct expand_vec_perm_d *d)
{
@@ -8694,6 +8700,24 @@ loongarch_try_expand_lsx_vshuf_const (struct expand_vec_perm_d *d)
if (d->testing_p)
return true;
+ /* If match extract-even and extract-odd permutations pattern, use
+ * vselect much better than vshuf. */
+ if (loongarch_is_odd_extraction (d)
+ || loongarch_is_even_extraction (d))
+ {
+ if (loongarch_expand_vselect_vconcat (d->target, d->op0, d->op1,
+ d->perm, d->nelt))
+ return true;
+
+ unsigned char perm2[MAX_VECT_LEN];
+ for (i = 0; i < d->nelt; ++i)
+ perm2[i] = (d->perm[i] + d->nelt) & (2 * d->nelt - 1);
+
+ if (loongarch_expand_vselect_vconcat (d->target, d->op1, d->op0,
+ perm2, d->nelt))
+ return true;
+ }
+
for (i = 0; i < d->nelt; i += 1)
{
rperm[i] = GEN_INT (d->perm[i]);
@@ -8878,7 +8902,7 @@ loongarch_is_even_extraction (struct expand_vec_perm_d *d)
result = false;
break;
}
- buf += 1;
+ buf += 2;
}
return result;
@@ -8900,7 +8924,7 @@ loongarch_is_extraction_permutation (struct expand_vec_perm_d *d)
result = false;
break;
}
- buf += 2;
+ buf += 1;
}
return result;
@@ -9377,6 +9401,11 @@ loongarch_expand_vec_perm_const_2 (struct expand_vec_perm_d *d)
Selector after: { 1, 3, 1, 3 }.
Even extraction selector sample: E_V4DImode, { 0, 2, 4, 6 }
Selector after: { 0, 2, 0, 2 }. */
+
+ /* Better implement of extract-even and extract-odd permutations. */
+ if (loongarch_expand_vec_perm_even_odd (d))
+ return true;
+
for (i = 0; i < d->nelt / 2; i += 1)
{
idx = d->perm[i];
--git a/gcc/testsuite/gcc.target/loongarch/lasx-extract-even_odd-opt.c b/gcc/testsuite/gcc.target/loongarch/lasx-extract-even_odd-opt.c
new file mode 100644
index 00000000000..515f0c8621a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/lasx-extract-even_odd-opt.c
@@ -0,0 +1,54 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -mlasx" } */
+/* { dg-final { scan-assembler "xvilvl.d" } } */
+/* { dg-final { scan-assembler "xvilvh.d" } } */
+
+#define CMUL(a, b, c) \
+ { \
+ (c).ai = (a).ai * (b).ai - (a).bi * (b).bi; \
+ (c).bi = (a).ai * (b).bi + (a).bi * (b).ai; \
+ (c).ci = (a).ci * (b).ci - (a).di * (b).di; \
+ (c).di = (a).ci * (b).di + (a).di * (b).ci; \
+ }
+#define CSUM(a, b) \
+ { \
+ (a).ai += (b).ai; \
+ (a).bi += (b).bi; \
+ (a).ci += (b).ci; \
+ (a).di += (b).di; \
+ }
+
+typedef struct
+{
+ double ai;
+ double bi;
+ double ci;
+ double di;
+} complex;
+
+typedef struct
+{
+ complex e[6][6];
+} matrix;
+
+typedef struct
+{
+ complex c[6];
+} vector;
+
+void
+mult_adj_mat_vec (matrix *a, vector *b, vector *c)
+{
+ register int i, j;
+ register complex x, y;
+ for (i = 0; i < 6; i++)
+ {
+ x.ai = x.bi = x.ci = x.di = 0.0;
+ for (j = 0; j < 6; j++)
+ {
+ CMUL (a->e[j][i], b->c[j], y);
+ CSUM (x, y);
+ }
+ c->c[i] = x;
+ }
+}
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1 2/2] LoongArch: Optimize vector constant extract-{even/odd} permutation.
2023-11-28 7:39 [PATCH v1 2/2] LoongArch: Optimize vector constant extract-{even/odd} permutation Li Wei
@ 2023-11-29 9:44 ` Xi Ruoyao
2023-12-02 8:52 ` [pushed][PATCH " chenglulu
0 siblings, 1 reply; 3+ messages in thread
From: Xi Ruoyao @ 2023-11-29 9:44 UTC (permalink / raw)
To: Li Wei, gcc-patches; +Cc: i, xuchenghua, chenglulu
On Tue, 2023-11-28 at 15:39 +0800, Li Wei wrote:
> For vector constant extract-{even/odd} permutation replace the default
> [x]vshuf instruction combination with [x]vilv{l/h} instruction, which
> can reduce instructions and improves performance.
>
> gcc/ChangeLog:
>
> * config/loongarch/loongarch.cc
> (loongarch_is_odd_extraction):
> Supplementary function prototype.
^^
These two white spaces should be removed. And I'd suggest "New forward
declaration".
Otherwise LGTM.
> (loongarch_is_even_extraction): Adjust.
> (loongarch_try_expand_lsx_vshuf_const): Adjust.
> (loongarch_is_extraction_permutation): Adjust.
> (loongarch_expand_vec_perm_const_2): Adjust.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/loongarch/lasx-extract-even_odd-opt.c: New test.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pushed][PATCH v1 2/2] LoongArch: Optimize vector constant extract-{even/odd} permutation.
2023-11-29 9:44 ` Xi Ruoyao
@ 2023-12-02 8:52 ` chenglulu
0 siblings, 0 replies; 3+ messages in thread
From: chenglulu @ 2023-12-02 8:52 UTC (permalink / raw)
To: Xi Ruoyao, Li Wei, gcc-patches; +Cc: i, xuchenghua
在 2023/11/29 下午5:44, Xi Ruoyao 写道:
> On Tue, 2023-11-28 at 15:39 +0800, Li Wei wrote:
>> For vector constant extract-{even/odd} permutation replace the default
>> [x]vshuf instruction combination with [x]vilv{l/h} instruction, which
>> can reduce instructions and improves performance.
>>
>> gcc/ChangeLog:
>>
>> * config/loongarch/loongarch.cc
>> (loongarch_is_odd_extraction):
>> Supplementary function prototype.
> ^^
> These two white spaces should be removed. And I'd suggest "New forward
> declaration".
>
> Otherwise LGTM.
pushed to r14-6073. At the same time, the indentation problem has been
modified.
Thanks.
>
>> (loongarch_is_even_extraction): Adjust.
>> (loongarch_try_expand_lsx_vshuf_const): Adjust.
>> (loongarch_is_extraction_permutation): Adjust.
>> (loongarch_expand_vec_perm_const_2): Adjust.
>>
>> gcc/testsuite/ChangeLog:
>>
>> * gcc.target/loongarch/lasx-extract-even_odd-opt.c: New test.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-02 8:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-28 7:39 [PATCH v1 2/2] LoongArch: Optimize vector constant extract-{even/odd} permutation Li Wei
2023-11-29 9:44 ` Xi Ruoyao
2023-12-02 8:52 ` [pushed][PATCH " chenglulu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).