diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2011-12-23 01:11:55 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2011-12-23 11:29:10 +0100 |
commit | c09fdea2c0f7fd4c27b029a3c4b76bb161f63dca (patch) | |
tree | 757f2264adabe4824ab0c246de5baed8cb14fa74 /common/tlsfbits.h | |
parent | 5d96cda9449cb6ac80b768856e5ab8255ba9502e (diff) | |
download | barebox-c09fdea2c0f7fd4c27b029a3c4b76bb161f63dca.tar.gz barebox-c09fdea2c0f7fd4c27b029a3c4b76bb161f63dca.tar.xz |
tlsf: remove unused stuff from tlsfbits.h
Also, as this file is locally used by the tlsf implementation,
move this file to common.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/tlsfbits.h')
-rw-r--r-- | common/tlsfbits.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/common/tlsfbits.h b/common/tlsfbits.h new file mode 100644 index 0000000000..93466e46a8 --- /dev/null +++ b/common/tlsfbits.h @@ -0,0 +1,55 @@ +#ifndef INCLUDED_tlsfbits +#define INCLUDED_tlsfbits + +#include <linux/bitops.h> + +/* +** 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) +tlsf_decl 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 |