summaryrefslogtreecommitdiff
path: root/compiler.h
blob: 10050178caba6dea1977d989a3d1a88dcaecc94f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef _COMPILER_H_
#define _COMPILER_H_

#include <stdint.h>

#ifdef __GNUC__
# define __packed	__attribute__ ((packed))
# define __unused	__attribute__ ((unused))
# define __noreturn	__attribute__ ((noreturn))
# define likely(x)	__builtin_expect(!!(x), 1)
# define unlikely(x)	__builtin_expect(!!(x), 0)

static inline void prefetch(const void *ptr)
{
	/* We could use some arch specific instructions here, but a GCC builtin
	   is fine for now */
	__builtin_prefetch(ptr, 0, 3);
}

static inline int32_t bswap_32(int32_t x)
{
	return __builtin_bswap32(x);
}

#else
# define __packed
# define __unused
# define __noreturn
# define likely(x) (x)
# define unlikely(x) (x)

static inline prefetch(const void *ptr)
{
	/* empty */
}

static inline int32_t bswap_32(int32_t x)
{
	int32_t ret = 0;

	ret |= ((x & 0xFF000000) >> 24);
	ret |= ((x & 0x00FF0000) >> 8);
	ret |= ((x & 0x0000FF00) << 8);
	ret |= ((x & 0x000000FF) << 24);
	return ret;

}

#endif /* __GNUC__ */

#ifndef offsetof
# define offsetof(type, member) ((size_t) &((type *)0)->member)
#endif /* offsetof */

#ifndef container_of
# define container_of(ptr, type, member) ({				\
		const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
		(type *)( (char *)__mptr - offsetof(type, member) );})
#endif /* container_of */

#endif /* _COMPILER_H_ */
ll percpu update from Tejun Heo: "This includes just one patch to reject non-power-of-2 alignments and trigger warning. Interestingly, this actually caught a bug in XEN ARM64" * 'for-4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu: percpu: ensure the requested alignment is power of two
Diffstat (limited to 'mm')