From owner-svn-src-head@freebsd.org Sat Aug 5 03:55:39 2017 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 87697DB5D04 for ; Sat, 5 Aug 2017 03:55:39 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-io0-x234.google.com (mail-io0-x234.google.com [IPv6:2607:f8b0:4001:c06::234]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5BC3D63430 for ; Sat, 5 Aug 2017 03:55:39 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-io0-x234.google.com with SMTP id c74so11823703iod.4 for ; Fri, 04 Aug 2017 20:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=fZFbPWEzrlHZNB7ND2VEwCDbWwgVRkA0kkezJMfVeEQ=; b=V987beTTQ63tExRITY1AAKGIm2dESvElKHkFxg+p0C/C1XswWG4BhaxarrEuthTIih WAeNO7xPjeWQnNjXE5/JxrlzpLXQr2nlqjO96MuWOBR73ZfqRq7P91flxGadZzVuOQcC xaxFeBTdebD/iYq5xnNCKToALM3YrAvexQn2eT1WARJyaWkdDevopS3c2tIzrSC5c9wK vSwM2qJExPhe8iLa8gUcd0R+GaJBgT53QE+G5cDwFH8UL3Kyqsvuc2NG4jvTTcnkB3kD xxtzYfekUJ0Xuw7ldyz/5c+Hwbjo9v4TUW4ckkSUV+Wp9Za8zBFjG5xUYAB/x9n75iBf UhAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=fZFbPWEzrlHZNB7ND2VEwCDbWwgVRkA0kkezJMfVeEQ=; b=ldVsHq/oa9pvhbJTNPFZ+RwMClOYN1T4krnmqZe1Tod38bAbb0Q+c6/iYU+Sw6I80Y YfyYFh9XcAzihNL8HJLrsFe49TMxEqCGE/7DF8wi3CMos2Bz8DKadoBrYwt1sYSnTsTy gVgZpKpQaLSZLPO1Fk7aZswa3i2cZdpS/xfp5uYp7+3UlSbcLhNR64lTKQneiGwmQAxQ Rc7Bgspf4KleZfHlJ/XRZfjtCctzBaBf7zhWDjs+/HT4qw0nq6ZLGFVwcAvQDgqamg8H 6lvqzDHvPpYJjbRKiND5aC9TG5RLgSqPhmX7jLGWLujfFPacGXSrr1we6e/kpSF9pBZ5 L1dg== X-Gm-Message-State: AHYfb5gmaWNDBNAg//+UkHzdDUEyL03iSlN8lw274FIzCxNFhSaQ9VSP zZSssHLUCBZ3tO3+lsjfga6oMOq0VE5M X-Received: by 10.107.190.197 with SMTP id o188mr4742802iof.160.1501905338668; Fri, 04 Aug 2017 20:55:38 -0700 (PDT) MIME-Version: 1.0 Sender: wlosh@bsdimp.com Received: by 10.79.58.17 with HTTP; Fri, 4 Aug 2017 20:55:38 -0700 (PDT) X-Originating-IP: [2603:300b:6:5100:d916:ea3b:9e7d:6b51] In-Reply-To: <20170805123249.K1377@besplex.bde.org> References: <201708040423.v744NOix022999@repo.freebsd.org> <20170805123249.K1377@besplex.bde.org> From: Warner Losh Date: Fri, 4 Aug 2017 21:55:38 -0600 X-Google-Sender-Auth: 0f4UTYpGde1x-n_2DglaHjnp8xE Message-ID: Subject: Re: svn commit: r322041 - head/sys/kern To: Bruce Evans Cc: Alan Cox , src-committers , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 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: Sat, 05 Aug 2017 03:55:39 -0000 On Fri, Aug 4, 2017 at 9:22 PM, Bruce Evans wrote: > On Fri, 4 Aug 2017, Alan Cox wrote: > > Log: >> In case readers are misled by expressions that combine multiplication and >> division, add parentheses to make the precedence explicit. >> >> Submitted by: Doug Moore >> Requested by: imp >> Reviewed by: imp >> MFC after: 1 week >> X-MFC after: r321840 >> Differential Revision: https://reviews.freebsd.org/D11815 >> > > This obfuscates the necessary parentheses. > > Modified: head/sys/kern/subr_blist.c >> ... >> static inline daddr_t >> radix_to_skip(daddr_t radix) >> { >> >> return (radix / >> - (BLIST_BMAP_RADIX / BLIST_META_RADIX * (BLIST_META_RADIX - >> 1))); >> + ((BLIST_BMAP_RADIX / BLIST_META_RADIX) * (BLIST_META_RADIX - >> 1))); >> } >> > > Readers now have to do a more complete parse to find the interesting parts, > and writers have to count to a large number to get the count right when > the parantheses pile up at the right. > > This expression is relatively simple to parse to remove the obfuscation, > but consider more complicated cases: > > (1) > (a + b + c + d + e) + (f + g + h + i + j) > > in floating point so that addition is not associative and the order > matters. > The order is left to right in C, and this expression uses 2 sets of > parentheses to not use left to right for all terms. Full parentheses gives > the good obfuscation: > > ((((a + b) + c) + d) + e) + ((((f + g) + h) + i) + j) > > (2) Similarly with +- instead of all +. The order matters much more, but I > don't remember ever seeing expressions with only +- being obfuscated by > parentheses, except in floating point code where the author wants to > emphasize the left to right evaluation. I guess there are also examples > with integer types. Even with all + operations, the order is critical > with plain ints, since different orders might cause overflow, and with > mixed signed/unsigned/small/large integer types, the promotions depend > on the order. > > (3) Similarly with */ instead of +-. These are even more similar in > programming uses than in math structures, since + is always associative > and commutative in math structures, but it is not even commutative in > programming. You know, for this case, it's totally cool. Warner