Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | #ifndef STDLIB_H |
| 2 | #define STDLIB_H |
| 3 | |
| 4 | #include <stddef.h> |
| 5 | |
Uwe Hermann | 55e6eba | 2007-10-27 20:05:21 +0000 | [diff] [blame] | 6 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 7 | |
Stefan Reinauer | d40393e | 2012-03-30 13:00:46 -0700 | [diff] [blame] | 8 | #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1UL) |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame] | 9 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
Aaron Durbin | 3ece5ac | 2013-03-28 16:17:11 -0500 | [diff] [blame] | 10 | #define ALIGN_UP(x,a) ALIGN((x),(a)) |
| 11 | #define ALIGN_DOWN(x,a) ((x) & ~((typeof(x))(a)-1UL)) |
Andrew Bresticker | 19fd0b0 | 2015-02-05 13:27:59 -0800 | [diff] [blame] | 12 | #define IS_ALIGNED(x,a) (((x) & ((typeof(x))(a)-1UL)) == 0) |
Rudolf Marek | 79e5325 | 2008-12-23 17:34:15 +0000 | [diff] [blame] | 13 | |
Rudolf Marek | c221349 | 2008-03-19 20:24:33 +0000 | [diff] [blame] | 14 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
| 15 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
Edward O'Callaghan | fd57066 | 2014-07-07 20:33:09 +1000 | [diff] [blame] | 16 | #define ABS(a) (((a) < 0) ? (-(a)) : (a)) |
| 17 | #define CEIL_DIV(a, b) (((a) + (b) - 1) / (b)) |
| 18 | #define IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0) |
Rudolf Marek | c221349 | 2008-03-19 20:24:33 +0000 | [diff] [blame] | 19 | |
Kyösti Mälkki | 931c1dc | 2014-06-30 09:40:19 +0300 | [diff] [blame] | 20 | #define min(a,b) MIN((a),(b)) |
| 21 | #define max(a,b) MAX((a),(b)) |
| 22 | |
Stefan Reinauer | 35b6bbb | 2010-03-28 21:26:54 +0000 | [diff] [blame] | 23 | #if !defined(__PRE_RAM__) |
Ron Minnich | eb59636 | 2012-04-11 10:30:15 -0700 | [diff] [blame] | 24 | void *memalign(size_t boundary, size_t size); |
Stefan Reinauer | 6bd571e | 2009-09-25 21:59:57 +0000 | [diff] [blame] | 25 | void *malloc(size_t size); |
Stefan Reinauer | e09f7ef | 2012-12-18 14:27:50 -0800 | [diff] [blame] | 26 | /* We never free memory */ |
| 27 | static inline void free(void *ptr) {} |
Corey Osgood | 908ff5e | 2007-11-07 19:02:35 +0000 | [diff] [blame] | 28 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 29 | |
Gabe Black | e5b2127 | 2014-04-05 03:54:30 -0700 | [diff] [blame] | 30 | #ifndef __ROMCC__ |
| 31 | static inline unsigned long div_round_up(unsigned int n, unsigned int d) |
| 32 | { |
| 33 | return (n + d - 1) / d; |
| 34 | } |
| 35 | #endif |
| 36 | |
| 37 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 38 | #endif /* STDLIB_H */ |