-
Notifications
You must be signed in to change notification settings - Fork 71
/
align.h
46 lines (38 loc) · 1.09 KB
/
align.h
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
#pragma once
#ifndef ZIMG_ALIGN_H_
#define ZIMG_ALIGN_H_
namespace zimg {
/**
* 64-byte alignment allows the use of instructions up to AVX-512.
*/
#if defined(ZIMG_X86)
constexpr int ALIGNMENT = 64;
constexpr int ALIGNMENT_RELAXED = 32;
#elif defined(ZIMG_ARM)
constexpr int ALIGNMENT = 16;
constexpr int ALIGNMENT_RELAXED = 16;
#else
constexpr int ALIGNMENT = alignof(long double);
constexpr int ALIGNMENT_RELAXED = alignof(long double);
#endif
/**
* Round up the argument x to the nearest multiple of n.
* x must be non-negative and n must be positive and power-of-2.
*/
template <class T>
constexpr T ceil_n(T x, unsigned n) { return (x + (n - 1)) & ~static_cast<T>(n - 1); }
/**
* Round down the argument x to the nearest multiple of n.
* x must be non-negative and n must be positive and power-of-2.
*/
template <class T>
constexpr T floor_n(T x, unsigned n) { return x & ~static_cast<T>(n - 1); }
/**
* Alignment in units of object count.
*
* @tparam T type of object
*/
template <class T>
constexpr unsigned AlignmentOf = ALIGNMENT / sizeof(T);
} // namespace zimg
#endif // ZIMG_ALIGN_H_