|
|
1.1 root 1: /* 1.1.1.2 ! root 2: * Copyright (c) 2009-2015 Richard Braun. ! 3: * All rights reserved. 1.1 root 4: * 1.1.1.2 ! root 5: * Redistribution and use in source and binary forms, with or without ! 6: * modification, are permitted provided that the following conditions ! 7: * are met: ! 8: * 1. Redistributions of source code must retain the above copyright ! 9: * notice, this list of conditions and the following disclaimer. ! 10: * 2. Redistributions in binary form must reproduce the above copyright ! 11: * notice, this list of conditions and the following disclaimer in the ! 12: * documentation and/or other materials provided with the distribution. 1.1 root 13: * 1.1.1.2 ! root 14: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR ! 15: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ! 16: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ! 17: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, ! 18: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT ! 19: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ! 20: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ! 21: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ! 22: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF ! 23: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.1 root 24: * 25: * 26: * Helper macros. 1.1.1.2 ! root 27: * ! 28: * Upstream site with license notes : ! 29: * http://git.sceen.net/rbraun/librbraun.git/ 1.1 root 30: */ 31: 32: #ifndef _KERN_MACROS_H 33: #define _KERN_MACROS_H 34: 35: #define MACRO_BEGIN ({ 36: #define MACRO_END }) 37: #define MACRO_RETURN if (1) return 38: 39: #define __QUOTE(x) #x 40: #define QUOTE(x) __QUOTE(x) 41: 42: #ifdef __ASSEMBLER__ 43: #define DECL_CONST(x, s) x 44: #else /* __ASSEMBLER__ */ 45: #define __DECL_CONST(x, s) x##s 46: #define DECL_CONST(x, s) __DECL_CONST(x, s) 47: #endif /* __ASSEMBLER__ */ 48: 49: #define STRLEN(x) (sizeof(x) - 1) 50: #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 51: 52: #define MIN(a, b) ((a) < (b) ? (a) : (b)) 53: #define MAX(a, b) ((a) > (b) ? (a) : (b)) 54: 55: #define DIV_CEIL(n, d) (((n) + (d) - 1) / (d)) 56: 57: #define P2ALIGNED(x, a) (((x) & ((a) - 1)) == 0) 58: #define ISP2(x) P2ALIGNED(x, x) 59: #define P2ALIGN(x, a) ((x) & -(a)) 60: #define P2ROUND(x, a) (-(-(x) & -(a))) 61: #define P2END(x, a) (-(~(x) & -(a))) 62: 63: #define structof(ptr, type, member) \ 64: ((type *)((char *)(ptr) - offsetof(type, member))) 65: 66: #define access_once(x) (*(volatile typeof(x) *)&(x)) 67: 68: #define alignof(x) __alignof__(x) 69: 70: #ifndef likely 71: #define likely(expr) __builtin_expect(!!(expr), 1) 72: #endif /* likely */ 73: #ifndef unlikely 74: #define unlikely(expr) __builtin_expect(!!(expr), 0) 75: #endif /* unlikely */ 76: 77: #ifndef barrier 78: #define barrier() asm volatile("" : : : "memory") 79: #endif /* barrier */ 80: 81: #define __noreturn __attribute__((noreturn)) 82: #define __aligned(x) __attribute__((aligned(x))) 83: #define __always_inline inline __attribute__((always_inline)) 84: #ifndef __section 85: #define __section(x) __attribute__((section(x))) 86: #endif /* __section */ 87: #define __packed __attribute__((packed)) 88: #define __alias(x) __attribute__((alias(x))) 89: 90: #define __format_printf(fmt, args) \ 91: __attribute__((format(printf, fmt, args))) 92: 93: #endif /* _KERN_MACROS_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.