public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Andrew Jones <drjones@redhat.com>,
	Nikos Nikoleris <nikos.nikoleris@arm.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com,
	alexandru.elisei@arm.com, andre.przywara@arm.com
Subject: Re: [kvm-unit-tests PATCH v2 1/4] lib/string: Add strnlen, strrchr and strtoul
Date: Tue, 23 Mar 2021 14:01:47 +0100	[thread overview]
Message-ID: <f60f2012-b007-b9db-e680-1ecf110e343d@redhat.com> (raw)
In-Reply-To: <20210323121415.rss3evguqb3b7vvz@kamzik.brq.redhat.com>

On 23/03/2021 13.14, Andrew Jones wrote:
> 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.
> 
> Anybody else have suggestions? Paolo? Thomas?

What does a "normal" libc implementation do (e.g. glibc)? If it is also not 
doing overflow checking, I think we also don't need it in the kvm-unit-tests.

  Thomas


  parent reply	other threads:[~2021-03-23 13:02 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
2021-03-23 13:41         ` Andrew Jones
2021-03-23 16:11           ` Andre Przywara
2021-03-23 13:01       ` Thomas Huth [this message]
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=f60f2012-b007-b9db-e680-1ecf110e343d@redhat.com \
    --to=thuth@redhat.com \
    --cc=alexandru.elisei@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=nikos.nikoleris@arm.com \
    --cc=pbonzini@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