-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathalign.hpp
More file actions
60 lines (53 loc) · 1.53 KB
/
align.hpp
File metadata and controls
60 lines (53 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*!
******************************************************************************
*
* \file
*
* \brief RAJA header file containing an implementation of std align.
*
******************************************************************************
*/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Copyright (c) 2016-18, Lawrence Livermore National Security, LLC.
//
// Produced at the Lawrence Livermore National Laboratory
//
// LLNL-CODE-689114
//
// All rights reserved.
//
// This file is part of RAJA.
//
// For details about use and distribution, please read RAJA/LICENSE.
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
#ifndef COMBRAJA_ALIGN_HPP
#define COMBRAJA_ALIGN_HPP
//#include "RAJA/config.hpp"
#include "config.hpp"
#define COMBRAJA_INLINE inline
namespace COMBRAJA
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Taken from libc++
// See libc++ license in docs/Licenses/libc++ License
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
COMBRAJA_INLINE
void* align(size_t alignment, size_t size, void*& ptr, size_t& space)
{
void* r = nullptr;
if (size <= space) {
char* p1 = static_cast<char*>(ptr);
char* p2 = reinterpret_cast<char*>(
reinterpret_cast<size_t>(p1 + (alignment - 1)) & -alignment);
size_t d = static_cast<size_t>(p2 - p1);
if (d <= space - size) {
r = p2;
ptr = r;
space -= d;
}
}
return r;
}
} // end namespace COMBRAJA
#endif