Path: blob/main/sys/compat/linuxkpi/common/include/linux/compiler.h
102597 views
/*-1* Copyright (c) 2010 Isilon Systems, Inc.2* Copyright (c) 2010 iX Systems, Inc.3* Copyright (c) 2010 Panasas, Inc.4* Copyright (c) 2013-2016 Mellanox Technologies, Ltd.5* Copyright (c) 2015 François Tigeot6* All rights reserved.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice unmodified, this list of conditions, and the following13* disclaimer.14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR19* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES20* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.21* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,22* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT23* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF27* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28*/29#ifndef _LINUXKPI_LINUX_COMPILER_H_30#define _LINUXKPI_LINUX_COMPILER_H_3132#include <sys/cdefs.h>33#include <sys/endian.h>3435#include <compat/linuxkpi/common/include/linux/compiler_types.h>3637#define __bitwise38#define __devinitdata39#define __init40#define __initconst41#define __devinit42#define __devexit43#define __exit44#define ____cacheline_aligned __aligned(CACHE_LINE_SIZE)45#define ____cacheline_aligned_in_smp __aligned(CACHE_LINE_SIZE)4647#if __has_attribute(__counted_by__)48#define __counted_by(_x) __attribute__((__counted_by__(_x)))49#else50#define __counted_by(_x)51#endif52#if BYTE_ORDER == LITTLE_ENDIAN53#define __counted_by_le(_x) __counted_by(_x)54#define __counted_by_be(_x)55#else56#define __counted_by_le(_x)57#define __counted_by_be(_x) __counted_by(_x)58#endif5960#define likely(x) __builtin_expect(!!(x), 1)61#define unlikely(x) __builtin_expect(!!(x), 0)62#define typeof(x) __typeof(x)6364#define uninitialized_var(x) x = x6566#define barrier() __asm__ __volatile__("": : :"memory")6768#define lower_32_bits(n) ((u32)(n))69#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))7071#define WRITE_ONCE(x,v) do { \72barrier(); \73(*(volatile __typeof(x) *)(uintptr_t)&(x)) = (v); \74barrier(); \75} while (0)7677#define READ_ONCE(x) ({ \78__typeof(x) __var = ({ \79barrier(); \80(*(const volatile __typeof(x) *)&(x)); \81}); \82barrier(); \83__var; \84})8586#define lockless_dereference(p) READ_ONCE(p)8788#define _AT(T,X) ((T)(X))89#define __must_be_array(a) __same_type(a, &(a)[0])9091#define sizeof_field(_s, _m) sizeof(((_s *)0)->_m)9293#define is_signed_type(t) ((t)-1 < (t)1)94#define is_unsigned_type(t) ((t)-1 > (t)1)9596#if __has_builtin(__builtin_dynamic_object_size)97#define __struct_size(_s) __builtin_dynamic_object_size(_s, 0)98#else99#define __struct_size(_s) __builtin_object_size(_s, 0)100#endif101102#endif /* _LINUXKPI_LINUX_COMPILER_H_ */103104105