2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2015-02-14 17:29:47 +05:00
|
|
|
|
2024-12-26 17:53:56 +01:00
|
|
|
#pragma once
|
2015-02-14 17:29:47 +05:00
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
#include <cstddef>
|
2015-02-19 22:17:42 +05:00
|
|
|
|
2015-02-14 17:29:47 +05:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2018-01-18 21:06:35 +01:00
|
|
|
/* Minimum alignment needed by all CPU native data types (SSE, AVX). */
|
2024-12-26 17:53:59 +01:00
|
|
|
#define MIN_ALIGNMENT_CPU_DATA_TYPES 16 // NOLINT
|
2018-01-18 21:06:35 +01:00
|
|
|
|
2015-02-14 17:29:47 +05:00
|
|
|
/* Allocate block of size bytes at least aligned to a given value. */
|
2025-01-01 18:15:54 +01:00
|
|
|
void *util_aligned_malloc(const size_t size, const int alignment);
|
2015-02-14 17:29:47 +05:00
|
|
|
|
|
|
|
|
/* Free memory allocated by util_aligned_malloc. */
|
2025-01-09 12:04:08 +01:00
|
|
|
void util_aligned_free(void *ptr, const size_t size);
|
2015-02-14 17:29:47 +05:00
|
|
|
|
2019-05-02 12:40:24 +02:00
|
|
|
/* Aligned new operator. */
|
2019-05-14 15:05:24 +02:00
|
|
|
template<typename T, typename... Args> T *util_aligned_new(Args... args)
|
2019-05-02 12:40:24 +02:00
|
|
|
{
|
|
|
|
|
void *mem = util_aligned_malloc(sizeof(T), alignof(T));
|
2019-05-14 15:05:24 +02:00
|
|
|
return new (mem) T(args...);
|
2019-05-02 12:40:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-03 17:42:08 +02:00
|
|
|
template<typename T> void util_aligned_delete(T *t)
|
|
|
|
|
{
|
|
|
|
|
if (t) {
|
|
|
|
|
t->~T();
|
2025-01-09 12:04:08 +01:00
|
|
|
util_aligned_free(t, sizeof(T));
|
2019-05-03 17:42:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-14 17:29:47 +05:00
|
|
|
CCL_NAMESPACE_END
|