tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: 64-bit masks



Hello,

Sad Clouds <cryintothebluesky%googlemail.com@localhost> wrote:
> 1. What is the correct (portable?) way of specifying 64-bit constants?
> 
> If I need a 64-bit constant set to all 1s, will the following work on all  
> systems
> 
> unit64_t num = 0xffffffffffffffffULL;

I would use ~0ULL.

> 2. I have an array of 64 objects that I need to keep track of. I keep  
> their state (i.e. busy/free) in a 64-bit mask, 1 for busy, 0 for free.
> 
> unit64_t state;

How about uint32_t state[2]; ?  To mark/unmark bit, it would be a matter
of shifting and masking.  In a case you would want to use ffs()/ffs32(),
popcount(), atomic operations or similar routines - it might be better.

-- 
Mindaugas


Home | Main Index | Thread Index | Old Index