From owner-svn-src-head@freebsd.org Tue May 31 05:53:13 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E354EB550C0; Tue, 31 May 2016 05:53:13 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail109.syd.optusnet.com.au (mail109.syd.optusnet.com.au [211.29.132.80]) by mx1.freebsd.org (Postfix) with ESMTP id AC53F117B; Tue, 31 May 2016 05:53:12 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c122-106-149-109.carlnfd1.nsw.optusnet.com.au (c122-106-149-109.carlnfd1.nsw.optusnet.com.au [122.106.149.109]) by mail109.syd.optusnet.com.au (Postfix) with ESMTPS id A31F2D64FE1; Tue, 31 May 2016 15:53:05 +1000 (AEST) Date: Tue, 31 May 2016 15:53:04 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Andrey Chernov cc: Bruce Evans , Conrad Meyer , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r300965 - head/lib/libc/stdlib In-Reply-To: Message-ID: <20160531152438.S1534@besplex.bde.org> References: <201605291639.u4TGdSwq032144@repo.freebsd.org> <20160530122100.X924@besplex.bde.org> <5985bdc1-b821-f352-0bc5-c45c600c5318@freebsd.org> <20160531130326.G1052@besplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=EfU1O6SC c=1 sm=1 tr=0 a=R/f3m204ZbWUO/0rwPSMPw==:117 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=Jp1r1I4GX9VPI0hR0fIA:9 a=8koyKKvalQC48CK6:21 a=xtXk7xc7YLWh467y:21 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2016 05:53:14 -0000 On Tue, 31 May 2016, Andrey Chernov wrote: > On 31.05.2016 6:42, Bruce Evans wrote: >> >> Er, I already said which types are better -- [u]int_fast32_t here. > > [u]int_fast32_t have _at_least_ 32 bits. int32_t in the initial PRNG can > be changed since does not overflow and involve several calculations, but > uint_fast32_t is needed just for two operations: I think you mean a native uint32_t is needed for 2 operations. > *f += *r; > i = (*f >> 1) & 0x7fffffff; This takes 2 operations (add and shift) with native uint32_t. It takes 4 logical operations (maybe more physically, or less after optimization) with emulated uint32_t (add, mask to 32 bits (maybe move to another register to do this), shift, mask to 32 bits). When you write the final mask explicitly, it is to 31 bits and optimizing this away is especially easy in both cases. > We need to assign values from uint32_t to uint_fast32_t (since array > size can't be changed), FP code using double_t is similar: data in tables should normally be in doubles since double_t might be too much larger; data in function parameters is almost always in doubles since APIs are deficient and don't even support double_t as an arg; then it is best to assign to a double_t variable since if you just use the double then expressions using it will promote it to double_t but it is too easy to lose this expansion too early. It takes extra variables and a little more code for the assignments, but the extra variables are optimized away in cases where there is no expansion. > do this single operation fast and store them > back into array of uint32_t. I doubt that much gain can comes from it > and even pessimization in some cases. Better let compiler do its job here. It's never a pessimization if the compiler does its job. It is good to practice this on a simple 2-step operation. Think of a multi-step operation where each step requires clipping to 32 bits. Using uint32_t for the calculation is just a concise way of writing "& 0xffffffff" after every step (even ones that don't need it). It is difficult and sometimes impossible for the compiler to optimize away these masks across a large number of steps. Sometimes this is easy for the programmer. Bruce