| 7 | #define CPU_ALIGNMENT (16) |
| 8 | |
| 9 | static 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 | |
| 24 | static void cpu_aligned_free(void* ptr) { |
| 25 | void** raw_ptr = ((void**)(ptr))[-1]; |
nothing calls this directly
no test coverage detected