Re: [PATCH] slab.h: Avoid using & for logical and of booleans
From: Vlastimil Babka
Date: Tue Nov 13 2018 - 13:25:57 EST
On 11/12/18 10:55 AM, David Laight wrote:
> From: Vlastimil Babka [mailto:vbabka@xxxxxxx]
>> Sent: 09 November 2018 19:16
> ...
>> This? Not terribly elegant, but I don't see a nicer way right now...
>
> Maybe just have two copies of the function body?
>
> static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags)
> {
> #ifndef CONFIG_ZONE_DMA
> return flags & __GFP_RECLAIMABLE ? KMALLOC_RECLAIM : KMALLOC_NORMAL;
> #else
> if (likely((flags & (__GFP_DMA | __GFP_RECLAIMABLE)) == 0))
> return KMALLOC_NORMAL;
> return flags & __GFP_DMA ? KMALLOC_DMA : KMALLOC_RECLAIM;
> #endif
> }
OK that's probably the most straightforward to follow, thanks.
Note that for CONFIG_ZONE_DMA=n the result is identical to original code and
all other attempts. flags & __GFP_DMA is converted to 1/0 index without branches
or cmovs or whatnot.
----8<----