2018-03-07 20:57:14 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
|
|
|
*
|
2018-05-26 01:49:13 +08:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-03-07 20:57:14 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UTIL_H
|
|
|
|
#define UTIL_H
|
|
|
|
|
|
|
|
#define offsetof(st, m) __builtin_offsetof(st, m)
|
2018-09-13 09:25:27 +08:00
|
|
|
#define va_start __builtin_va_start
|
|
|
|
#define va_end __builtin_va_end
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
/** Roundup (x/y) to ( x/y + (x%y) ? 1 : 0) **/
|
2018-07-19 09:16:56 +08:00
|
|
|
#define INT_DIV_ROUNDUP(x, y) ((((x)+(y))-1)/(y))
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-04-19 16:16:42 +08:00
|
|
|
#define min(x, y) ((x) < (y)) ? (x) : (y)
|
|
|
|
|
|
|
|
#define max(x, y) ((x) < (y)) ? (y) : (x)
|
|
|
|
|
2018-09-13 09:25:27 +08:00
|
|
|
/** Replaces 'x' by the string "x". */
|
|
|
|
#define STRINGIFY(x) #x
|
|
|
|
|
|
|
|
/* Macro used to check if a value is aligned to the required boundary.
|
|
|
|
* Returns TRUE if aligned; FALSE if not aligned
|
|
|
|
* NOTE: The required alignment must be a power of 2 (2, 4, 8, 16, 32, etc)
|
|
|
|
*/
|
|
|
|
static inline bool mem_aligned_check(uint64_t value, uint64_t req_align)
|
|
|
|
{
|
|
|
|
return ((value & (req_align - 1UL)) == 0UL);
|
|
|
|
}
|
|
|
|
|
2018-03-07 20:57:14 +08:00
|
|
|
#endif /* UTIL_H */
|