compiler.h revision 330856
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 330856 2018-03-13 16:24:28Z 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
43323214Srlibby#define __chk_user_ptr(x)		((void)0)
44323214Srlibby#define __chk_io_ptr(x)			((void)0)
45219820Sjeff#define __builtin_warning(x, y...)	(1)
46219820Sjeff#define __acquires(x)
47219820Sjeff#define __releases(x)
48323214Srlibby#define __acquire(x)			do { } while (0)
49323214Srlibby#define __release(x)			do { } while (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
59329959Shselasky#define	__percpu
60329959Shselasky#define	__weak __weak_symbol
61328653Shselasky#define	__malloc
62328653Shselasky#define	___stringify(...)		#__VA_ARGS__
63328653Shselasky#define	__stringify(...)		___stringify(__VA_ARGS__)
64219820Sjeff#define	__attribute_const__		__attribute__((__const__))
65219820Sjeff#undef __always_inline
66219820Sjeff#define	__always_inline			inline
67330856Shselasky#define	noinline			__noinline
68299653Shselasky#define	____cacheline_aligned		__aligned(CACHE_LINE_SIZE)
69219820Sjeff
70219820Sjeff#define	likely(x)			__builtin_expect(!!(x), 1)
71219820Sjeff#define	unlikely(x)			__builtin_expect(!!(x), 0)
72219820Sjeff#define typeof(x)			__typeof(x)
73219820Sjeff
74219820Sjeff#define	uninitialized_var(x)		x = x
75330856Shselasky#define	__maybe_unused			__unused
76289577Shselasky#define	__always_unused			__unused
77289577Shselasky#define	__must_check			__result_use_check
78219820Sjeff
79289577Shselasky#define	__printf(a,b)			__printflike(a,b)
80289577Shselasky
81289577Shselasky#define	barrier()			__asm__ __volatile__("": : :"memory")
82289577Shselasky
83299653Shselasky#define	___PASTE(a,b) a##b
84299653Shselasky#define	__PASTE(a,b) ___PASTE(a,b)
85299653Shselasky
86292537Shselasky#define	ACCESS_ONCE(x)			(*(volatile __typeof(x) *)&(x))
87292537Shselasky
88292537Shselasky#define	WRITE_ONCE(x,v) do {		\
89292537Shselasky	barrier();			\
90292537Shselasky	ACCESS_ONCE(x) = (v);		\
91292537Shselasky	barrier();			\
92292537Shselasky} while (0)
93292537Shselasky
94292537Shselasky#define	READ_ONCE(x) ({			\
95322498Shselasky	__typeof(x) __var = ({		\
96322498Shselasky		barrier();		\
97322498Shselasky		ACCESS_ONCE(x);		\
98322498Shselasky	});				\
99292537Shselasky	barrier();			\
100292537Shselasky	__var;				\
101292537Shselasky})
102299653Shselasky
103299653Shselasky#define	lockless_dereference(p) READ_ONCE(p)
104299653Shselasky
105299653Shselasky#define	_AT(T,X)	((T)(X))
106299653Shselasky
107219820Sjeff#endif	/* _LINUX_COMPILER_H_ */
108