All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/defines.h"
37 #include <cstddef>
38 #include <cstdint>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
44 
52 inline size_t
53 ArchAlignMemorySize(size_t nBytes) {
54  return (nBytes + 7) & (~0x7);
55 }
56 
63 #define ARCH_MAX_ALIGNMENT_INCREASE 7
64 
70 inline void *
71 ArchAlignMemory(void *base)
72 {
73  return reinterpret_cast<void *>
74  ((reinterpret_cast<uintptr_t>(base) + 7) & ~0x7);
75 }
76 
80 #if defined(ARCH_OS_DARWIN) && defined(ARCH_CPU_ARM)
81 #define ARCH_CACHE_LINE_SIZE 128
82 #else
83 #define ARCH_CACHE_LINE_SIZE 64
84 #endif
85 
87 
88 PXR_NAMESPACE_CLOSE_SCOPE
89 
90 #endif // PXR_BASE_ARCH_ALIGN_H
void * ArchAlignMemory(void *base)
Align memory to the next &quot;best&quot; alignment value.
Definition: align.h:71
size_t ArchAlignMemorySize(size_t nBytes)
Return suitably aligned memory size.
Definition: align.h:53