Loading...
Searching...
No Matches
align.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_BASE_ARCH_ALIGN_H
25#define PXR_BASE_ARCH_ALIGN_H
26
30
31#if !defined(__cplusplus)
32#error This include file can only be included in C++ programs.
33#endif
34
35#include "pxr/pxr.h"
36#include "pxr/base/arch/api.h"
37#include "pxr/base/arch/defines.h"
38#include <cstddef>
39#include <cstdint>
40
41PXR_NAMESPACE_OPEN_SCOPE
42
45
53inline size_t
54ArchAlignMemorySize(size_t nBytes) {
55 return (nBytes + 7) & (~0x7);
56}
57
64#define ARCH_MAX_ALIGNMENT_INCREASE 7
65
71inline void *
72ArchAlignMemory(void *base)
73{
74 return reinterpret_cast<void *>
75 ((reinterpret_cast<uintptr_t>(base) + 7) & ~0x7);
76}
77
81#if defined(ARCH_OS_DARWIN) && defined(ARCH_CPU_ARM)
82#define ARCH_CACHE_LINE_SIZE 128
83#else
84#define ARCH_CACHE_LINE_SIZE 64
85#endif
86
88ARCH_API
89void *
90ArchAlignedAlloc(size_t alignment, size_t size);
91
93ARCH_API
94void
95ArchAlignedFree(void* ptr);
96
98
99PXR_NAMESPACE_CLOSE_SCOPE
100
101#endif // PXR_BASE_ARCH_ALIGN_H
void * ArchAlignMemory(void *base)
Align memory to the next "best" alignment value.
Definition: align.h:72
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:54