MCPcopy Create free account
hub / github.com/MegEngine/MegCC / cpu_aligned_malloc

Function cpu_aligned_malloc

runtime/src/device.c:9–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#define CPU_ALIGNMENT (16)
8
9static void* cpu_aligned_malloc(size_t size) {
10 if (size == 0) {
11 return NULL;
12 }
13 void* raw_ptr = tinynn_malloc(size + sizeof(void*) + CPU_ALIGNMENT);
14 if (!raw_ptr) {
15 LOG_ERROR("malloc memory fail.\n");
16 return NULL;
17 }
18 void** ptr =
19 (void**)(((size_t)raw_ptr + sizeof(void*) + CPU_ALIGNMENT - 1) & (-CPU_ALIGNMENT));
20 ptr[-1] = raw_ptr;
21 return ptr;
22}
23
24static void cpu_aligned_free(void* ptr) {
25 void** raw_ptr = ((void**)(ptr))[-1];

Callers

nothing calls this directly

Calls 1

tinynn_mallocFunction · 0.85

Tested by

no test coverage detected