From owner-svn-src-all@freebsd.org Sun May 29 08:01:09 2016 Return-Path: Delivered-To: svn-src-all@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 9F7FBB4FAC3; Sun, 29 May 2016 08:01:09 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail104.syd.optusnet.com.au (mail104.syd.optusnet.com.au [211.29.132.246]) by mx1.freebsd.org (Postfix) with ESMTP id 66BF716C0; Sun, 29 May 2016 08:01:09 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from besplex.bde.org (c110-21-42-169.carlnfd1.nsw.optusnet.com.au [110.21.42.169]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id 8EA4B421683; Sun, 29 May 2016 18:00:58 +1000 (AEST) Date: Sun, 29 May 2016 18:00:56 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Don Lewis cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r300949 - head/sys/netpfil/ipfw In-Reply-To: <201605290723.u4T7Nvvk027654@repo.freebsd.org> Message-ID: <20160529173603.G2146@besplex.bde.org> References: <201605290723.u4T7Nvvk027654@repo.freebsd.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=c+ZWOkJl c=1 sm=1 tr=0 a=kDyANCGC9fy361NNEb9EQQ==:117 a=kDyANCGC9fy361NNEb9EQQ==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=EowK929v9maM7jh68bYA:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 May 2016 08:01:09 -0000 On Sun, 29 May 2016, Don Lewis wrote: > Log: > Cast some expressions that multiply a long long constant by a > floating point constant to int64_t. This avoids the runtime > conversion of the the other operand in a set of comparisons from > int64_t to floating point and doing the comparisions in floating > point. > > Suggested by: lidl > Submitted by: Rasool Al-Saadi > MFC after: 2 weeks (with r300779) Compilers are still permitted to (and perhaps even required to) evaluate FP constant expressions at runtime (to get rounding and/or exception flags right). They probably don't in practice, but it is unclear what happens for -O0 and the rules for rounding are too hard to understand. > Modified: head/sys/netpfil/ipfw/dn_aqm_pie.c > ============================================================================== > --- head/sys/netpfil/ipfw/dn_aqm_pie.c Sun May 29 07:14:51 2016 (r300948) > +++ head/sys/netpfil/ipfw/dn_aqm_pie.c Sun May 29 07:23:56 2016 (r300949) > @@ -244,17 +244,17 @@ calculate_drop_prob(void *x) > p *= (PIE_MAX_PROB << 12) / AQM_TIME_1S; > > /* auto-tune drop probability */ > - if (prob< PIE_MAX_PROB * 0.000001) > + if (prob < (int64_t)(PIE_MAX_PROB * 0.000001)) > p >>= 11 + PIE_FIX_POINT_BITS+12; > + else if (prob < (int64_t)(PIE_MAX_PROB * 0.00001)) > p >>= 9 + PIE_FIX_POINT_BITS+12; Why not just divide by integer powers of 10? This might not give a suitably monotonic/continuous scaling at the endpoints, but it is unclear if the FP gives that either even if we are more careful with the rounding mode. A table of endpoints could be used to get precise control. Then FP can be used more safely, since it is clear that constants in tables must be evaluated at compile time. > ... Similarly for all cases. Bruce