From: David Laight <David.Laight@ACULAB.COM>
To: 'Ivan Orlov' <ivan.orlov0322@gmail.com>,
"paul.walmsley@sifive.com" <paul.walmsley@sifive.com>,
"palmer@dabbelt.com" <palmer@dabbelt.com>,
"aou@eecs.berkeley.edu" <aou@eecs.berkeley.edu>
Cc: "conor.dooley@microchip.com" <conor.dooley@microchip.com>,
"ajones@ventanamicro.com" <ajones@ventanamicro.com>,
"samuel@sholland.org" <samuel@sholland.org>,
"alexghiti@rivosinc.com" <alexghiti@rivosinc.com>,
"linux-riscv@lists.infradead.org"
<linux-riscv@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"skhan@linuxfoundation.org" <skhan@linuxfoundation.org>
Subject: RE: [PATCH] riscv: lib: Optimize 'strlen' function
Date: Mon, 18 Dec 2023 09:12:36 +0000 [thread overview]
Message-ID: <6aa468db18c04ad39e46612b343b2a60@AcuMS.aculab.com> (raw)
In-Reply-To: <45351e30-d197-4b9c-864f-8ff5f9b6ab61@gmail.com>
From: Ivan Orlov
> Sent: 17 December 2023 23:23
>
> On 12/17/23 18:10, David Laight wrote:
> > From: Ivan Orlov
> >> Sent: 13 December 2023 15:46
> >
> > Looking at the old code...
> >
> >> 1:
> >> - lbu t0, 0(t1)
> >> - beqz t0, 2f
> >> - addi t1, t1, 1
> >> - j 1b
> >
> > I suspect there is (at least) a two clock stall between
> > the 'ldu' and 'beqz'.
>
> Hmm, the stall exists due to memory access? Why does two subsequent
> accesses to the memory (as in the example you provided) do the trick? Is
> it because two "ldb"s could be parallelized?
On the fpga RISCV (and probably other 'small' implementations)
there is a two clock result delay from memory loads while the
result is written to the 'register file'.
ALU results get short-circuited so can be used in the next instruction.
The memory loads themselves are pipelined and can be issued
every clock.
(On the fpga version actual memory delays stall the pipeline.)
...
> Maybe we could enhance it even more by loading 4 consequent bytes into
> different registers so the memory loads would still be parallelized?
You need the loads to be pipelined, not parallelized.
That will help if there are longer delays accessing cache memory.
I'd expect any cpu with (say) a 4 clock cache read latency to
pipeline reads so that one can be issued every clock provided
the results aren't needed.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
prev parent reply other threads:[~2023-12-18 9:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 15:45 [PATCH] riscv: lib: Optimize 'strlen' function Ivan Orlov
2023-12-17 17:00 ` David Laight
2023-12-17 22:52 ` Ivan Orlov
2023-12-18 1:41 ` Ivan Orlov
2023-12-18 9:20 ` David Laight
2023-12-18 10:03 ` Ivan Orlov
2023-12-18 10:12 ` David Laight
2023-12-17 18:10 ` David Laight
2023-12-17 23:23 ` Ivan Orlov
2023-12-18 9:12 ` David Laight [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6aa468db18c04ad39e46612b343b2a60@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=ajones@ventanamicro.com \
--cc=alexghiti@rivosinc.com \
--cc=aou@eecs.berkeley.edu \
--cc=conor.dooley@microchip.com \
--cc=ivan.orlov0322@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=samuel@sholland.org \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox