From: David Laight <[email protected]>
To: 'Ammar Faizi' <[email protected]>,
Alviro Iskandar Setiawan <[email protected]>
Cc: "Willy Tarreau" <[email protected]>,
"Thomas Weißschuh" <[email protected]>,
"Nicholas Rosenberg" <[email protected]>,
"Michael William Jonathan" <[email protected]>,
"GNU/Weeb Mailing List" <[email protected]>,
"Linux Kernel Mailing List" <[email protected]>
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: <[email protected]> (raw)
In-Reply-To: <[email protected]>
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 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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