barebox/common/tlsfbits.h
Sascha Hauer e617c9b821 tlsf malloc: enable 64bit support on 64bit architectures
On 64bit architectures TLSF_64BIT should be defined. Decide that
depending on the CONFIG_64BIT symbol. When 64bit support is enabled
all allocations will be aligned to 8 byte boundaries which is necessary
for architectures that do not support unaligned accesses or have
a performance penalty for unaligned accesses.
Also changes the undefined tlsf_decl to 'static'.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-05-22 09:40:31 +02:00

60 lines
1.3 KiB
C

#ifndef INCLUDED_tlsfbits
#define INCLUDED_tlsfbits
#include <linux/bitops.h>
#ifdef CONFIG_64BIT
#define TLSF_64BIT
#endif
/*
** Architecture-specific bit manipulation routines.
**
** TLSF achieves O(1) cost for malloc and free operations by limiting
** the search for a free block to a free list of guaranteed size
** adequate to fulfill the request, combined with efficient free list
** queries using bitmasks and architecture-specific bit-manipulation
** routines.
**
** Most modern processors provide instructions to count leading zeroes
** in a word, find the lowest and highest set bit, etc. These
** specific implementations will be used when available, falling back
** to a reasonably efficient generic implementation.
**
** NOTE: TLSF spec relies on ffs/fls returning value 0..31.
** ffs/fls return 1-32 by default, returning 0 for error.
*/
static int tlsf_ffs(unsigned int word)
{
return ffs(word) - 1;
}
static int tlsf_fls(unsigned int word)
{
return fls(word) - 1;
}
/* Possibly 64-bit version of tlsf_fls. */
#if defined (TLSF_64BIT)
static int tlsf_fls_sizet(size_t size)
{
int high = (int)(size >> 32);
int bits = 0;
if (high)
{
bits = 32 + tlsf_fls(high);
}
else
{
bits = tlsf_fls((int)size & 0xffffffff);
}
return bits;
}
#else
#define tlsf_fls_sizet tlsf_fls
#endif
#endif