Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 29 May 2016 23:20:54 +0300
From:      Andrey Chernov <ache@freebsd.org>
To:        cem@FreeBSD.org
Cc:        src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r300965 - head/lib/libc/stdlib
Message-ID:  <e93730b9-7dfe-5375-00ba-128584091348@freebsd.org>
In-Reply-To: <CAG6CVpXuoetY2GvV7Zonueb0TvQfRcMAHQYLXhd6yab5Mi%2BR0Q@mail.gmail.com>
References:  <201605291639.u4TGdSwq032144@repo.freebsd.org> <CAG6CVpXuoetY2GvV7Zonueb0TvQfRcMAHQYLXhd6yab5Mi%2BR0Q@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 29.05.2016 22:39, Conrad Meyer wrote:
> Does clang actually generate different code with this change?

Yes, without -O it generates
andl    $2147483647, ...
With -O nothing is changed.
In general, it can be not clang and I see no point to left junk code in
any case.

> 
> On Sun, May 29, 2016 at 9:39 AM, Andrey A. Chernov <ache@freebsd.org> wrote:
>> Author: ache
>> Date: Sun May 29 16:39:28 2016
>> New Revision: 300965
>> URL: https://svnweb.freebsd.org/changeset/base/300965
>>
>> Log:
>>   Micro optimize: C standard guarantees that right shift for unsigned value
>>   fills left bits with zero, and we have exact 32bit unsigned value
>>   (uint32_t), so there is no reason to add "& 0x7fffffff" here.
>>
>>   MFC after:      1 week
>>
>> Modified:
>>   head/lib/libc/stdlib/random.c
>>
>> Modified: head/lib/libc/stdlib/random.c
>> ==============================================================================
>> --- head/lib/libc/stdlib/random.c       Sun May 29 16:32:56 2016        (r300964)
>> +++ head/lib/libc/stdlib/random.c       Sun May 29 16:39:28 2016        (r300965)
>> @@ -430,7 +430,7 @@ random(void)
>>                  */
>>                 f = fptr; r = rptr;
>>                 *f += *r;
>> -               i = (*f >> 1) & 0x7fffffff;     /* chucking least random bit */
>> +               i = *f >> 1;    /* chucking least random bit */
>>                 if (++f >= end_ptr) {
>>                         f = state;
>>                         ++r;
>>
> 




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e93730b9-7dfe-5375-00ba-128584091348>