> > On Sat, 21 Dec 2019 16:07:23 +0000 > Honnappa Nagarahalli <honnappa.nagaraha...@arm.com> wrote: > > > Converting these into macros will help remove the size based duplication of > APIs. I came up with the following macro: > > > > #define RTE_GET_BIT(nr, var, ret, memorder) \ ({ \ > > if (sizeof(var) == sizeof(uint32_t)) { \ > > uint32_t mask1 = 1U << (nr)%32; \ > > ret = __atomic_load_n(&var, (memorder)) & mask1;\ > > } \ > > else {\ > > uint64_t mask2 = 1UL << (nr)%64;\ > > ret = __atomic_load_n(&var, (memorder)) & mask2;\ > > } \ > > }) > > > Follow on if you want to do it as macros, then use typeof() to make the mask > any size. Yes, that makes it much simple #define RTE_GET_BIT(nr, var, ret, memorder) \ ({ \ typeof(var) mask; \ if (sizeof(var) == sizeof(uint32_t)) { \ mask = 1U << (nr)%32; \ } else {\ mask = 1UL << (nr)%64;\ } \ ret = __atomic_load_n(&var, (memorder)) & mask;\ })
- Re: [dpdk-dev] [PATCH v6 1/6] lib/eal: i... Honnappa Nagarahalli
- Re: [dpdk-dev] [PATCH v6 1/6] lib/ea... Stephen Hemminger
- Re: [dpdk-dev] [PATCH v6 1/6] l... Honnappa Nagarahalli
- Re: [dpdk-dev] [PATCH v6 1/... Stephen Hemminger
- Re: [dpdk-dev] [PATCH v6 1/... Gavin Hu
- Re: [dpdk-dev] [PATCH v6 1/... Honnappa Nagarahalli
- Re: [dpdk-dev] [PATCH v6 1/... Stephen Hemminger
- Re: [dpdk-dev] [PATCH v6 1/... Honnappa Nagarahalli
- Re: [dpdk-dev] [PATCH v6 1/... Honnappa Nagarahalli
- Re: [dpdk-dev] [PATCH v6 1/6] lib/ea... Stephen Hemminger
- Re: [dpdk-dev] [PATCH v6 1/6] l... Honnappa Nagarahalli
- Re: [dpdk-dev] [PATCH v6 1/6] lib/ea... Jerin Jacob
- [dpdk-dev] [PATCH v6 3/6] net/axgbe: use common ... Joyce Kong
- [dpdk-dev] [PATCH v6 4/6] net/bnx2x: use common ... Joyce Kong
- [dpdk-dev] [PATCH v6 5/6] net/qede: use common r... Joyce Kong
- [dpdk-dev] [PATCH v6 6/6] net/hinic: use common ... Joyce Kong
- Re: [dpdk-dev] [PATCH v6 0/6] implement common rte bi... Gavin Hu
- Re: [dpdk-dev] [PATCH v6 0/6] implement common rte bi... David Marchand