From: David Laight <David.Laight@ACULAB.COM>
To: 'Ammar Faizi' <ammarfaizi2@gnuweeb.org>,
Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
Cc: "Willy Tarreau" <w@1wt.eu>,
"Thomas Weißschuh" <linux@weissschuh.net>,
"Nicholas Rosenberg" <inori@vnlx.org>,
"Michael William Jonathan" <moe@gnuweeb.org>,
"GNU/Weeb Mailing List" <gwml@vger.gnuweeb.org>,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>
Subject: RE: [RFC PATCH v2 1/4] tools/nolibc: x86-64: Use `rep movsb` for `memcpy()` and `memmove()`
Date: Sun, 3 Sep 2023 20:35:06 +0000 [thread overview]
Message-ID: <0f885fa14710453c9512315d6cfeee35@AcuMS.aculab.com> (raw)
In-Reply-To: <4459ed19-f603-b4f6-392e-4e1322e06d56@gnuweeb.org>
From: Ammar Faizi
> Sent: 02 September 2023 13:37
> On 2023/09/02 午後7:29, Alviro Iskandar Setiawan wrote:
> > On Sat, Sep 2, 2023 at 1:38 PM Ammar Faizi wrote:
> >> Ok, I'll do that.
> >
> > Another micro-optimization. Since the likely case is the forward copy,
> > make it the case that doesn't take the jump.
> >
> > Pseudo C:
> > if (unlikely(dst - src < n))
> > backward_copy();
> > else
> > forward_copy();
>
> Point taken.
I believe it makes almost no difference.
I'm sure I read that modern (Intel at least) cpu never do
static branch prediction.
So 'cold cache' there is 50% chance of the branch being taken.
Nothing the compiler can do will affect it.
OTOH having
if (likely(dst - src >= n))
forwards();
else
backwards();
(and in that order) probably makes the code a bit easier to read.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2023-09-03 20:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-02 5:50 [RFC PATCH v2 0/4] nolibc x86-64 string functions Ammar Faizi
2023-09-02 5:50 ` [RFC PATCH v2 1/4] tools/nolibc: x86-64: Use `rep movsb` for `memcpy()` and `memmove()` Ammar Faizi
2023-09-02 6:07 ` Alviro Iskandar Setiawan
2023-09-02 6:11 ` Ammar Faizi
2023-09-02 6:22 ` Willy Tarreau
2023-09-02 6:37 ` Ammar Faizi
2023-09-02 12:29 ` Alviro Iskandar Setiawan
2023-09-02 12:36 ` Ammar Faizi
2023-09-03 20:35 ` David Laight [this message]
2023-09-02 5:50 ` [RFC PATCH v2 2/4] tools/nolibc: x86-64: Use `rep stosb` for `memset()` Ammar Faizi
2023-09-02 5:50 ` [RFC PATCH v2 3/4] tools/nolibc: string: Remove the `_nolibc_memcpy_down()` function Ammar Faizi
2023-09-02 5:50 ` [RFC PATCH v2 4/4] tools/nolibc: string: Remove the `_nolibc_memcpy_up()` function Ammar Faizi
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=0f885fa14710453c9512315d6cfeee35@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=alviro.iskandar@gnuweeb.org \
--cc=ammarfaizi2@gnuweeb.org \
--cc=gwml@vger.gnuweeb.org \
--cc=inori@vnlx.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=moe@gnuweeb.org \
--cc=w@1wt.eu \
/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
all inboxes | Powered by JetHome®