blob: 61ff200c53681b2b235850bacb7b0a0d1751a248 (
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
|
/* Copyright (c) 2014, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* @file
*
* ODP internal alignments
*/
#ifndef ODP_ALIGN_INTERNAL_H_
#define ODP_ALIGN_INTERNAL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <odp/api/align.h>
#include <stdint.h>
/* Macros to calculate ODP_ROUNDUP_POWER2_U32() in five rounds of shift
* and OR operations. */
#define _RSHIFT_U32(x, y) (((uint32_t)(x)) >> (y))
#define _POW2_U32_R1(x) (((uint32_t)(x)) | _RSHIFT_U32(x, 1))
#define _POW2_U32_R2(x) (_POW2_U32_R1(x) | _RSHIFT_U32(_POW2_U32_R1(x), 2))
#define _POW2_U32_R3(x) (_POW2_U32_R2(x) | _RSHIFT_U32(_POW2_U32_R2(x), 4))
#define _POW2_U32_R4(x) (_POW2_U32_R3(x) | _RSHIFT_U32(_POW2_U32_R3(x), 8))
#define _POW2_U32_R5(x) (_POW2_U32_R4(x) | _RSHIFT_U32(_POW2_U32_R4(x), 16))
/* Round up a uint32_t value 'x' to the next power of two.
*
* The value is not round up, if it's already a power of two (including 1).
* The value must be larger than 0 and not exceed 0x80000000.
*/
#define ROUNDUP_POWER2_U32(x) \
((((uint32_t)(x)) > 0x80000000) ? 0 : (_POW2_U32_R5(x - 1) + 1))
/*
* Round up 'x' to alignment 'align'
*/
#define ROUNDUP_ALIGN(x, align)\
((align) * (((x) + (align) - 1) / (align)))
/*
* Round up 'x' to cache line size alignment
*/
#define ROUNDUP_CACHE_LINE(x)\
ROUNDUP_ALIGN(x, ODP_CACHE_LINE_SIZE)
/*
* Round down 'x' to 'align' alignment, which is a power of two
*/
#define ROUNDDOWN_POWER2(x, align)\
((x) & (~((align) - 1)))
/*
* Check if value is a power of two
*/
#define CHECK_IS_POWER2(x) ((((x) - 1) & (x)) == 0)
#ifdef __cplusplus
}
#endif
#endif
|