Re: [PATCH] riscv: avoid vrgather in RVV memcmp mismatch path
Kito Cheng <[email protected]> Thu, 11 Jun 2026 22:03:25 +0800
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CA+yXCZCac+tew9++-+S8crU6s9to8iFqyYV3jxhtrXO+YeDM0A@mail.gmail.com> |
--000000000000a20d120653fad3fd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Ack, the patch seems good to me, plan to put to my test queue then push :) Pincheng Wang <[email protected]> =E6=96=BC 2026=E5=B9=B46=E6= =9C=8811=E6=97=A5=E9=80=B1=E5=9B=9B =E4=B8=8B=E5=8D=8810:01=E5=AF=AB=E9=81= =93=EF=BC=9A > Hi all, > > Gentle ping. :) > > BR, > Pincheng Wang > > On 2026/5/29 9:29, Pincheng Wang wrote: > > vfirst.m already returns the byte offset of the first mismatch in the > > current vector chunk. Use that offset to reload the two differing bytes > > with lbu instead of extracting them with vrgather.vx and vmv.x.s. > > > > The vector gather path can be more expensive on some implementations an= d > > also increases vector register pressure. This keeps the mismatch path > > shorter while preserving the memcmp result. > > > > Signed-off-by: Pincheng Wang <[email protected]> > > --- > > newlib/libc/machine/riscv/memcmp-asm.S | 10 ++++------ > > 1 file changed, 4 insertions(+), 6 deletions(-) > > > > diff --git a/newlib/libc/machine/riscv/memcmp-asm.S > b/newlib/libc/machine/riscv/memcmp-asm.S > > index b05df9521..1cf1680e2 100644 > > --- a/newlib/libc/machine/riscv/memcmp-asm.S > > +++ b/newlib/libc/machine/riscv/memcmp-asm.S > > @@ -28,12 +28,10 @@ memcmp: > > li a0, 0 > > ret > > .Lfound: > > - vrgather.vx v16, v0, a4 > > - vrgather.vx v24, v8, a4 > > - vmv.x.s a0, v16 > > - vmv.x.s a4, v24 > > - andi a0, a0, 0xff > > - andi a4, a4, 0xff > > + add a0, a0, a4 > > + add a1, a1, a4 > > + lbu a0, 0(a0) > > + lbu a4, 0(a1) > > sub a0, a0, a4 > > ret > > .size memcmp, .-memcmp > > --000000000000a20d120653fad3fd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Ack, the patch seems good to me, plan=C2=A0to put to my te= st queue then push :)</div><br><div class=3D"gmail_quote gmail_quote_contai= ner"><div dir=3D"ltr" class=3D"gmail_attr">Pincheng Wang <<a href=3D"mai= lto:[email protected]">[email protected]</a>> = =E6=96=BC 2026=E5=B9=B46=E6=9C=8811=E6=97=A5=E9=80=B1=E5=9B=9B =E4=B8=8B=E5= =8D=8810:01=E5=AF=AB=E9=81=93=EF=BC=9A<br></div><blockquote class=3D"gmail_= quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,= 204);padding-left:1ex">Hi all,<br> <br> Gentle ping. :)<br> <br> BR,<br> Pincheng Wang<br> <br> On 2026/5/29 9:29, Pincheng Wang wrote:<br> > vfirst.m already returns the byte offset of the first mismatch in the<= br> > current vector chunk. Use that offset to reload the two differing byte= s<br> > with lbu instead of extracting them with vrgather.vx and vmv.x.s.<br> > <br> > The vector gather path can be more expensive on some implementations a= nd<br> > also increases vector register pressure. This keeps the mismatch path<= br> > shorter while preserving the memcmp result.<br> > <br> > Signed-off-by: Pincheng Wang <<a href=3D"mailto:pincheng.plct@isrc.= iscas.ac.cn" target=3D"_blank">[email protected]</a>><br> > ---<br> >=C2=A0 =C2=A0newlib/libc/machine/riscv/memcmp-asm.S | 10 ++++------<br> >=C2=A0 =C2=A01 file changed, 4 insertions(+), 6 deletions(-)<br> > <br> > diff --git a/newlib/libc/machine/riscv/memcmp-asm.S b/newlib/libc/mach= ine/riscv/memcmp-asm.S<br> > index b05df9521..1cf1680e2 100644<br> > --- a/newlib/libc/machine/riscv/memcmp-asm.S<br> > +++ b/newlib/libc/machine/riscv/memcmp-asm.S<br> > @@ -28,12 +28,10 @@ memcmp:<br> >=C2=A0 =C2=A0 =C2=A0li a0, 0<br> >=C2=A0 =C2=A0 =C2=A0ret<br> >=C2=A0 =C2=A0.Lfound:<br> > -=C2=A0 vrgather.vx v16, v0, a4<br> > -=C2=A0 vrgather.vx v24, v8, a4<br> > -=C2=A0 vmv.x.s a0, v16<br> > -=C2=A0 vmv.x.s a4, v24<br> > -=C2=A0 andi a0, a0, 0xff<br> > -=C2=A0 andi a4, a4, 0xff<br> > +=C2=A0 add a0, a0, a4<br> > +=C2=A0 add a1, a1, a4<br> > +=C2=A0 lbu a0, 0(a0)<br> > +=C2=A0 lbu a4, 0(a1)<br> >=C2=A0 =C2=A0 =C2=A0sub a0, a0, a4<br> >=C2=A0 =C2=A0 =C2=A0ret<br> >=C2=A0 =C2=A0.size memcmp, .-memcmp<br> <br> </blockquote></div> --000000000000a20d120653fad3fd--