lkml.org 
[lkml]   [2018]   [Oct]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: Question on FIELD_PREP() for static array
From
Date
On Wed, 2018-10-10 at 18:16 +0100, John Garry wrote:
> (to: get_maintainers -f include/linux/bitfield.h)
>
> Hi,
>
> I would like to use FIELD_PREP() macro for assigning a static array,
> like this:
> function()
> {
> static u32 val[2] = {FIELD_PREP(GENMASK_ULL(10, 0), 5), 0};
>
> }
>
> However the compiler complains of non-const expression:
> ./include/linux/bitfield.h:88:2: error: initializer element is not constant
> ({ \
>
> Specifically it doesn't like the __BF_FIELD_CHECK() in FIELD_PREP().
>
> Any ideas on compiler trickery we could do with the FIELD_PREP()
> definition to avoid this issue (i.e. enforce the check but only use the
> constant value)?

Perhaps __bf_shf should not use __builtin_ffsll.

As mask is known constant, maybe expand the test
in-place with some switch/case.


\
 
 \ /
  Last update: 2018-10-10 19:34    [W:0.045 / U:1.436 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site