tech-userlevel archive

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

Re: 64-bit masks

On Fri, Nov 27, 2009 at 02:06:38PM -0000, Sad Clouds wrote:
> Hi I'm writing a shared library and have a two part question:
> 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;

Adding my tuppence... ~(uint64_t)0

Or, for true portability (even then assuming 'long' is 32bit):
#define CONST64(u,l) ((uint64_t)(u) << 16 | (l))
then use: CONST64(0xfffffffful,0xfffffffful)

> 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.


If you want a fast way of finding a free slot, then you might
want to use a freelist, eg allocate a char[64] array and use a zero
to mean allocated, non-zero free - with the value that of the next
free item, 0xff meaning no more free.

The 64 byte map may well generate faster code, even for storing just
0 and 1. Especially true on systems that do not have native 64bit support.


David Laight:

Home | Main Index | Thread Index | Old Index