From: Florian Weimer <fweimer@redhat.com>
To: Nikolay Borisov <nborisov@suse.com>
Cc: linux-kernel@vger.kernel.org, ndesaulniers@google.com,
torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org,
david@fromorbit.com
Subject: Re: [PATCH] lib/string: Bring optimized memcmp from glibc
Date: Wed, 28 Jul 2021 22:12:09 +0200 [thread overview]
Message-ID: <877dha6vvq.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20210721135926.602840-1-nborisov@suse.com> (Nikolay Borisov's message of "Wed, 21 Jul 2021 16:59:26 +0300")
* Nikolay Borisov:
> +/*
> + * Compare A and B bytewise in the byte order of the machine.
> + * A and B are known to be different. This is needed only on little-endian
> + * machines.
> + */
> +static inline int memcmp_bytes(unsigned long a, unsigned long b)
> +{
> + long srcp1 = (long) &a;
> + long srcp2 = (long) &b;
> + unsigned long a0, b0;
> +
> + do {
> + a0 = ((uint8_t *) srcp1)[0];
> + b0 = ((uint8_t *) srcp2)[0];
> + srcp1 += 1;
> + srcp2 += 1;
> + } while (a0 == b0);
> + return a0 - b0;
> +}
Should this be this?
static inline int memcmp_bytes(unsigned long a, unsigned long b)
{
if (sizeof(a) == 4)
return __builtin_bswap32(a) < __builtin_bswap32(b) ? -1 : 0;
else
return __builtin_bswap64(a) < __builtin_bswap64(b) ? -1 : 0;
}
(Or whatever macro versions the kernel has for this.)
Or is the expectation that targets that don't have an assembler
implementation for memcmp have also bad bswap built-ins?
Thanks,
Florian
prev parent reply other threads:[~2021-07-28 20:12 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-21 13:59 [PATCH] lib/string: Bring optimized memcmp from glibc Nikolay Borisov
2021-07-21 14:32 ` Christoph Hellwig
2021-07-21 14:35 ` Nikolay Borisov
2021-07-21 14:42 ` Christoph Hellwig
2021-07-21 14:51 ` Matthew Wilcox
2021-07-21 15:17 ` Peter.Enderborg
2021-07-21 15:34 ` Matthew Wilcox
2021-07-21 15:39 ` Peter.Enderborg
2021-07-21 18:00 ` Linus Torvalds
2021-07-21 18:17 ` Nikolay Borisov
2021-07-21 18:45 ` Linus Torvalds
2021-07-21 18:55 ` Linus Torvalds
2021-07-21 19:26 ` Linus Torvalds
2021-07-22 11:28 ` Nikolay Borisov
2021-07-22 16:40 ` Linus Torvalds
2021-07-22 17:03 ` Nikolay Borisov
2021-08-26 9:03 ` Nikolay Borisov
2021-07-22 8:28 ` Nikolay Borisov
2021-07-23 14:02 ` David Laight
2021-07-21 20:10 ` David Sterba
2021-07-21 20:27 ` Linus Torvalds
2021-07-22 5:54 ` Nikolay Borisov
2021-07-28 20:12 ` Florian Weimer [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=877dha6vvq.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=david@fromorbit.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nborisov@suse.com \
--cc=ndesaulniers@google.com \
--cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.