compiler.h revision 322498
1219820Sjeff/*-
2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc.
3219820Sjeff * Copyright (c) 2010 iX Systems, Inc.
4219820Sjeff * Copyright (c) 2010 Panasas, Inc.
5299653Shselasky * Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
6289577Shselasky * Copyright (c) 2015 Fran��ois Tigeot
7219820Sjeff * All rights reserved.
8219820Sjeff *
9219820Sjeff * Redistribution and use in source and binary forms, with or without
10219820Sjeff * modification, are permitted provided that the following conditions
11219820Sjeff * are met:
12219820Sjeff * 1. Redistributions of source code must retain the above copyright
13219820Sjeff *    notice unmodified, this list of conditions, and the following
14219820Sjeff *    disclaimer.
15219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright
16219820Sjeff *    notice, this list of conditions and the following disclaimer in the
17219820Sjeff *    documentation and/or other materials provided with the distribution.
18219820Sjeff *
19219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20219820Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21219820Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22219820Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23219820Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24219820Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28219820Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29289644Shselasky *
30289644Shselasky * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/linux/compiler.h 322498 2017-08-14 12:45:55Z hselasky $
31219820Sjeff */
32219820Sjeff#ifndef	_LINUX_COMPILER_H_
33219820Sjeff#define	_LINUX_COMPILER_H_
34219820Sjeff
35219820Sjeff#include <sys/cdefs.h>
36219820Sjeff
37219820Sjeff#define __user
38219820Sjeff#define __kernel
39219820Sjeff#define __safe
40219820Sjeff#define __force
41219820Sjeff#define __nocast
42219820Sjeff#define __iomem
43219820Sjeff#define __chk_user_ptr(x)		0
44219820Sjeff#define __chk_io_ptr(x)			0
45219820Sjeff#define __builtin_warning(x, y...)	(1)
46219820Sjeff#define __acquires(x)
47219820Sjeff#define __releases(x)
48219820Sjeff#define __acquire(x)			0
49219820Sjeff#define __release(x)			0
50219820Sjeff#define __cond_lock(x,c)		(c)
51219820Sjeff#define	__bitwise
52219820Sjeff#define __devinitdata
53299653Shselasky#define	__deprecated
54219820Sjeff#define __init
55219820Sjeff#define	__devinit
56219820Sjeff#define	__devexit
57219820Sjeff#define __exit
58299653Shselasky#define	__rcu
59219820Sjeff#define	__stringify(x)			#x
60219820Sjeff#define	__attribute_const__		__attribute__((__const__))
61219820Sjeff#undef __always_inline
62219820Sjeff#define	__always_inline			inline
63299653Shselasky#define	____cacheline_aligned		__aligned(CACHE_LINE_SIZE)
64219820Sjeff
65219820Sjeff#define	likely(x)			__builtin_expect(!!(x), 1)
66219820Sjeff#define	unlikely(x)			__builtin_expect(!!(x), 0)
67219820Sjeff#define typeof(x)			__typeof(x)
68219820Sjeff
69219820Sjeff#define	uninitialized_var(x)		x = x
70289577Shselasky#define	__always_unused			__unused
71289577Shselasky#define	__must_check			__result_use_check
72219820Sjeff
73289577Shselasky#define	__printf(a,b)			__printflike(a,b)
74289577Shselasky
75289577Shselasky#define	barrier()			__asm__ __volatile__("": : :"memory")
76289577Shselasky
77299653Shselasky#define	___PASTE(a,b) a##b
78299653Shselasky#define	__PASTE(a,b) ___PASTE(a,b)
79299653Shselasky
80292537Shselasky#define	ACCESS_ONCE(x)			(*(volatile __typeof(x) *)&(x))
81292537Shselasky
82292537Shselasky#define	WRITE_ONCE(x,v) do {		\
83292537Shselasky	barrier();			\
84292537Shselasky	ACCESS_ONCE(x) = (v);		\
85292537Shselasky	barrier();			\
86292537Shselasky} while (0)
87292537Shselasky
88292537Shselasky#define	READ_ONCE(x) ({			\
89322498Shselasky	__typeof(x) __var = ({		\
90322498Shselasky		barrier();		\
91322498Shselasky		ACCESS_ONCE(x);		\
92322498Shselasky	});				\
93292537Shselasky	barrier();			\
94292537Shselasky	__var;				\
95292537Shselasky})
96299653Shselasky
97299653Shselasky#define	lockless_dereference(p) READ_ONCE(p)
98299653Shselasky
99299653Shselasky#define	_AT(T,X)	((T)(X))
100299653Shselasky
101219820Sjeff#endif	/* _LINUX_COMPILER_H_ */
102