1 : // Copyright 2014 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Internal implementations for align.h. Not meant to be included directly.
16 :
17 : #ifndef SYZYGY_COMMON_ALIGN_IMPL_H_
18 : #define SYZYGY_COMMON_ALIGN_IMPL_H_
19 :
20 : namespace common {
21 :
22 E : template<typename T> bool IsPowerOfTwo(const T* pointer) {
23 E : return IsPowerOfTwo(reinterpret_cast<uintptr_t>(pointer));
24 E : }
25 :
26 E : template<typename T> T* AlignUp(T* pointer, size_t alignment) {
27 : return reinterpret_cast<T*>(AlignUp(
28 E : reinterpret_cast<uintptr_t>(pointer), alignment));
29 E : }
30 :
31 E : template<typename T> const T* AlignUp(const T* pointer, size_t alignment) {
32 : return reinterpret_cast<const T*>(AlignUp(
33 E : reinterpret_cast<uintptr_t>(pointer), alignment));
34 E : }
35 :
36 E : template<typename T> T* AlignDown(T* pointer, size_t alignment) {
37 : return reinterpret_cast<T*>(AlignDown(
38 E : reinterpret_cast<uintptr_t>(pointer), alignment));
39 E : }
40 :
41 E : template<typename T> const T* AlignDown(const T* pointer, size_t alignment) {
42 : return reinterpret_cast<const T*>(AlignDown(
43 E : reinterpret_cast<uintptr_t>(pointer), alignment));
44 E : }
45 :
46 E : template<typename T> bool IsAligned(const T* pointer, size_t alignment) {
47 E : return IsAligned(reinterpret_cast<uintptr_t>(pointer), alignment);
48 E : }
49 :
50 : template<typename T> size_t GetAlignment(const T* pointer) {
51 : return GetAlignment(reinterpret_cast<uintptr_t>(pointer));
52 : }
53 :
54 : } // namespace common
55 :
56 : #endif // SYZYGY_COMMON_ALIGN_IMPL_H_
|