[BACK]Return to cdefs.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / sys

Annotation of src/sys/sys/cdefs.h, Revision 1.95

1.95    ! christos    1: /*     $NetBSD: cdefs.h,v 1.94 2012/03/15 00:09:08 christos Exp $      */
1.10      cgd         2:
1.1       cgd         3: /*
1.8       cgd         4:  * Copyright (c) 1991, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to Berkeley by
                      8:  * Berkeley Software Design, Inc.
1.1       cgd         9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
1.49      agc        18:  * 3. Neither the name of the University nor the names of its contributors
1.1       cgd        19:  *    may be used to endorse or promote products derived from this software
                     20:  *    without specific prior written permission.
                     21:  *
                     22:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     23:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     24:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     25:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     26:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     27:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     28:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     29:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     30:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     31:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     32:  * SUCH DAMAGE.
                     33:  *
1.25      fvdl       34:  *     @(#)cdefs.h     8.8 (Berkeley) 1/9/95
1.1       cgd        35:  */
                     36:
1.17      mikel      37: #ifndef        _SYS_CDEFS_H_
                     38: #define        _SYS_CDEFS_H_
1.1       cgd        39:
1.32      thorpej    40: /*
                     41:  * Macro to test if we're using a GNU C compiler of a specific vintage
                     42:  * or later, for e.g. features that appeared in a particular version
                     43:  * of GNU C.  Usage:
                     44:  *
                     45:  *     #if __GNUC_PREREQ__(major, minor)
                     46:  *     ...cool feature...
                     47:  *     #else
                     48:  *     ...delete feature...
                     49:  *     #endif
                     50:  */
                     51: #ifdef __GNUC__
                     52: #define        __GNUC_PREREQ__(x, y)                                           \
                     53:        ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||                  \
                     54:         (__GNUC__ > (x)))
                     55: #else
                     56: #define        __GNUC_PREREQ__(x, y)   0
                     57: #endif
                     58:
1.15      jtc        59: #include <machine/cdefs.h>
1.29      thorpej    60: #ifdef __ELF__
                     61: #include <sys/cdefs_elf.h>
                     62: #else
                     63: #include <sys/cdefs_aout.h>
                     64: #endif
1.15      jtc        65:
1.87      dyoung     66: #ifdef __GNUC__
                     67: #define        __strict_weak_alias(alias,sym)                                  \
                     68:        __unused static __typeof__(alias) *__weak_alias_##alias = &sym; \
                     69:        __weak_alias(alias,sym)
                     70: #else
                     71: #define        __strict_weak_alias(alias,sym) __weak_alias(alias,sym)
                     72: #endif
                     73:
1.1       cgd        74: /*
1.85      joerg      75:  * Optional marker for size-optimised MD calling convention.
                     76:  */
                     77: #ifndef __compactcall
                     78: #define        __compactcall
                     79: #endif
                     80:
                     81: /*
1.1       cgd        82:  * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
                     83:  * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
                     84:  * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
                     85:  * in between its arguments.  __CONCAT can also concatenate double-quoted
                     86:  * strings produced by the __STRING macro, but this only works with ANSI C.
                     87:  */
1.29      thorpej    88:
                     89: #define        ___STRING(x)    __STRING(x)
                     90: #define        ___CONCAT(x,y)  __CONCAT(x,y)
                     91:
1.37      kleink     92: #if __STDC__ || defined(__cplusplus)
1.1       cgd        93: #define        __P(protos)     protos          /* full-blown ANSI C */
                     94: #define        __CONCAT(x,y)   x ## y
                     95: #define        __STRING(x)     #x
                     96:
1.8       cgd        97: #define        __const         const           /* define reserved names to standard */
                     98: #define        __signed        signed
                     99: #define        __volatile      volatile
1.65      ragge     100: #if defined(__cplusplus) || defined(__PCC__)
                    101: #define        __inline        inline          /* convert to C++/C99 keyword */
1.8       cgd       102: #else
1.35      simonb    103: #if !defined(__GNUC__) && !defined(__lint__)
1.8       cgd       104: #define        __inline                        /* delete GCC keyword */
1.35      simonb    105: #endif /* !__GNUC__  && !__lint__ */
1.8       cgd       106: #endif /* !__cplusplus */
                    107:
1.1       cgd       108: #else  /* !(__STDC__ || __cplusplus) */
                    109: #define        __P(protos)     ()              /* traditional C preprocessor */
                    110: #define        __CONCAT(x,y)   x/**/y
                    111: #define        __STRING(x)     "x"
                    112:
1.8       cgd       113: #ifndef __GNUC__
                    114: #define        __const                         /* delete pseudo-ANSI C keywords */
                    115: #define        __inline
                    116: #define        __signed
                    117: #define        __volatile
                    118: #endif /* !__GNUC__ */
1.23      thorpej   119:
1.8       cgd       120: /*
                    121:  * In non-ANSI C environments, new programs will want ANSI-only C keywords
                    122:  * deleted from the program and old programs will want them left alone.
                    123:  * Programs using the ANSI C keywords const, inline etc. as normal
                    124:  * identifiers should define -DNO_ANSI_KEYWORDS.
                    125:  */
                    126: #ifndef        NO_ANSI_KEYWORDS
                    127: #define        const           __const         /* convert ANSI C keywords */
1.1       cgd       128: #define        inline          __inline
                    129: #define        signed          __signed
                    130: #define        volatile        __volatile
1.8       cgd       131: #endif /* !NO_ANSI_KEYWORDS */
1.1       cgd       132: #endif /* !(__STDC__ || __cplusplus) */
1.27      mycroft   133:
                    134: /*
                    135:  * Used for internal auditing of the NetBSD source tree.
                    136:  */
                    137: #ifdef __AUDIT__
                    138: #define        __aconst        __const
                    139: #else
                    140: #define        __aconst
1.28      kleink    141: #endif
                    142:
                    143: /*
1.83      matt      144:  * Compile Time Assertion.
                    145:  */
1.84      matt      146: #ifdef __COUNTER__
                    147: #define        __CTASSERT(x)           __CTASSERT0(x, __ctassert, __COUNTER__)
                    148: #else
1.83      matt      149: #define        __CTASSERT(x)           __CTASSERT0(x, __ctassert, __LINE__)
1.84      matt      150: #endif
1.83      matt      151: #define        __CTASSERT0(x, y, z)    __CTASSERT1(x, y, z)
                    152: #define        __CTASSERT1(x, y, z)    typedef char y ## z[(x) ? 1 : -1];
                    153:
                    154: /*
1.54      christos  155:  * The following macro is used to remove const cast-away warnings
                    156:  * from gcc -Wcast-qual; it should be used with caution because it
                    157:  * can hide valid errors; in particular most valid uses are in
                    158:  * situations where the API requires it, not to cast away string
1.55      christos  159:  * constants. We don't use *intptr_t on purpose here and we are
1.54      christos  160:  * explicit about unsigned long so that we don't have additional
                    161:  * dependencies.
                    162:  */
1.55      christos  163: #define __UNCONST(a)   ((void *)(unsigned long)(const void *)(a))
1.54      christos  164:
                    165: /*
1.59      he        166:  * The following macro is used to remove the volatile cast-away warnings
                    167:  * from gcc -Wcast-qual; as above it should be used with caution
                    168:  * because it can hide valid errors or warnings.  Valid uses include
                    169:  * making it possible to pass a volatile pointer to memset().
                    170:  * For the same reasons as above, we use unsigned long and not intptr_t.
                    171:  */
                    172: #define __UNVOLATILE(a)        ((void *)(unsigned long)(volatile void *)(a))
                    173:
                    174: /*
1.28      kleink    175:  * GCC2 provides __extension__ to suppress warnings for various GNU C
                    176:  * language extensions under "-ansi -pedantic".
                    177:  */
1.32      thorpej   178: #if !__GNUC_PREREQ__(2, 0)
1.28      kleink    179: #define        __extension__           /* delete __extension__ if non-gcc or gcc1 */
1.27      mycroft   180: #endif
1.6       jtc       181:
                    182: /*
1.8       cgd       183:  * GCC1 and some versions of GCC2 declare dead (non-returning) and
                    184:  * pure (no side effects) functions using "volatile" and "const";
                    185:  * unfortunately, these then cause warnings under "-ansi -pedantic".
                    186:  * GCC2 uses a new, peculiar __attribute__((attrs)) style.  All of
                    187:  * these work for GNU C++ (modulo a slight glitch in the C++ grammar
                    188:  * in the distribution version of 2.5.5).
1.76      joerg     189:  *
                    190:  * GCC defines a pure function as depending only on its arguments and
                    191:  * global variables.  Typical examples are strlen and sqrt.
                    192:  *
                    193:  * GCC defines a const function as depending only on its arguments.
                    194:  * Therefore calling a const function again with identical arguments
                    195:  * will always produce the same result.
                    196:  *
                    197:  * Rounding modes for floating point operations are considered global
                    198:  * variables and prevent sqrt from being a const function.
                    199:  *
                    200:  * Calls to const functions can be optimised away and moved around
                    201:  * without limitations.
1.6       jtc       202:  */
1.66      joerg     203: #if !__GNUC_PREREQ__(2, 0)
                    204: #define __attribute__(x)
                    205: #endif
                    206:
                    207: #if __GNUC_PREREQ__(2, 5)
                    208: #define        __dead          __attribute__((__noreturn__))
                    209: #elif defined(__GNUC__)
1.8       cgd       210: #define        __dead          __volatile
1.66      joerg     211: #else
                    212: #define        __dead
1.6       jtc       213: #endif
                    214:
1.66      joerg     215: #if __GNUC_PREREQ__(2, 96)
                    216: #define        __pure          __attribute__((__pure__))
                    217: #elif defined(__GNUC__)
                    218: #define        __pure          __const
                    219: #else
1.8       cgd       220: #define        __pure
1.43      thorpej   221: #endif
                    222:
1.76      joerg     223: #if __GNUC_PREREQ__(2, 5)
                    224: #define        __constfunc     __attribute__((__const__))
                    225: #else
                    226: #define        __constfunc
                    227: #endif
                    228:
1.67      ad        229: #if __GNUC_PREREQ__(3, 0)
1.69      gmcgarry  230: #define        __noinline      __attribute__((__noinline__))
1.67      ad        231: #else
                    232: #define        __noinline      /* nothing */
                    233: #endif
                    234:
1.89      joerg     235: #if __GNUC_PREREQ__(4, 1)
                    236: #define        __returns_twice __attribute__((__returns_twice__))
                    237: #else
                    238: #define        __returns_twice /* nothing */
                    239: #endif
                    240:
1.88      chs       241: #if __GNUC_PREREQ__(4, 5)
                    242: #define        __noclone       __attribute__((__noclone__))
                    243: #else
                    244: #define        __noclone       /* nothing */
                    245: #endif
                    246:
1.43      thorpej   247: #if __GNUC_PREREQ__(2, 7)
                    248: #define        __unused        __attribute__((__unused__))
1.53      he        249: #else
                    250: #define        __unused        /* delete */
                    251: #endif
                    252:
                    253: #if __GNUC_PREREQ__(3, 1)
1.52      drochner  254: #define        __used          __attribute__((__used__))
1.43      thorpej   255: #else
1.62      uwe       256: #define        __used          __unused
1.43      thorpej   257: #endif
                    258:
1.82      matt      259: #if __GNUC_PREREQ__(3, 1)
                    260: #define        __noprofile     __attribute__((__no_instrument_function__))
                    261: #else
                    262: #define        __noprofile     /* nothing */
                    263: #endif
                    264:
1.81      joerg     265: #if defined(__cplusplus)
                    266: #define        __BEGIN_EXTERN_C        extern "C" {
                    267: #define        __END_EXTERN_C          }
                    268: #define        __static_cast(x,y)      static_cast<x>(y)
                    269: #else
                    270: #define        __BEGIN_EXTERN_C
                    271: #define        __END_EXTERN_C
                    272: #define        __static_cast(x,y)      (x)y
                    273: #endif
                    274:
1.80      joerg     275: #if __GNUC_PREREQ__(4, 0)
                    276: #  define __dso_public __attribute__((__visibility__("default")))
                    277: #  define __dso_hidden __attribute__((__visibility__("hidden")))
1.81      joerg     278: #  define __BEGIN_PUBLIC_DECLS \
                    279:        _Pragma("GCC visibility push(default)") __BEGIN_EXTERN_C
                    280: #  define __END_PUBLIC_DECLS   __END_EXTERN_C _Pragma("GCC visibility pop")
                    281: #  define __BEGIN_HIDDEN_DECLS \
                    282:        _Pragma("GCC visibility push(hidden)") __BEGIN_EXTERN_C
                    283: #  define __END_HIDDEN_DECLS   __END_EXTERN_C _Pragma("GCC visibility pop")
1.80      joerg     284: #else
                    285: #  define __dso_public
                    286: #  define __dso_hidden
1.81      joerg     287: #  define __BEGIN_PUBLIC_DECLS __BEGIN_EXTERN_C
                    288: #  define __END_PUBLIC_DECLS   __END_EXTERN_C
                    289: #  define __BEGIN_HIDDEN_DECLS __BEGIN_EXTERN_C
                    290: #  define __END_HIDDEN_DECLS   __END_EXTERN_C
1.80      joerg     291: #endif
                    292:
1.81      joerg     293: #define        __BEGIN_DECLS           __BEGIN_PUBLIC_DECLS
                    294: #define        __END_DECLS             __END_PUBLIC_DECLS
1.80      joerg     295:
1.79      joerg     296: /*
                    297:  * Non-static C99 inline functions are optional bodies.  They don't
                    298:  * create global symbols if not used, but can be replaced if desirable.
                    299:  * This differs from the behavior of GCC before version 4.3.  The nearest
                    300:  * equivalent for older GCC is `extern inline'.  For newer GCC, use the
                    301:  * gnu_inline attribute additionally to get the old behavior.
                    302:  *
                    303:  * For C99 compilers other than GCC, the C99 behavior is expected.
                    304:  */
                    305: #if defined(__GNUC__) && defined(__GNUC_STDC_INLINE__)
                    306: #define        __c99inline     extern __attribute__((__gnu_inline__)) __inline
                    307: #elif defined(__GNUC__)
                    308: #define        __c99inline     extern __inline
                    309: #elif defined(__STDC_VERSION__)
                    310: #define        __c99inline     __inline
                    311: #endif
                    312:
1.78      christos  313: #if defined(__lint__)
                    314: #define        __packed        __packed
                    315: #define        __aligned(x)    /* delete */
                    316: #define        __section(x)    /* delete */
                    317: #elif __GNUC_PREREQ__(2, 7)
1.43      thorpej   318: #define        __packed        __attribute__((__packed__))
                    319: #define        __aligned(x)    __attribute__((__aligned__(x)))
                    320: #define        __section(x)    __attribute__((__section__(x)))
1.65      ragge     321: #elif defined(__PCC__)
1.75      reinoud   322: #define        __packed        _Pragma("packed 1")
1.73      gmcgarry  323: #define        __aligned(x)    _Pragma("aligned " __STRING(x))
1.68      gmcgarry  324: #define        __section(x)    _Pragma("section " ## x)
1.86      nonaka    325: #elif defined(_MSC_VER)
                    326: #define        __packed        /* ignore */
1.43      thorpej   327: #else
1.44      thorpej   328: #define        __packed        error: no __packed for this compiler
                    329: #define        __aligned(x)    error: no __aligned for this compiler
                    330: #define        __section(x)    error: no __section for this compiler
1.39      kleink    331: #endif
                    332:
                    333: /*
                    334:  * C99 defines the restrict type qualifier keyword, which was made available
                    335:  * in GCC 2.92.
                    336:  */
1.69      gmcgarry  337: #if defined(__lint__)
                    338: #define        __restrict      /* delete __restrict when not supported */
                    339: #elif __STDC_VERSION__ >= 199901L
1.39      kleink    340: #define        __restrict      restrict
1.90      joerg     341: #elif __GNUC_PREREQ__(2, 92)
                    342: #define        __restrict      __restrict__
                    343: #else
1.39      kleink    344: #define        __restrict      /* delete __restrict when not supported */
1.40      kleink    345: #endif
1.42      enami     346:
                    347: /*
                    348:  * C99 defines __func__ predefined identifier, which was made available
                    349:  * in GCC 2.95.
                    350:  */
                    351: #if !(__STDC_VERSION__ >= 199901L)
                    352: #if __GNUC_PREREQ__(2, 6)
                    353: #define        __func__        __PRETTY_FUNCTION__
                    354: #elif __GNUC_PREREQ__(2, 4)
                    355: #define        __func__        __FUNCTION__
                    356: #else
                    357: #define        __func__        ""
                    358: #endif
                    359: #endif /* !(__STDC_VERSION__ >= 199901L) */
1.18      christos  360:
1.29      thorpej   361: #if defined(_KERNEL)
                    362: #if defined(NO_KERNEL_RCSIDS)
                    363: #undef __KERNEL_RCSID
                    364: #define        __KERNEL_RCSID(_n, _s)          /* nothing */
                    365: #endif /* NO_KERNEL_RCSIDS */
                    366: #endif /* _KERNEL */
1.18      christos  367:
1.72      pooka     368: #if !defined(_STANDALONE) && !defined(_KERNEL)
1.65      ragge     369: #if defined(__GNUC__) || defined(__PCC__)
1.30      itohy     370: #define        __RENAME(x)     ___RENAME(x)
1.29      thorpej   371: #else
1.23      thorpej   372: #ifdef __lint__
1.29      thorpej   373: #define        __RENAME(x)     __symbolrename(x)
1.21      christos  374: #else
1.50      grant     375: #error "No function renaming possible"
1.29      thorpej   376: #endif /* __lint__ */
                    377: #endif /* __GNUC__ */
1.31      cgd       378: #else /* _STANDALONE || _KERNEL */
                    379: #define        __RENAME(x)     no renaming in kernel or standalone environment
1.33      thorpej   380: #endif
                    381:
                    382: /*
1.51      martin    383:  * A barrier to stop the optimizer from moving code or assume live
                    384:  * register values. This is gcc specific, the version is more or less
                    385:  * arbitrary, might work with older compilers.
                    386:  */
                    387: #if __GNUC_PREREQ__(2, 95)
                    388: #define        __insn_barrier()        __asm __volatile("":::"memory")
                    389: #else
                    390: #define        __insn_barrier()        /* */
                    391: #endif
                    392:
                    393: /*
1.33      thorpej   394:  * GNU C version 2.96 adds explicit branch prediction so that
                    395:  * the CPU back-end can hint the processor and also so that
                    396:  * code blocks can be reordered such that the predicted path
                    397:  * sees a more linear flow, thus improving cache behavior, etc.
                    398:  *
1.48      perry     399:  * The following two macros provide us with a way to use this
1.33      thorpej   400:  * compiler feature.  Use __predict_true() if you expect the expression
                    401:  * to evaluate to true, and __predict_false() if you expect the
                    402:  * expression to evaluate to false.
                    403:  *
                    404:  * A few notes about usage:
                    405:  *
                    406:  *     * Generally, __predict_false() error condition checks (unless
                    407:  *       you have some _strong_ reason to do otherwise, in which case
                    408:  *       document it), and/or __predict_true() `no-error' condition
                    409:  *       checks, assuming you want to optimize for the no-error case.
                    410:  *
1.36      kleink    411:  *     * Other than that, if you don't know the likelihood of a test
1.33      thorpej   412:  *       succeeding from empirical or other `hard' evidence, don't
                    413:  *       make predictions.
1.34      thorpej   414:  *
                    415:  *     * These are meant to be used in places that are run `a lot'.
                    416:  *       It is wasteful to make predictions in code that is run
                    417:  *       seldomly (e.g. at subsystem initialization time) as the
                    418:  *       basic block reordering that this affects can often generate
                    419:  *       larger code.
1.33      thorpej   420:  */
                    421: #if __GNUC_PREREQ__(2, 96)
1.47      christos  422: #define        __predict_true(exp)     __builtin_expect((exp) != 0, 1)
                    423: #define        __predict_false(exp)    __builtin_expect((exp) != 0, 0)
1.33      thorpej   424: #else
1.47      christos  425: #define        __predict_true(exp)     (exp)
                    426: #define        __predict_false(exp)    (exp)
1.31      cgd       427: #endif
1.45      thorpej   428:
                    429: /*
1.70      alc       430:  * Compiler-dependent macros to declare that functions take printf-like
                    431:  * or scanf-like arguments.  They are null except for versions of gcc
                    432:  * that are known to support the features properly (old versions of gcc-2
                    433:  * didn't permit keeping the keywords out of the application namespace).
                    434:  */
                    435: #if __GNUC_PREREQ__(2, 7)
                    436: #define __printflike(fmtarg, firstvararg)      \
                    437:            __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
                    438: #define __scanflike(fmtarg, firstvararg)       \
                    439:            __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
                    440: #define __format_arg(fmtarg)    __attribute__((__format_arg__ (fmtarg)))
                    441: #else
                    442: #define __printflike(fmtarg, firstvararg)      /* nothing */
                    443: #define __scanflike(fmtarg, firstvararg)       /* nothing */
                    444: #define __format_arg(fmtarg)                   /* nothing */
                    445: #endif
                    446:
                    447: /*
1.45      thorpej   448:  * Macros for manipulating "link sets".  Link sets are arrays of pointers
                    449:  * to objects, which are gathered up by the linker.
                    450:  *
                    451:  * Object format-specific code has provided us with the following macros:
                    452:  *
                    453:  *     __link_set_add_text(set, sym)
                    454:  *             Add a reference to the .text symbol `sym' to `set'.
                    455:  *
                    456:  *     __link_set_add_rodata(set, sym)
                    457:  *             Add a reference to the .rodata symbol `sym' to `set'.
                    458:  *
                    459:  *     __link_set_add_data(set, sym)
                    460:  *             Add a reference to the .data symbol `sym' to `set'.
                    461:  *
                    462:  *     __link_set_add_bss(set, sym)
                    463:  *             Add a reference to the .bss symbol `sym' to `set'.
                    464:  *
                    465:  *     __link_set_decl(set, ptype)
                    466:  *             Provide an extern declaration of the set `set', which
                    467:  *             contains an array of the pointer type `ptype'.  This
                    468:  *             macro must be used by any code which wishes to reference
                    469:  *             the elements of a link set.
                    470:  *
                    471:  *     __link_set_start(set)
                    472:  *             This points to the first slot in the link set.
                    473:  *
                    474:  *     __link_set_end(set)
                    475:  *             This points to the (non-existent) slot after the last
                    476:  *             entry in the link set.
                    477:  *
                    478:  *     __link_set_count(set)
                    479:  *             Count the number of entries in link set `set'.
                    480:  *
                    481:  * In addition, we provide the following macros for accessing link sets:
                    482:  *
                    483:  *     __link_set_foreach(pvar, set)
                    484:  *             Iterate over the link set `set'.  Because a link set is
                    485:  *             an array of pointers, pvar must be declared as "type **pvar",
                    486:  *             and the actual entry accessed as "*pvar".
                    487:  *
                    488:  *     __link_set_entry(set, idx)
                    489:  *             Access the link set entry at index `idx' from set `set'.
                    490:  */
                    491: #define        __link_set_foreach(pvar, set)                                   \
                    492:        for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++)
                    493:
                    494: #define        __link_set_entry(set, idx)      (__link_set_begin(set)[idx])
1.1       cgd       495:
1.61      dyoung    496: /*
                    497:  * Return the number of elements in a statically-allocated array,
                    498:  * __x.
                    499:  */
                    500: #define        __arraycount(__x)       (sizeof(__x) / sizeof(__x[0]))
                    501:
                    502: /* __BIT(n): nth bit, where __BIT(0) == 0x1. */
                    503: #define        __BIT(__n)      \
1.74      christos  504:     (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : ((uintmax_t)1 << (uintmax_t)(__n)))
1.61      dyoung    505:
                    506: /* __BITS(m, n): bits m through n, m < n. */
                    507: #define        __BITS(__m, __n)        \
                    508:        ((__BIT(MAX((__m), (__n)) + 1) - 1) ^ (__BIT(MIN((__m), (__n))) - 1))
                    509:
                    510: /* find least significant bit that is set */
                    511: #define        __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask))
                    512:
1.63      dyoung    513: #define        __PRIuBIT       PRIuMAX
                    514: #define        __PRIuBITS      __PRIuBIT
                    515:
1.61      dyoung    516: #define        __PRIxBIT       PRIxMAX
                    517: #define        __PRIxBITS      __PRIxBIT
                    518:
1.64      dyoung    519: #define        __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask))
1.63      dyoung    520: #define        __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask))
1.61      dyoung    521: #define        __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask))
                    522:
1.77      christos  523: /*
                    524:  * Only to be used in other headers that are included from both c or c++
                    525:  * NOT to be used in code.
                    526:  */
                    527: #ifdef __cplusplus
                    528: #define __CAST(__dt, __st)     static_cast<__dt>(__st)
                    529: #else
                    530: #define __CAST(__dt, __st)     ((__dt)(__st))
                    531: #endif
                    532:
1.93      christos  533: #define __type_mask(t) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \
                    534:     (~((1ULL << (sizeof(t) * NBBY)) - 1)) : 0ULL)
                    535:
1.94      christos  536: #ifndef __ASSEMBLER__
1.95    ! christos  537: static __inline long long __zeroll(void) { return 0; }
        !           538: static __inline int __negative_p(double x) { return x < 0; }
1.94      christos  539: #else
                    540: #define __zeroll() (0LL)
                    541: #define __negative_p(x) ((x) < 0)
                    542: #endif
1.93      christos  543:
                    544: #define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1))))
                    545: #define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1))))
                    546: #define __type_min_u(t) ((t)0ULL)
                    547: #define __type_max_u(t) ((t)~0ULL)
                    548: #define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1)
                    549: #define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t))
                    550: #define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t))
                    551:
                    552:
                    553: #define __type_fit_u(t, a) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \
1.94      christos  554:     (((a) & __type_mask(t)) == 0) : !__negative_p(a))
1.93      christos  555:
1.94      christos  556: #define __type_fit_s(t, a) (/*LINTED*/__negative_p(a) ? \
                    557:     ((intmax_t)((a) + __zeroll()) >= (intmax_t)__type_min_s(t)) : \
                    558:     ((intmax_t)((a) + __zeroll()) <= (intmax_t)__type_max_s(t)))
1.93      christos  559:
                    560: /*
                    561:  * return true if value 'a' fits in type 't'
                    562:  */
                    563: #define __type_fit(t, a) (__type_is_signed(t) ? \
                    564:     __type_fit_s(t, a) : __type_fit_u(t, a))
                    565:
1.17      mikel     566: #endif /* !_SYS_CDEFS_H_ */

CVSweb <webmaster@jp.NetBSD.org>