Skip to content

Commit d486800

Browse files
committed
RISC-V: fold duplicate code in vector_macro()
There's no need to have almost identical code twice. Do away with M_VMSGEU and instead simply use an unused (for these macros) field to tell apart both variants.
1 parent 404def8 commit d486800

File tree

3 files changed

+7
-43
lines changed

3 files changed

+7
-43
lines changed

gas/config/tc-riscv.c

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,7 @@ vector_macro (struct riscv_cl_insn *ip)
19581958
int vs2 = (ip->insn_opcode >> OP_SH_VS2) & OP_MASK_VS2;
19591959
int vm = (ip->insn_opcode >> OP_SH_VMASK) & OP_MASK_VMASK;
19601960
int vtemp = (ip->insn_opcode >> OP_SH_VFUNCT6) & OP_MASK_VFUNCT6;
1961+
const char *vmslt_vx = ip->insn_mo->match ? "vmsltu.vx" : "vmslt.vx";
19611962
int mask = ip->insn_mo->mask;
19621963

19631964
switch (mask)
@@ -1966,7 +1967,7 @@ vector_macro (struct riscv_cl_insn *ip)
19661967
if (vm)
19671968
{
19681969
/* Unmasked. */
1969-
macro_build (NULL, "vmslt.vx", "Vd,Vt,sVm", vd, vs2, vs1, -1);
1970+
macro_build (NULL, vmslt_vx, "Vd,Vt,sVm", vd, vs2, vs1, -1);
19701971
macro_build (NULL, "vmnand.mm", "Vd,Vt,Vs", vd, vd, vd);
19711972
break;
19721973
}
@@ -1975,13 +1976,13 @@ vector_macro (struct riscv_cl_insn *ip)
19751976
/* Masked. Have vtemp to avoid overlap constraints. */
19761977
if (vd == vm)
19771978
{
1978-
macro_build (NULL, "vmslt.vx", "Vd,Vt,sVm", vtemp, vs2, vs1, -1);
1979+
macro_build (NULL, vmslt_vx, "Vd,Vt,sVm", vtemp, vs2, vs1, -1);
19791980
macro_build (NULL, "vmandnot.mm", "Vd,Vt,Vs", vd, vm, vtemp);
19801981
}
19811982
else
19821983
{
19831984
/* Preserve the value of vd if not updating by vm. */
1984-
macro_build (NULL, "vmslt.vx", "Vd,Vt,sVm", vtemp, vs2, vs1, -1);
1985+
macro_build (NULL, vmslt_vx, "Vd,Vt,sVm", vtemp, vs2, vs1, -1);
19851986
macro_build (NULL, "vmandnot.mm", "Vd,Vt,Vs", vtemp, vm, vtemp);
19861987
macro_build (NULL, "vmandnot.mm", "Vd,Vt,Vs", vd, vd, vm);
19871988
macro_build (NULL, "vmor.mm", "Vd,Vt,Vs", vd, vtemp, vd);
@@ -1990,42 +1991,7 @@ vector_macro (struct riscv_cl_insn *ip)
19901991
else if (vd != vm)
19911992
{
19921993
/* Masked. This may cause the vd overlaps vs2, when LMUL > 1. */
1993-
macro_build (NULL, "vmslt.vx", "Vd,Vt,sVm", vd, vs2, vs1, vm);
1994-
macro_build (NULL, "vmxor.mm", "Vd,Vt,Vs", vd, vd, vm);
1995-
}
1996-
else
1997-
as_bad (_("must provide temp if destination overlaps mask"));
1998-
break;
1999-
2000-
case M_VMSGEU:
2001-
if (vm)
2002-
{
2003-
/* Unmasked. */
2004-
macro_build (NULL, "vmsltu.vx", "Vd,Vt,sVm", vd, vs2, vs1, -1);
2005-
macro_build (NULL, "vmnand.mm", "Vd,Vt,Vs", vd, vd, vd);
2006-
break;
2007-
}
2008-
if (vtemp != 0)
2009-
{
2010-
/* Masked. Have vtemp to avoid overlap constraints. */
2011-
if (vd == vm)
2012-
{
2013-
macro_build (NULL, "vmsltu.vx", "Vd,Vt,sVm", vtemp, vs2, vs1, -1);
2014-
macro_build (NULL, "vmandnot.mm", "Vd,Vt,Vs", vd, vm, vtemp);
2015-
}
2016-
else
2017-
{
2018-
/* Preserve the value of vd if not updating by vm. */
2019-
macro_build (NULL, "vmsltu.vx", "Vd,Vt,sVm", vtemp, vs2, vs1, -1);
2020-
macro_build (NULL, "vmandnot.mm", "Vd,Vt,Vs", vtemp, vm, vtemp);
2021-
macro_build (NULL, "vmandnot.mm", "Vd,Vt,Vs", vd, vd, vm);
2022-
macro_build (NULL, "vmor.mm", "Vd,Vt,Vs", vd, vtemp, vd);
2023-
}
2024-
}
2025-
else if (vd != vm)
2026-
{
2027-
/* Masked. This may cause the vd overlaps vs2, when LMUL > 1. */
2028-
macro_build (NULL, "vmsltu.vx", "Vd,Vt,sVm", vd, vs2, vs1, vm);
1994+
macro_build (NULL, vmslt_vx, "Vd,Vt,sVm", vd, vs2, vs1, vm);
20291995
macro_build (NULL, "vmxor.mm", "Vd,Vt,Vs", vd, vd, vm);
20301996
}
20311997
else
@@ -2180,7 +2146,6 @@ macro (struct riscv_cl_insn *ip, expressionS *imm_expr,
21802146
break;
21812147

21822148
case M_VMSGE:
2183-
case M_VMSGEU:
21842149
vector_macro (ip);
21852150
break;
21862151

include/opcode/riscv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ enum
563563
M_SEXTB,
564564
M_SEXTH,
565565
M_VMSGE,
566-
M_VMSGEU,
567566
M_FLH,
568567
M_FSH,
569568
M_NUM_MACROS

opcodes/riscv-opc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,8 +1620,8 @@ const struct riscv_opcode riscv_opcodes[] =
16201620

16211621
{"vmsge.vx", 0, INSN_CLASS_V, "Vd,Vt,sVm", 0, (int) M_VMSGE, match_never, INSN_MACRO },
16221622
{"vmsge.vx", 0, INSN_CLASS_V, "Vd,Vt,s,VM,VT", 0, (int) M_VMSGE, match_never, INSN_MACRO },
1623-
{"vmsgeu.vx", 0, INSN_CLASS_V, "Vd,Vt,sVm", 0, (int) M_VMSGEU, match_never, INSN_MACRO },
1624-
{"vmsgeu.vx", 0, INSN_CLASS_V, "Vd,Vt,s,VM,VT", 0, (int) M_VMSGEU, match_never, INSN_MACRO },
1623+
{"vmsgeu.vx", 0, INSN_CLASS_V, "Vd,Vt,sVm", 1, (int) M_VMSGE, match_never, INSN_MACRO },
1624+
{"vmsgeu.vx", 0, INSN_CLASS_V, "Vd,Vt,s,VM,VT", 1, (int) M_VMSGE, match_never, INSN_MACRO },
16251625

16261626
{"vminu.vv", 0, INSN_CLASS_V, "Vd,Vt,VsVm", MATCH_VMINUVV, MASK_VMINUVV, match_opcode, 0},
16271627
{"vminu.vx", 0, INSN_CLASS_V, "Vd,Vt,sVm", MATCH_VMINUVX, MASK_VMINUVX, match_opcode, 0},

0 commit comments

Comments
 (0)