aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/include/api/odp_align.h
blob: 6ec5a0a7ebbc20da43dc493e78dacc8521508198 (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* Copyright (c) 2013, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:	BSD-3-Clause
 */


/**
 * @file
 *
 * ODP alignments
 */

#ifndef ODP_ALIGN_H_
#define ODP_ALIGN_H_

#ifdef __cplusplus
extern "C" {
#endif

/** @addtogroup odp_compiler_optim
 *  Macros that allow cache line size configuration, check that
 *  alignment is a power of two etc.
 *  @{
 */

#ifdef __GNUC__

/* Checkpatch complains, but cannot use __aligned(size) for this purpose. */

/**
 * Defines type/struct/variable alignment in bytes
 */
#define ODP_ALIGNED(x) __attribute__((__aligned__(x)))

/**
 * Defines type/struct to be packed
 */
#define ODP_PACKED __attribute__((__packed__))

/**
 * Returns offset of member in type
 */
#define ODP_OFFSETOF(type, member) __builtin_offsetof(type, member)

/**
 * Returns sizeof member
 */
#define ODP_FIELD_SIZEOF(type, member) sizeof(((type *)0)->member)

#if defined __x86_64__ || defined __i386__

/** Cache line size */
#define ODP_CACHE_LINE_SIZE 64

#elif defined __arm__ || defined __aarch64__

/** Cache line size */
#define ODP_CACHE_LINE_SIZE 64

#elif defined __OCTEON__

/** Cache line size */
#define ODP_CACHE_LINE_SIZE 128

#elif defined __powerpc__

/** Cache line size */
#define ODP_CACHE_LINE_SIZE 64

#else
#error GCC target not found
#endif

#else
#error Non-gcc compatible compiler
#endif

/** Page size */
#define ODP_PAGE_SIZE       4096


/*
 * Round up
 */


/**
 * @internal
 * Round up pointer 'x' to alignment 'align'
 */
#define ODP_ALIGN_ROUNDUP_PTR(x, align)\
	((void *)ODP_ALIGN_ROUNDUP((uintptr_t)(x), (uintptr_t)(align)))


/**
 * @internal
 * Round up pointer 'x' to cache line size alignment
 */
#define ODP_CACHE_LINE_SIZE_ROUNDUP_PTR(x)\
	((void *)ODP_CACHE_LINE_SIZE_ROUNDUP((uintptr_t)(x)))



/*
 * Round down
 */


/**
 * @internal
 * Round down pointer 'x' to 'align' alignment, which is a power of two
 */
#define ODP_ALIGN_ROUNDDOWN_PTR_POWER_2(x, align)\
((void *)ODP_ALIGN_ROUNDDOWN_POWER_2((uintptr_t)(x), (uintptr_t)(align)))


/**
 * @internal
 * Round down pointer 'x' to cache line size alignment
 */
#define ODP_CACHE_LINE_SIZE_ROUNDDOWN_PTR(x)\
	((void *)ODP_CACHE_LINE_SIZE_ROUNDDOWN((uintptr_t)(x)))


/** Defines type/struct/variable to be cache line size aligned */
#define ODP_ALIGNED_CACHE   ODP_ALIGNED(ODP_CACHE_LINE_SIZE)

/** Defines type/struct/variable to be page size aligned */
#define ODP_ALIGNED_PAGE    ODP_ALIGNED(ODP_PAGE_SIZE)

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#endif