MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_realloc_aligned

Function PyArray_realloc_aligned

numpy/random/include/aligned_malloc.h:9–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#define NPY_MEMALIGN 16 /* 16 for SSE2, 32 for AVX, 64 for Xeon Phi */
8
9static inline void *PyArray_realloc_aligned(void *p, size_t n)
10{
11 void *p1, **p2, *base;
12 size_t old_offs, offs = NPY_MEMALIGN - 1 + sizeof(void *);
13 if (NPY_UNLIKELY(p != NULL))
14 {
15 base = *(((void **)p) - 1);
16 if (NPY_UNLIKELY((p1 = PyMem_Realloc(base, n + offs)) == NULL))
17 return NULL;
18 if (NPY_LIKELY(p1 == base))
19 return p;
20 p2 = (void **)(((Py_uintptr_t)(p1) + offs) & ~(NPY_MEMALIGN - 1));
21 old_offs = (size_t)((Py_uintptr_t)p - (Py_uintptr_t)base);
22 memmove((void *)p2, ((char *)p1) + old_offs, n);
23 }
24 else
25 {
26 if (NPY_UNLIKELY((p1 = PyMem_Malloc(n + offs)) == NULL))
27 return NULL;
28 p2 = (void **)(((Py_uintptr_t)(p1) + offs) & ~(NPY_MEMALIGN - 1));
29 }
30 *(p2 - 1) = p1;
31 return (void *)p2;
32}
33
34static inline void *PyArray_malloc_aligned(size_t n)
35{

Callers 2

PyArray_malloc_alignedFunction · 0.85
PyArray_calloc_alignedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected