Date: Thu, 5 Apr 2018 09:58:36 -0600 From: Warner Losh <imp@bsdimp.com> To: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= <royger@freebsd.org> Cc: Ian Lepore <ian@freebsd.org>, src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r332072 - head/sys/sys Message-ID: <CANCZdfputnwHg-gChVKfvZdHn1nHcHXpE0WVLfejHUZfeC8jLg@mail.gmail.com> 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>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Apr 5, 2018 at 9:46 AM, Roger Pau Monn=C3=A9 <royger@freebsd.org> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfputnwHg-gChVKfvZdHn1nHcHXpE0WVLfejHUZfeC8jLg>