Path: blob/main/sys/contrib/ck/include/gcc/ck_cc.h
48375 views
/*1* Copyright 2009-2015 Samy Al Bahra.2* Copyright 2014 Paul Khuong.3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#ifndef CK_GCC_CC_H28#define CK_GCC_CC_H2930#include <ck_md.h>3132#ifdef __SUNPRO_C33#define CK_CC_UNUSED34#define CK_CC_USED35#define CK_CC_IMM36#define CK_CC_IMM_U3237#else38#define CK_CC_UNUSED __attribute__((unused))39#define CK_CC_USED __attribute__((used))40#define CK_CC_IMM "i"4142#define CK_CC_CONTAINER(F, T, M, N) \43CK_CC_INLINE static T * \44N(F *p) \45{ \46\47return (T *)(void *)((char *)p - __builtin_offsetof(T, M)); \48}4950#if defined(__x86_64__) || defined(__x86__)51#define CK_CC_IMM_U32 "Z"52#define CK_CC_IMM_S32 "e"53#else54#define CK_CC_IMM_U32 CK_CC_IMM55#define CK_CC_IMM_S32 CK_CC_IMM56#endif /* __x86_64__ || __x86__ */57#endif5859#ifdef __OPTIMIZE__60#define CK_CC_INLINE CK_CC_UNUSED inline61#else62#define CK_CC_INLINE CK_CC_UNUSED63#endif6465#define CK_CC_FORCE_INLINE CK_CC_UNUSED __attribute__((always_inline)) inline66#define CK_CC_RESTRICT __restrict__6768/*69* Packed attribute.70*/71#define CK_CC_PACKED __attribute__((packed))7273/*74* Weak reference.75*/76#define CK_CC_WEAKREF __attribute__((weakref))7778/*79* Alignment attribute.80*/81#define CK_CC_ALIGN(B) __attribute__((aligned(B)))8283/*84* Cache align.85*/86#define CK_CC_CACHELINE CK_CC_ALIGN(CK_MD_CACHELINE)8788/*89* These are functions which should be avoided.90*/91#ifdef __freestanding__92#pragma GCC poison malloc free93#endif9495/*96* Branch execution hints.97*/98#define CK_CC_LIKELY(x) (__builtin_expect(!!(x), 1))99#define CK_CC_UNLIKELY(x) (__builtin_expect(!!(x), 0))100101/*102* Some compilers are overly strict regarding aliasing semantics.103* Unfortunately, in many cases it makes more sense to pay aliasing104* cost rather than overly expensive register spillage.105*/106#define CK_CC_ALIASED __attribute__((__may_alias__))107108/*109* Compile-time typeof110*/111#define CK_CC_TYPEOF(X, DEFAULT) __typeof__(X)112113/*114* Portability wrappers for bitwise operations.115*/116#ifndef CK_MD_CC_BUILTIN_DISABLE117#define CK_F_CC_FFS118CK_CC_INLINE static int119ck_cc_ffs(unsigned int x)120{121122return __builtin_ffsl(x);123}124125#define CK_F_CC_FFSL126CK_CC_INLINE static int127ck_cc_ffsl(unsigned long x)128{129130return __builtin_ffsll(x);131}132133#define CK_F_CC_CTZ134CK_CC_INLINE static int135ck_cc_ctz(unsigned int x)136{137138return __builtin_ctz(x);139}140141#define CK_F_CC_POPCOUNT142CK_CC_INLINE static int143ck_cc_popcount(unsigned int x)144{145146return __builtin_popcount(x);147}148#endif /* CK_MD_CC_BUILTIN_DISABLE */149#endif /* CK_GCC_CC_H */150151152