Date: Fri, 6 Apr 2018 07:14:42 -0700 From: Conrad Meyer <cem@freebsd.org> To: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= <royger@freebsd.org> Cc: src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r332092 - in head/sys: amd64/amd64 sys x86/x86 Message-ID: <CAG6CVpV8Ue-t--%2BMMS%2B11x_=LjgWbQiAq2KGzOEdiGPpxQ%2BPhQ@mail.gmail.com> In-Reply-To: <201804061120.w36BK6s6074635@repo.freebsd.org> References: <201804061120.w36BK6s6074635@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
I like something like this for clarity. But I don't see any reason for these function-like macros instead of the more general definition of an SI prefix constant multiple. A multiple works with numeric literals and variables alike. Something like: #define GiB ((size_t)1 << 30) my_foo =3D 15 * GiB; (There's nothing byte-specific about SI prefixes, but "Gi" alone is a worse name. Arguably, size_t is wrong for quantities of bytes on 32-bit platforms with 64-bit off_t.) The compiler will still reduce constant expressions. Perhaps even better, conversion away is straightforward units math, and the compiler can still do the clever thing with right shifts: my_gb =3D howmany(my_foo, GiB); //or my_gb =3D my_foo / GiB; Unfortunately, I expect a lot of code to already have defines or variables with conflicting names, so I'm not sure adding these names to primary headers is viable as-is. Best, Conrad On Fri, Apr 6, 2018 at 4:20 AM, Roger Pau Monn=C3=A9 <royger@freebsd.org> w= rote: > Author: royger > Date: Fri Apr 6 11:20:06 2018 > New Revision: 332092 > URL: https://svnweb.freebsd.org/changeset/base/332092 > > Log: > remove GiB/MiB macros from param.h > > And instead define them in the files where they are used. > > Requested by: bde > > Modified: > head/sys/amd64/amd64/mp_machdep.c > head/sys/sys/param.h > head/sys/x86/x86/mp_x86.c > > Modified: head/sys/amd64/amd64/mp_machdep.c > =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/amd64/amd64/mp_machdep.c Fri Apr 6 09:25:08 2018 (= r332091) > +++ head/sys/amd64/amd64/mp_machdep.c Fri Apr 6 11:20:06 2018 (= r332092) > @@ -83,6 +83,8 @@ __FBSDID("$FreeBSD$"); > #define BIOS_RESET (0x0f) > #define BIOS_WARM (0x0a) > > +#define GiB(v) (v ## ULL << 30) > + > extern struct pcpu __pcpu[]; > > /* Temporary variables for init_secondary() */ > > 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 Fri Apr 6 09:25:08 2018 (r332091) > +++ head/sys/sys/param.h Fri Apr 6 11:20:06 2018 (r332092) > @@ -362,8 +362,4 @@ __END_DECLS > */ > #define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[off= set]) > > -/* Unit conversion macros. */ > -#define GiB(v) (v ## ULL << 30) > -#define MiB(v) (v ## ULL << 20) > - > #endif /* _SYS_PARAM_H_ */ > > Modified: head/sys/x86/x86/mp_x86.c > =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/x86/x86/mp_x86.c Fri Apr 6 09:25:08 2018 (r332091) > +++ head/sys/x86/x86/mp_x86.c Fri Apr 6 11:20:06 2018 (r332092) > @@ -160,6 +160,8 @@ struct cache_info { > > unsigned int boot_address; > > +#define MiB(v) (v ## ULL << 20) > + > void > mem_range_AP_init(void) > { >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAG6CVpV8Ue-t--%2BMMS%2B11x_=LjgWbQiAq2KGzOEdiGPpxQ%2BPhQ>