1 : // Copyright 2011 Google Inc.
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 : // Utility functions to align and test alignment.
16 :
17 : #ifndef SYZYGY_COMMON_ALIGN_H_
18 : #define SYZYGY_COMMON_ALIGN_H_
19 :
20 m : namespace common {
21 :
22 : // @returns true iff @p value is a power of two.
23 m : bool IsPowerOfTwo(size_t value);
24 :
25 : // @param value the value to round up.
26 : // @param alignment the alignment boundary to round @p value up to.
27 : // @pre alignment != 0.
28 : // @returns @p value rounded up to the nearest higher multiple of @p alignment.
29 m : size_t AlignUp(size_t value, size_t alignment);
30 :
31 : // @param value the value to round up.
32 : // @param alignment the alignment boundary to round @p value up to.
33 : // @pre alignment != 0.
34 : // @returns @p value rounded down to the nearest lower multiple of @p alignment.
35 m : size_t AlignDown(size_t value, size_t alignment);
36 :
37 : // @param value the value to test.
38 : // @param alignment the alignment boundary to test.
39 : // @pre alignment != 0.
40 : // @returns true iff value is an even multiple of alignment.
41 m : bool IsAligned(size_t value, size_t alignment);
42 :
43 m : } // namespace common
44 :
45 : #endif // SYZYGY_COMMON_ALIGN_H_
|