All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
align.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_ARCH_ALIGN_H
8#define PXR_BASE_ARCH_ALIGN_H
9
13
14#if !defined(__cplusplus)
15#error This include file can only be included in C++ programs.
16#endif
17
18#include "pxr/pxr.h"
19#include "pxr/base/arch/api.h"
20#include "pxr/base/arch/defines.h"
21#include <cstddef>
22#include <cstdint>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
28
36inline size_t
37ArchAlignMemorySize(size_t nBytes) {
38 return (nBytes + 7) & (~0x7);
39}
40
47#define ARCH_MAX_ALIGNMENT_INCREASE 7
48
54inline void *
55ArchAlignMemory(void *base)
56{
57 return reinterpret_cast<void *>
58 ((reinterpret_cast<uintptr_t>(base) + 7) & ~0x7);
59}
60
64#if defined(ARCH_OS_DARWIN) && defined(ARCH_CPU_ARM)
65#define ARCH_CACHE_LINE_SIZE 128
66#else
67#define ARCH_CACHE_LINE_SIZE 64
68#endif
69
71ARCH_API
72void *
73ArchAlignedAlloc(size_t alignment, size_t size);
74
76ARCH_API
77void
78ArchAlignedFree(void* ptr);
79
81
82PXR_NAMESPACE_CLOSE_SCOPE
83
84#endif // PXR_BASE_ARCH_ALIGN_H
void * ArchAlignMemory(void *base)
Align memory to the next "best" alignment value.
Definition: align.h:55
ARCH_API void * ArchAlignedAlloc(size_t alignment, size_t size)
Aligned memory allocation.
ARCH_API void ArchAlignedFree(void *ptr)
Free memory allocated by ArchAlignedAlloc.
size_t ArchAlignMemorySize(size_t nBytes)
Return suitably aligned memory size.
Definition: align.h:37