Browse code

core/mem: removed tlsf_malloc_bits.h

- no longer needed after sync with v3.1

Daniel-Constantin Mierla authored on 06/04/2021 06:38:16
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,119 +0,0 @@
1
-#ifndef INCLUDED_tlsfbits
2
-#define INCLUDED_tlsfbits
3
-
4
-#if defined(__cplusplus)
5
-#define tlsf_decl inline
6
-#else
7
-#define tlsf_decl static
8
-#endif
9
-
10
-/*
11
-** Architecture-specific bit manipulation routines.
12
-**
13
-** TLSF achieves O(1) cost for malloc and free operations by limiting
14
-** the search for a free block to a free list of guaranteed size
15
-** adequate to fulfill the request, combined with efficient free list
16
-** queries using bitmasks and architecture-specific bit-manipulation
17
-** routines.
18
-**
19
-** Most modern processors provide instructions to count leading zeroes
20
-** in a word, find the lowest and highest set bit, etc. These
21
-** specific implementations will be used when available, falling back
22
-** to a reasonably efficient generic implementation.
23
-**
24
-** NOTE: TLSF spec relies on ffs/fls returning value 0..31.
25
-** ffs/fls return 1-32 by default, returning 0 for error.
26
-*/
27
-
28
-/*
29
-** Detect whether or not we are building for a 32- or 64-bit (LP/LLP)
30
-** architecture. There is no reliable portable method at compile-time.
31
-*/
32
-#if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) \
33
-	|| defined (_WIN64) || defined (__LP64__) || defined (__LLP64__)
34
-#define TLSF_64BIT
35
-#endif
36
-
37
-/*
38
-** gcc 3.4 and above have builtin support, specialized for architecture.
39
-** Some compilers masquerade as gcc; patchlevel test filters them out.
40
-**
41
-** Note: clang is compatible with GCC builtins and will also define those macros
42
-*/
43
-#if defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \
44
-	&& defined (__GNUC_PATCHLEVEL__)
45
-
46
-tlsf_decl int tlsf_ffs(unsigned int word)
47
-{
48
-	return __builtin_ffs(word) - 1;
49
-}
50
-
51
-tlsf_decl int tlsf_fls(unsigned int word)
52
-{
53
-	const int bit = word ? 32 - __builtin_clz(word) : 0;
54
-	return bit - 1;
55
-}
56
-
57
-#if defined (TLSF_64BIT)
58
-tlsf_decl int tlsf_fls_sizet(size_t size)
59
-{
60
-	const int bit = size ? 64 - __builtin_clzl(size) : 0;
61
-	return bit - 1;
62
-}
63
-#endif
64
-#else
65
-/* Fall back to generic implementation. */
66
-
67
-tlsf_decl int tlsf_fls_generic(unsigned int word)
68
-{
69
-	int bit = 32;
70
-
71
-	if (!word) bit -= 1;
72
-	if (!(word & 0xffff0000)) { word <<= 16; bit -= 16; }
73
-	if (!(word & 0xff000000)) { word <<= 8; bit -= 8; }
74
-	if (!(word & 0xf0000000)) { word <<= 4; bit -= 4; }
75
-	if (!(word & 0xc0000000)) { word <<= 2; bit -= 2; }
76
-	if (!(word & 0x80000000)) { word <<= 1; bit -= 1; }
77
-
78
-	return bit;
79
-}
80
-
81
-/* Implement ffs in terms of fls. */
82
-tlsf_decl int tlsf_ffs(unsigned int word)
83
-{
84
-	return tlsf_fls_generic(word & (~word + 1)) - 1;
85
-}
86
-
87
-tlsf_decl int tlsf_fls(unsigned int word)
88
-{
89
-	return tlsf_fls_generic(word) - 1;
90
-}
91
-
92
-#if defined (TLSF_64BIT)
93
-tlsf_decl int tlsf_fls_sizet(size_t size)
94
-{
95
-	int high = (int)(size >> 32);
96
-	int bits = 0;
97
-	if (high)
98
-	{
99
-		bits = 32 + tlsf_fls(high);
100
-	}
101
-	else
102
-	{
103
-		bits = tlsf_fls((int)size & 0xffffffff);
104
-
105
-	}
106
-	return bits;
107
-}
108
-#endif /* defined (TLSF_64BIT) */
109
-
110
-#endif /* GNUC */
111
-
112
-
113
-#if !defined (TLSF_64BIT)
114
-#define tlsf_fls_sizet tlsf_fls
115
-#endif
116
-
117
-#undef tlsf_decl
118
-
119
-#endif