From owner-svn-src-all@freebsd.org Thu Apr 5 15:58:38 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7AEAAF8F80D for ; Thu, 5 Apr 2018 15:58:38 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-io0-x231.google.com (mail-io0-x231.google.com [IPv6:2607:f8b0:4001:c06::231]) (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 0B7CF8353E for ; Thu, 5 Apr 2018 15:58:38 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-io0-x231.google.com with SMTP id y128so31188732iod.4 for ; Thu, 05 Apr 2018 08:58:38 -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=YLfxFBoSQGkqIW65V6UOkbgjI8VF/Dcc1eUDnlivCTY=; b=OaEKY9r8SEWlvZGUCgftNma7j3ZQYreN0E4fP5J/W84/LU9NF/3yfp9XfmlYHWvo47 zn9Q68wuKMzsFNzzE+fT8NRpx0+RwfsjAzTSqXGcOIf4PEiSNiKGNMXz3nHpm95jMwNM JGj5ZSsQj55ow7rW30DL8qC/F2E7tiaFVzsDzmpqJTNPOxdlKui+V15VKDPC/WV0R8bA WxU0auijCOLVCaehK0FME/s/EtMg9x0W/uDN4jDPrSxg/kUtbiLywp355kMU0eP+N66I hw/eAdwZbM4htNBeHKJ9Yr+cwMpSmWzi6k9PjkIKCn3ZA8KfKtjDkgXUU9g6bLpw03Az VB5g== 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=YLfxFBoSQGkqIW65V6UOkbgjI8VF/Dcc1eUDnlivCTY=; b=YcG0dYCgc3jdoYK04NISiQBmJkA7UuO0OAiXxJBpy8LmsDUl3plRFVJ6PYtSrkAiOW a4eiI2wctWzAtJKIyeK1CjTIwPdxwRA7VSQc7ZIwpR+bplhwkYqtObjyztarmgJTC+0m 8QHrvC+eBVpUPiFE3pxJkOhxtGFwDgbcW1e4pcFbbHBG6gv7UFHuCT9CLdazrHF1wenL wwgQ19vuQHC6KnqilO3Pw8fr8z7IswwHd0zz/sWBa/N2mCcwCPSVXCc5jkkBp8RajkSr rpoxPfkK4s7yYDcxOYfVQ1845OPQkxGjLIJw9zXzgLxY36gBkqr/vlsg0BiroQH/YL3h AerA== X-Gm-Message-State: ALQs6tD+56HvvfuG7iIuP9ATLXnrLzMNwQd9spEG+rrr9OZPF2vB+gKG zgrFBgFQAFZ+tq+hJ3Iw4Tw3VSOHaDohvGQ5QvlnIg== X-Google-Smtp-Source: AIpwx48OAVYzY0JqVlQnMYHBFyMwGNmLcwSYX6vI6O2RhjKlbu3eWjQDmhjIca2vESzvuQOK45+/D52vJ0nIlBkiTQA= X-Received: by 10.107.144.11 with SMTP id s11mr21298407iod.37.1522943917285; Thu, 05 Apr 2018 08:58:37 -0700 (PDT) MIME-Version: 1.0 Sender: wlosh@bsdimp.com Received: by 10.79.203.196 with HTTP; Thu, 5 Apr 2018 08:58:36 -0700 (PDT) X-Originating-IP: [2603:300b:6:5100:1052:acc7:f9de:2b6d] In-Reply-To: <20180405154619.q3blip266qa3z5ut@MacBook-Pro-de-Roger.local> References: <201804051431.w35EVtg4047897@repo.freebsd.org> <1522942377.49673.245.camel@freebsd.org> <20180405154619.q3blip266qa3z5ut@MacBook-Pro-de-Roger.local> From: Warner Losh Date: Thu, 5 Apr 2018 09:58:36 -0600 X-Google-Sender-Auth: 4xnmOBh0savK7uMhUlT9cEVyNhE Message-ID: Subject: Re: svn commit: r332072 - head/sys/sys To: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= Cc: Ian Lepore , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.25 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 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: Thu, 05 Apr 2018 15:58:38 -0000 On Thu, Apr 5, 2018 at 9:46 AM, Roger Pau Monn=C3=A9 w= rote: > On Thu, Apr 05, 2018 at 09:32:57AM -0600, Ian Lepore wrote: > > On Thu, 2018-04-05 at 14:31 +0000, Roger Pau Monn=C3=A9 wrote: > > > Author: royger > > > Date: Thu Apr 5 14:31:54 2018 > > > New Revision: 332072 > > > URL: https://svnweb.freebsd.org/changeset/base/332072 > > > > > > Log: > > > introduce GiB and MiB macros > > > > > > This macros convert from GiB or MiB into bytes. > > > > > > Sponsored by: Citrix Systems R&D > > > > > > Modified: > > > head/sys/sys/param.h > > > > > > Modified: head/sys/sys/param.h > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > > --- head/sys/sys/param.h Thu Apr 5 14:25:39 2018 (r332071) > > > +++ head/sys/sys/param.h Thu Apr 5 14:31:54 2018 (r332072) > > > @@ -362,4 +362,8 @@ __END_DECLS > > > */ > > > #define __PAST_END(array, offset) (((__typeof__(*(array)) > *)(array))[offset]) > > > > > > +/* Unit conversion macros. */ > > > +#define GiB(v) (v ## ULL << 30) > > > +#define MiB(v) (v ## ULL << 20) > > > + > > > #endif /* _SYS_PARAM_H_ */ > > > > > > > These names don't make it clear whether the conversion is bytes->GiB or > > GiB->bytes. The names seem way too generic for a public namespace in a > > file as heavily included behind your back as param.h is. > > > > Also, this completely reasonable usage won't work, likely with > > confusing compile error messages: > > > > int bytes, gibytes; > > ... > > bytes =3D GiB(gibytes); > > I find those helpful for their specific usage. I could introduce > static inline functions like: > > size_t gb_to_bytes(size_t)... > > But I assume this is also going to cause further discussion. > Yea, traditional macro names would be "gibtob" and "btogib" but I didn't just reply to bikeshed a name: But you don't need to specify a type, consider the current btodb macro: #define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \ (sizeof (bytes) > sizeof(long) \ ? (daddr_t)((unsigned long long)(bytes) >> DEV_BSHIFT) \ : (daddr_t)((unsigned long)(bytes) >> DEV_BSHIFT)) which shows how to do this in a macro, which is orthogonal to any name you may choose. I can also bikeshed function vs macro :) Warner