Pixar Arch
 
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 "./api.h"
19#include "./defines.h"
20#include <cstddef>
21#include <cstdint>
22
23namespace pxr {
24
32inline size_t
33ArchAlignMemorySize(size_t nBytes) {
34 return (nBytes + 7) & (~0x7);
35}
36
43#define ARCH_MAX_ALIGNMENT_INCREASE 7
44
50inline void *
51ArchAlignMemory(void *base)
52{
53 return reinterpret_cast<void *>
54 ((reinterpret_cast<uintptr_t>(base) + 7) & ~0x7);
55}
56
60#if defined(ARCH_OS_DARWIN) && defined(ARCH_CPU_ARM)
61#define ARCH_CACHE_LINE_SIZE 128
62#else
63#define ARCH_CACHE_LINE_SIZE 64
64#endif
65
67ARCH_API
68void *
69ArchAlignedAlloc(size_t alignment, size_t size);
70
72ARCH_API
73void
74ArchAlignedFree(void* ptr);
75
76} // namespace pxr
77
78#endif // PXR_ARCH_ALIGN_H
ARCH_API void * ArchAlignedAlloc(size_t alignment, size_t size)
Aligned memory allocation.
size_t ArchAlignMemorySize(size_t nBytes)
Return suitably aligned memory size.
Definition align.h:33
ARCH_API void ArchAlignedFree(void *ptr)
Free memory allocated by ArchAlignedAlloc.
void * ArchAlignMemory(void *base)
Align memory to the next "best" alignment value.
Definition align.h:51