mm/mm_heap: using LOG2_CEIL to generate MM_MIN_SHIFT at compile time
#include <nuttx/mutex.h>
#include <nuttx/fs/procfs.h>
+#include <nuttx/lib/math32.h>
#include <assert.h>
#include <execinfo.h>
* minor performance losses.
*/
+#define MM_MIN_SHIFT LOG2_CEIL(sizeof(struct mm_freenode_s))
#if defined(CONFIG_MM_SMALL) && UINTPTR_MAX <= UINT32_MAX
-/* Two byte offsets; Pointers may be 2 or 4 bytes;
- * sizeof(struct mm_freenode_s) is 8 or 12 bytes.
- * REVISIT: We could do better on machines with 16-bit addressing.
- */
-
-# define MM_MIN_SHIFT_ ( 4) /* 16 bytes */
# define MM_MAX_SHIFT (15) /* 32 Kb */
-
-#elif defined(CONFIG_HAVE_LONG_LONG)
-/* Four byte offsets; Pointers may be 4 or 8 bytes
- * sizeof(struct mm_freenode_s) is 16 or 24 bytes.
- */
-
-# if UINTPTR_MAX <= UINT32_MAX
-# define MM_MIN_SHIFT_ ( 4) /* 16 bytes */
-# elif UINTPTR_MAX <= UINT64_MAX
-# define MM_MIN_SHIFT_ ( 5) /* 32 bytes */
-# endif
-# define MM_MAX_SHIFT (22) /* 4 Mb */
-
#else
-/* Four byte offsets; Pointers must be 4 bytes.
- * sizeof(struct mm_freenode_s) is 16 bytes.
- */
-
-# define MM_MIN_SHIFT_ ( 4) /* 16 bytes */
# define MM_MAX_SHIFT (22) /* 4 Mb */
#endif
#if CONFIG_MM_BACKTRACE == 0
-# define MM_MIN_SHIFT (MM_MIN_SHIFT_ + 1)
# define MM_ADD_BACKTRACE(heap, ptr) \
do \
{ \
} \
while (0)
#elif CONFIG_MM_BACKTRACE > 0
-# define MM_MIN_SHIFT (MM_MIN_SHIFT_ + 2)
# define MM_ADD_BACKTRACE(heap, ptr) \
do \
{ \
while (0)
#else
# define MM_ADD_BACKTRACE(heap, ptr)
-# define MM_MIN_SHIFT MM_MIN_SHIFT_
#endif
/* All other definitions derive from these two */
@@ -185,9 +160,6 @@ struct mm_allocnode_s
mmsize_t preceding; /* Size of the preceding chunk */
};
-static_assert(SIZEOF_MM_ALLOCNODE <= MM_MIN_CHUNK,
- "Error size for struct mm_allocnode_s\n");
-
/* This describes a free chunk */
struct mm_freenode_s
@@ -204,6 +176,9 @@ struct mm_freenode_s
FAR struct mm_freenode_s *blink;
};
+static_assert(SIZEOF_MM_ALLOCNODE <= MM_MIN_CHUNK,
+ "Error size for struct mm_allocnode_s\n");
+
static_assert(SIZEOF_MM_FREENODE <= MM_MIN_CHUNK,
"Error size for struct mm_freenode_s\n");
