[sr-dev] git:master:0683df11: mem: TLSF bit ops cleanup / 64 bits improvement

Camille Oudot camille.oudot at orange.com
Tue Oct 25 11:34:52 CEST 2016


Module: kamailio
Branch: master
Commit: 0683df11e319aa3db45cd9b18af3a3c3b02088a8
URL: https://github.com/kamailio/kamailio/commit/0683df11e319aa3db45cd9b18af3a3c3b02088a8

Author: Camille Oudot <camille.oudot at orange.com>
Committer: Camille Oudot <camille.oudot at orange.com>
Date: 2016-10-25T11:32:35+02:00

mem: TLSF bit ops cleanup / 64 bits improvement

- remove unsupproted compilers
- use 64 bits __builtin_clzl() instead of twice 32 bits __builtin_clz()

---

Modified: mem/tlsf_malloc_bits.h

---

Diff:  https://github.com/kamailio/kamailio/commit/0683df11e319aa3db45cd9b18af3a3c3b02088a8.diff
Patch: https://github.com/kamailio/kamailio/commit/0683df11e319aa3db45cd9b18af3a3c3b02088a8.patch

---

diff --git a/mem/tlsf_malloc_bits.h b/mem/tlsf_malloc_bits.h
index 3be2579..29c783d 100644
--- a/mem/tlsf_malloc_bits.h
+++ b/mem/tlsf_malloc_bits.h
@@ -37,6 +37,8 @@
 /*
 ** gcc 3.4 and above have builtin support, specialized for architecture.
 ** Some compilers masquerade as gcc; patchlevel test filters them out.
+**
+** Note: clang is compatible with GCC builtins and will also define those macros
 */
 #if defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \
 	&& defined (__GNUC_PATCHLEVEL__)
@@ -52,78 +54,13 @@ tlsf_decl int tlsf_fls(unsigned int word)
 	return bit - 1;
 }
 
-#elif defined (_MSC_VER) && (_MSC_VER >= 1400) && (defined (_M_IX86) || defined (_M_X64))
-/* Microsoft Visual C++ support on x86/X64 architectures. */
-
-#include <intrin.h>
-
-#pragma intrinsic(_BitScanReverse)
-#pragma intrinsic(_BitScanForward)
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
-	unsigned long index;
-	return _BitScanReverse(&index, word) ? index : -1;
-}
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
-	unsigned long index;
-	return _BitScanForward(&index, word) ? index : -1;
-}
-
-#elif defined (_MSC_VER) && defined (_M_PPC)
-/* Microsoft Visual C++ support on PowerPC architectures. */
-
-#include <ppcintrinsics.h>
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
-	const int bit = 32 - _CountLeadingZeros(word);
-	return bit - 1;
-}
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
-	const unsigned int reverse = word & (~word + 1);
-	const int bit = 32 - _CountLeadingZeros(reverse);
-	return bit - 1;
-}
-
-#elif defined (__ARMCC_VERSION)
-/* RealView Compilation Tools for ARM */
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
-	const unsigned int reverse = word & (~word + 1);
-	const int bit = 32 - __clz(reverse);
-	return bit - 1;
-}
-
-tlsf_decl int tlsf_fls(unsigned int word)
-{
-	const int bit = word ? 32 - __clz(word) : 0;
-	return bit - 1;
-}
-
-#elif defined (__ghs__)
-/* Green Hills support for PowerPC */
-
-#include <ppc_ghs.h>
-
-tlsf_decl int tlsf_ffs(unsigned int word)
-{
-	const unsigned int reverse = word & (~word + 1);
-	const int bit = 32 - __CLZ32(reverse);
-	return bit - 1;
-}
-
-tlsf_decl int tlsf_fls(unsigned int word)
+#if defined (TLSF_64BIT)
+tlsf_decl int tlsf_fls_sizet(size_t size)
 {
-	const int bit = word ? 32 - __CLZ32(word) : 0;
+	const int bit = size ? 64 - __builtin_clzl(size) : 0;
 	return bit - 1;
 }
-
+#endif
 #else
 /* Fall back to generic implementation. */
 
@@ -152,9 +89,6 @@ tlsf_decl int tlsf_fls(unsigned int word)
 	return tlsf_fls_generic(word) - 1;
 }
 
-#endif
-
-/* Possibly 64-bit version of tlsf_fls. */
 #if defined (TLSF_64BIT)
 tlsf_decl int tlsf_fls_sizet(size_t size)
 {
@@ -171,7 +105,12 @@ tlsf_decl int tlsf_fls_sizet(size_t size)
 	}
 	return bits;
 }
-#else
+#endif /* defined (TLSF_64BIT) */
+
+#endif /* GNUC */
+
+
+#if !defined (TLSF_64BIT)
 #define tlsf_fls_sizet tlsf_fls
 #endif
 




More information about the sr-dev mailing list