From: Aaron Conole <aconole@redhat.com>
To: David Marchand <david.marchand@redhat.com>
Cc: dev <dev@dpdk.org>, dpdk stable <stable@dpdk.org>
Subject: Re: [dpdk-stable] [PATCH] test/common: fix log2 check
Date: Thu, 05 Dec 2019 09:39:25 -0500 [thread overview]
Message-ID: <f7to8wmygyq.fsf@dhcp-25.97.bos.redhat.com> (raw)
In-Reply-To: <CAJFAV8xpg3=N1jFcYjkXMZDyGFM4Co5ojNVFSR+zuCdZt5QsyQ@mail.gmail.com> (David Marchand's message of "Thu, 5 Dec 2019 09:31:18 +0100")
David Marchand <david.marchand@redhat.com> writes:
> On Wed, Dec 4, 2019 at 10:20 PM Aaron Conole <aconole@redhat.com> wrote:
>>
>> David Marchand <david.marchand@redhat.com> writes:
>>
>> > We recently started to get random failures on the common_autotest ut with
>> > clang on Ubuntu 16.04.6.
>> >
>> > Example: https://travis-ci.com/DPDK/dpdk/jobs/263177424
>> >
>> > Wrong rte_log2_u64(0) val 0, expected ffffffff
>> > Test Failed
>> >
>> > The ut passes 0 to log2() to get an expected value.
>> >
>> > Quoting log2 / log(3) manual:
>> > If x is zero, then a pole error occurs, and the functions return
>> > -HUGE_VAL, -HUGE_VALF, or -HUGE_VALL, respectively.
>> >
>> > rte_log2_uXX helpers handle 0 as a special value and return 0.
>> > Let's have dedicated tests for this case.
>> >
>> > Fixes: 05c4345ef5c2 ("test: add unit test for integer log2 function")
>> > Cc: stable@dpdk.org
>> >
>> > Signed-off-by: David Marchand <david.marchand@redhat.com>
>> > ---
>>
>> Acked-by: Aaron Conole <aconole@redhat.com>
>>
>> Somethings that concern me:
>>
>> 1. A log2(0) should probably be an undetermined value, but this
>> effectively makes log2(0) == log2(1) so that if anyone uses these
>> for some mathematical work, it will have an exceptional behavior. I
>> know it's documented from a programmer perspective, but I am all for
>> documenting the mathematical side effect as well.
>
> What do you have in mind, adding a big warning in the doxygen "THIS IS
> NOT REAL MATH STUFF" ? :-)
Is such a warning not reasonable? :-)
>>
>> 2. Why hasn't this been complaining for so long? Or has it and we just
>> haven't noticed? Were some compiler flags changed recently? (maybe
>> -funsafe-math was always set or something?)
>
> Yes, I wondered too how we did not see this earlier.
> Even now, it happens randomly.
>
> libc log2(0) is not undefined itself, it returns -infinity.
> Looking at the test code, ceilf (I would expect ceil) returns
> -infinity when getting it passed.
> So I'd say the problem lies in the cast to uint32_t.
>
> Both gcc and clang do not seem to bother with standard compilation
> flags, and the cast gives 0 on my RHEL.
>
> #include <stdio.h>
> #include <inttypes.h>
> #include <math.h>
>
> int main(int argc, char *argv[])
> {
> printf("%lf %f %"PRIu32"\n", log2(0), (float)log2(0), (uint32_t)log2(0));
> return 0;
> }
>
> $ ./log2
> -inf -inf 0
>
>
> Now, if I use UBSAN with clang, I get a complaint at runtime:
> $ ./log2
> (/home/dmarchan/log2+0x41dfa5): runtime error: value -inf is outside
> the range of representable values of type 'unsigned int'
> -inf -inf 0
>
> Not sure if it explains the random failures, but won't undefined
> behavior eat your babies?
Possibly. I would still expect it to be consistent when it eats babies,
but maybe it doesn't have to be.
next prev parent reply other threads:[~2019-12-05 14:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-04 20:52 David Marchand
2019-12-04 21:19 ` Aaron Conole
2019-12-05 8:31 ` David Marchand
2019-12-05 14:39 ` Aaron Conole [this message]
2019-12-20 14:01 ` [dpdk-stable] [PATCH v2] " David Marchand
2019-12-20 14:06 ` David Marchand
2019-12-20 14:43 ` David Marchand
2019-12-20 14:52 ` Aaron Conole
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=f7to8wmygyq.fsf@dhcp-25.97.bos.redhat.com \
--to=aconole@redhat.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=stable@dpdk.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).