19fd0b09ee
Add a macro to check if a value is aligned. BUG=chrome-os-partner:36258 BRANCH=none TEST=Build and boot on Pistachio. Change-Id: I0680954eb1b1964a631527f96aa0570a32944fa1 Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Original-Commit-Id: 4f1717648e0a4b54217d71f8d0a15d496737d156 Original-Change-Id: Ie0bc1374918a7ffaaec5fea62c1193a42edd416c Original-Signed-off-by: Andrew Bresticker <abrestic@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/246692 Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/8757 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@google.com> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
38 lines
1,016 B
C
38 lines
1,016 B
C
#ifndef STDLIB_H
|
|
#define STDLIB_H
|
|
|
|
#include <stddef.h>
|
|
|
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
|
|
|
#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1UL)
|
|
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
|
|
#define ALIGN_UP(x,a) ALIGN((x),(a))
|
|
#define ALIGN_DOWN(x,a) ((x) & ~((typeof(x))(a)-1UL))
|
|
#define IS_ALIGNED(x,a) (((x) & ((typeof(x))(a)-1UL)) == 0)
|
|
|
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
|
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
|
#define ABS(a) (((a) < 0) ? (-(a)) : (a))
|
|
#define CEIL_DIV(a, b) (((a) + (b) - 1) / (b))
|
|
#define IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
|
|
|
|
#define min(a,b) MIN((a),(b))
|
|
#define max(a,b) MAX((a),(b))
|
|
|
|
#if !defined(__PRE_RAM__)
|
|
void *memalign(size_t boundary, size_t size);
|
|
void *malloc(size_t size);
|
|
/* We never free memory */
|
|
static inline void free(void *ptr) {}
|
|
#endif
|
|
|
|
#ifndef __ROMCC__
|
|
static inline unsigned long div_round_up(unsigned int n, unsigned int d)
|
|
{
|
|
return (n + d - 1) / d;
|
|
}
|
|
#endif
|
|
|
|
|
|
#endif /* STDLIB_H */
|