Pixar Arch 0.25.8
Loading...
Searching...
No Matches
align.h
Go to the documentation of this file.
1// Copyright 2016 Pixar
2//
3// Licensed under the terms set forth in the LICENSE.txt file available at
4// https://openusd.org/license.
5//
6// Modified by Jeremy Retailleau.
7
8#ifndef PXR_ARCH_ALIGN_H
9#define PXR_ARCH_ALIGN_H
10
13
14#if !defined(__cplusplus)
15#error This include file can only be included in C++ programs.
16#endif
17
18#include "pxr/arch/pxr.h"
19#include "pxr/arch/api.h"
20#include "pxr/arch/defines.h"
21#include <cstddef>
22#include <cstdint>
23
24ARCH_NAMESPACE_OPEN_SCOPE
25
33inline size_t
34ArchAlignMemorySize(size_t nBytes) {
35 return (nBytes + 7) & (~0x7);
36}
37
44#define ARCH_MAX_ALIGNMENT_INCREASE 7
45
51inline void *
52ArchAlignMemory(void *base)
53{
54 return reinterpret_cast<void *>
55 ((reinterpret_cast<uintptr_t>(base) + 7) & ~0x7);
56}
57
61#if defined(ARCH_OS_DARWIN) && defined(ARCH_CPU_ARM)
62#define ARCH_CACHE_LINE_SIZE 128
63#else
64#define ARCH_CACHE_LINE_SIZE 64
65#endif
66
68ARCH_API
69void *
70ArchAlignedAlloc(size_t alignment, size_t size);
71
73ARCH_API
74void
75ArchAlignedFree(void* ptr);
76
77ARCH_NAMESPACE_CLOSE_SCOPE
78
79#endif // PXR_ARCH_ALIGN_H
size_t ArchAlignMemorySize(size_t nBytes)
Return suitably aligned memory size.
Definition align.h:34
void ArchAlignedFree(void *ptr)
Free memory allocated by ArchAlignedAlloc.
void * ArchAlignMemory(void *base)
Align memory to the next "best" alignment value.
Definition align.h:52
void * ArchAlignedAlloc(size_t alignment, size_t size)
Aligned memory allocation.