From: Andre Przywara <andre.przywara@arm.com>
To: Andrew Jones <drjones@redhat.com>
Cc: Nikos Nikoleris <nikos.nikoleris@arm.com>,
kvm@vger.kernel.org, pbonzini@redhat.com,
alexandru.elisei@arm.com, thuth@redhat.com
Subject: Re: [kvm-unit-tests PATCH v2 1/4] lib/string: Add strnlen, strrchr and strtoul
Date: Tue, 23 Mar 2021 13:00:01 +0000 [thread overview]
Message-ID: <20210323130001.7f160eaa@slackpad.fritz.box> (raw)
In-Reply-To: <20210323121415.rss3evguqb3b7vvz@kamzik.brq.redhat.com>
On Tue, 23 Mar 2021 13:14:15 +0100
Andrew Jones <drjones@redhat.com> wrote:
Hi,
> On Mon, Mar 22, 2021 at 09:35:23AM +0100, Andrew Jones wrote:
> > @@ -208,23 +209,46 @@ unsigned long int strtoul(const char *nptr, char **endptr, int base)
> > c = *s - 'A' + 10;
> > else
> > break;
> > - acc = acc * base + c;
> > +
> > + if (is_signed) {
> > + long __acc = (long)acc;
> > + overflow = __builtin_smull_overflow(__acc, base, &__acc);
> > + assert(!overflow);
> > + overflow = __builtin_saddl_overflow(__acc, c, &__acc);
> > + assert(!overflow);
> > + acc = (unsigned long)__acc;
> > + } else {
> > + overflow = __builtin_umull_overflow(acc, base, &acc);
> > + assert(!overflow);
> > + overflow = __builtin_uaddl_overflow(acc, c, &acc);
> > + assert(!overflow);
> > + }
> > +
>
> Unfortunately my use of these builtins isn't loved by older compilers,
> like the one used by the build-centos7 pipeline in our gitlab CI. I
> could wrap them in an #if GCC_VERSION >= 50100 and just have the old
> 'acc = acc * base + c' as the fallback, but that's not pretty and
> would also mean that clang would use the fallback too. Maybe we can
> try and make our compiler.h more fancy in order to provide a
> COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW define like linux does for
> both gcc and clang. Or, we could just forgot the overflow checking.
In line with my email from yesterday:
Before we go down the path of all evil (premature optimisation!), can't
we just copy
https://git.kernel.org/pub/scm/libs/klibc/klibc.git/tree/usr/klibc/strntoumax.c
and have a tested version that works everywhere? This is BSD/GPL dual
licensed, IIUC.
I don't really see the reason to performance optimise strtol in the
context of kvm-unit-tests.
Cheers,
Andre
next prev parent reply other threads:[~2021-03-23 13:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-18 18:07 [kvm-unit-tests PATCH v2 0/4] Fix the devicetree parser for stdout-path Nikos Nikoleris
2021-03-18 18:07 ` [kvm-unit-tests PATCH v2 1/4] lib/string: Add strnlen, strrchr and strtoul Nikos Nikoleris
2021-03-22 8:35 ` Andrew Jones
2021-03-22 9:52 ` Nikos Nikoleris
2021-03-22 10:09 ` Andrew Jones
2021-03-23 12:14 ` Andrew Jones
2021-03-23 13:00 ` Andre Przywara [this message]
2021-03-23 13:41 ` Andrew Jones
2021-03-23 16:11 ` Andre Przywara
2021-03-23 13:01 ` Thomas Huth
2021-03-23 13:31 ` Andrew Jones
2021-03-18 18:07 ` [kvm-unit-tests PATCH v2 3/4] Makefile: Remove overriding recipe for libfdt_clean Nikos Nikoleris
2021-03-18 18:07 ` [kvm-unit-tests PATCH v2 4/4] devicetree: Parse correctly the stdout-path Nikos Nikoleris
2021-03-22 8:53 ` [kvm-unit-tests PATCH v2 0/4] Fix the devicetree parser for stdout-path Andrew Jones
2021-03-22 9:55 ` Nikos Nikoleris
2021-03-22 18:04 ` Andre Przywara
2021-03-22 18:56 ` Andrew Jones
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=20210323130001.7f160eaa@slackpad.fritz.box \
--to=andre.przywara@arm.com \
--cc=alexandru.elisei@arm.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=nikos.nikoleris@arm.com \
--cc=pbonzini@redhat.com \
--cc=thuth@redhat.com \
/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