RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
align.hpp
Go to the documentation of this file.
1 
11 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
12 // Copyright (c) Lawrence Livermore National Security, LLC and other
13 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
14 // files for dates and other details. No copyright assignment is required
15 // to contribute to RAJA.
16 //
17 // SPDX-License-Identifier: (BSD-3-Clause)
18 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
19 
20 #ifndef RAJA_ALIGN_HPP
21 #define RAJA_ALIGN_HPP
22 
23 #include "RAJA/config.hpp"
24 
25 namespace RAJA
26 {
27 
28 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
29 // Taken from libc++
30 // See libc++ license in docs/Licenses/libc++ License
31 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
32 RAJA_INLINE
33 void* align(size_t alignment, size_t size, void*& ptr, size_t& space)
34 {
35 
36 #ifdef RAJA_COMPILER_MSVC
37 #pragma warning(disable : 4146) // Force msvc to ignore subtracting from signed
38  // number warning
39 #endif
40  void* r = nullptr;
41  if (size <= space)
42  {
43  char* p1 = static_cast<char*>(ptr);
44  char* p2 = reinterpret_cast<char*>(
45  reinterpret_cast<size_t>(p1 + (static_cast<ptrdiff_t>(alignment) - 1)) &
46  -alignment);
47  size_t d = static_cast<size_t>(p2 - p1);
48  if (d <= space - size)
49  {
50  r = p2;
51  ptr = r;
52  space -= d;
53  }
54  }
55  return r;
56 
57 #ifdef RAJA_COMPILER_MSVC
58 #pragma warning(default : 4146) // Force msvc to ignore subtracting from signed
59  // number warning
60 #endif
61 }
62 
63 } // end namespace RAJA
64 
65 #endif
Definition: AlignedRangeIndexSetBuilders.cpp:35
RAJA_INLINE void * align(size_t alignment, size_t size, void *&ptr, size_t &space)
Definition: align.hpp:33