Blame jemalloc/include/jemalloc/internal/jemalloc_internal_types.h

Packit 345191
#ifndef JEMALLOC_INTERNAL_TYPES_H
Packit 345191
#define JEMALLOC_INTERNAL_TYPES_H
Packit 345191
Packit 345191
#include "jemalloc/internal/quantum.h"
Packit 345191
Packit 345191
/* Page size index type. */
Packit 345191
typedef unsigned pszind_t;
Packit 345191
Packit 345191
/* Size class index type. */
Packit 345191
typedef unsigned szind_t;
Packit 345191
Packit 345191
/* Processor / core id type. */
Packit 345191
typedef int malloc_cpuid_t;
Packit 345191
Packit 345191
/*
Packit 345191
 * Flags bits:
Packit 345191
 *
Packit 345191
 * a: arena
Packit 345191
 * t: tcache
Packit 345191
 * 0: unused
Packit 345191
 * z: zero
Packit 345191
 * n: alignment
Packit 345191
 *
Packit 345191
 * aaaaaaaa aaaatttt tttttttt 0znnnnnn
Packit 345191
 */
Packit 345191
#define MALLOCX_ARENA_BITS	12
Packit 345191
#define MALLOCX_TCACHE_BITS	12
Packit 345191
#define MALLOCX_LG_ALIGN_BITS	6
Packit 345191
#define MALLOCX_ARENA_SHIFT	20
Packit 345191
#define MALLOCX_TCACHE_SHIFT	8
Packit 345191
#define MALLOCX_ARENA_MASK \
Packit 345191
    (((1 << MALLOCX_ARENA_BITS) - 1) << MALLOCX_ARENA_SHIFT)
Packit 345191
/* NB: Arena index bias decreases the maximum number of arenas by 1. */
Packit 345191
#define MALLOCX_ARENA_LIMIT	((1 << MALLOCX_ARENA_BITS) - 1)
Packit 345191
#define MALLOCX_TCACHE_MASK \
Packit 345191
    (((1 << MALLOCX_TCACHE_BITS) - 1) << MALLOCX_TCACHE_SHIFT)
Packit 345191
#define MALLOCX_TCACHE_MAX	((1 << MALLOCX_TCACHE_BITS) - 3)
Packit 345191
#define MALLOCX_LG_ALIGN_MASK	((1 << MALLOCX_LG_ALIGN_BITS) - 1)
Packit 345191
/* Use MALLOCX_ALIGN_GET() if alignment may not be specified in flags. */
Packit 345191
#define MALLOCX_ALIGN_GET_SPECIFIED(flags)				\
Packit 345191
    (ZU(1) << (flags & MALLOCX_LG_ALIGN_MASK))
Packit 345191
#define MALLOCX_ALIGN_GET(flags)					\
Packit 345191
    (MALLOCX_ALIGN_GET_SPECIFIED(flags) & (SIZE_T_MAX-1))
Packit 345191
#define MALLOCX_ZERO_GET(flags)						\
Packit 345191
    ((bool)(flags & MALLOCX_ZERO))
Packit 345191
Packit 345191
#define MALLOCX_TCACHE_GET(flags)					\
Packit 345191
    (((unsigned)((flags & MALLOCX_TCACHE_MASK) >> MALLOCX_TCACHE_SHIFT)) - 2)
Packit 345191
#define MALLOCX_ARENA_GET(flags)					\
Packit 345191
    (((unsigned)(((unsigned)flags) >> MALLOCX_ARENA_SHIFT)) - 1)
Packit 345191
Packit 345191
/* Smallest size class to support. */
Packit 345191
#define TINY_MIN		(1U << LG_TINY_MIN)
Packit 345191
Packit 345191
#define LONG			((size_t)(1U << LG_SIZEOF_LONG))
Packit 345191
#define LONG_MASK		(LONG - 1)
Packit 345191
Packit 345191
/* Return the smallest long multiple that is >= a. */
Packit 345191
#define LONG_CEILING(a)							\
Packit 345191
	(((a) + LONG_MASK) & ~LONG_MASK)
Packit 345191
Packit 345191
#define SIZEOF_PTR		(1U << LG_SIZEOF_PTR)
Packit 345191
#define PTR_MASK		(SIZEOF_PTR - 1)
Packit 345191
Packit 345191
/* Return the smallest (void *) multiple that is >= a. */
Packit 345191
#define PTR_CEILING(a)							\
Packit 345191
	(((a) + PTR_MASK) & ~PTR_MASK)
Packit 345191
Packit 345191
/*
Packit 345191
 * Maximum size of L1 cache line.  This is used to avoid cache line aliasing.
Packit 345191
 * In addition, this controls the spacing of cacheline-spaced size classes.
Packit 345191
 *
Packit 345191
 * CACHELINE cannot be based on LG_CACHELINE because __declspec(align()) can
Packit 345191
 * only handle raw constants.
Packit 345191
 */
Packit 345191
#define LG_CACHELINE		6
Packit 345191
#define CACHELINE		64
Packit 345191
#define CACHELINE_MASK		(CACHELINE - 1)
Packit 345191
Packit 345191
/* Return the smallest cacheline multiple that is >= s. */
Packit 345191
#define CACHELINE_CEILING(s)						\
Packit 345191
	(((s) + CACHELINE_MASK) & ~CACHELINE_MASK)
Packit 345191
Packit 345191
/* Return the nearest aligned address at or below a. */
Packit 345191
#define ALIGNMENT_ADDR2BASE(a, alignment)				\
Packit 345191
	((void *)((uintptr_t)(a) & ((~(alignment)) + 1)))
Packit 345191
Packit 345191
/* Return the offset between a and the nearest aligned address at or below a. */
Packit 345191
#define ALIGNMENT_ADDR2OFFSET(a, alignment)				\
Packit 345191
	((size_t)((uintptr_t)(a) & (alignment - 1)))
Packit 345191
Packit 345191
/* Return the smallest alignment multiple that is >= s. */
Packit 345191
#define ALIGNMENT_CEILING(s, alignment)					\
Packit 345191
	(((s) + (alignment - 1)) & ((~(alignment)) + 1))
Packit 345191
Packit 345191
/* Declare a variable-length array. */
Packit 345191
#if __STDC_VERSION__ < 199901L
Packit 345191
#  ifdef _MSC_VER
Packit 345191
#    include <malloc.h>
Packit 345191
#    define alloca _alloca
Packit 345191
#  else
Packit 345191
#    ifdef JEMALLOC_HAS_ALLOCA_H
Packit 345191
#      include <alloca.h>
Packit 345191
#    else
Packit 345191
#      include <stdlib.h>
Packit 345191
#    endif
Packit 345191
#  endif
Packit 345191
#  define VARIABLE_ARRAY(type, name, count) \
Packit 345191
	type *name = alloca(sizeof(type) * (count))
Packit 345191
#else
Packit 345191
#  define VARIABLE_ARRAY(type, name, count) type name[(count)]
Packit 345191
#endif
Packit 345191
Packit 345191
#endif /* JEMALLOC_INTERNAL_TYPES_H */