Messages in this thread | | | From | Nadav Amit <> | Subject | Re: [PATCH v1 05/15] mm/rmap: convert RMAP flags to a proper distinct rmap_t type | Date | Tue, 8 Mar 2022 18:24:01 +0000 |
| |
> On Mar 8, 2022, at 10:09 AM, Linus Torvalds <torvalds@linux-foundation.org> wrote: > > On Tue, Mar 8, 2022 at 9:15 AM Nadav Amit <namit@vmware.com> wrote: >> >> It would be much easier to read. The last time I made such a suggestion, >> Ingo said "I personally like bitfields in theory … [but] older versions of >> GCC did a really poor job of optimizing them.” > > Yeah, even not that old versions had serious issues, iirc. > > Bitfields can look nice, but they have some _serious_ syntax issues. > In particular, they are nice when you want to *test* one single field > (ie bit in this case), but basically atrociously bad in almost all > other circumstances. > > For example, passing a bitfield aggregate as an argument is just > crazy. Oh, you can do it, with syntax like > > (struct type) { .field1 = 1, .field3 = 1 } > > as the argument but when you say "much easier to read" I laugh in your > face and call your mother a hamster. > > And that's ignoring all the issues when you want to combine two > bitfields. You can't do it. There is nothing like the binary "or" > operator. Again, it's easy to modify *one* field, but taking two > bitfields and merging them? Not going to happen. > > So no. Bitfields have their place, but they are close to useless as > "flags" type things that get passed around as arguments, unless you > have very very specific and limited use.
I see your point regarding passing an arg. The or’ing of bitfields can easily be resolved, unless I am missing something, with a union that holds the aggregate value and an anonymous struct that holds the individual flags.
At the time, I thought that bitfields are much better fit for cpuid fields (which are not just flags).
Anyhow, I will refrain from using bitfields for flags, if only for the sake of my mother. :)
| |