blob: da6bb199839c1dc221dbcd30a1737e364ee722f9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ALPHA_COMPILER_H
2#define __ALPHA_COMPILER_H
3
4/*
5 * Herein are macros we use when describing various patterns we want to GCC.
6 * In all cases we can get better schedules out of the compiler if we hide
7 * as little as possible inside inline assembly. However, we want to be
8 * able to know what we'll get out before giving up inline assembly. Thus
9 * these tests and macros.
10 */
11
12#if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3
13# define __kernel_insbl(val, shift) __builtin_alpha_insbl(val, shift)
14# define __kernel_inswl(val, shift) __builtin_alpha_inswl(val, shift)
15# define __kernel_insql(val, shift) __builtin_alpha_insql(val, shift)
16# define __kernel_inslh(val, shift) __builtin_alpha_inslh(val, shift)
17# define __kernel_extbl(val, shift) __builtin_alpha_extbl(val, shift)
18# define __kernel_extwl(val, shift) __builtin_alpha_extwl(val, shift)
19# define __kernel_cmpbge(a, b) __builtin_alpha_cmpbge(a, b)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#else
21# define __kernel_insbl(val, shift) \
22 ({ unsigned long __kir; \
23 __asm__("insbl %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val)); \
24 __kir; })
25# define __kernel_inswl(val, shift) \
26 ({ unsigned long __kir; \
27 __asm__("inswl %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val)); \
28 __kir; })
29# define __kernel_insql(val, shift) \
30 ({ unsigned long __kir; \
31 __asm__("insql %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val)); \
32 __kir; })
33# define __kernel_inslh(val, shift) \
34 ({ unsigned long __kir; \
35 __asm__("inslh %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val)); \
36 __kir; })
37# define __kernel_extbl(val, shift) \
38 ({ unsigned long __kir; \
39 __asm__("extbl %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val)); \
40 __kir; })
41# define __kernel_extwl(val, shift) \
42 ({ unsigned long __kir; \
43 __asm__("extwl %2,%1,%0" : "=r"(__kir) : "rI"(shift), "r"(val)); \
44 __kir; })
45# define __kernel_cmpbge(a, b) \
46 ({ unsigned long __kir; \
47 __asm__("cmpbge %r2,%1,%0" : "=r"(__kir) : "rI"(b), "rJ"(a)); \
48 __kir; })
Ivan Kokshaysky88ed39b2007-04-16 22:53:21 -070049#endif
50
51#ifdef __alpha_cix__
52# if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3
53# define __kernel_cttz(x) __builtin_ctzl(x)
54# define __kernel_ctlz(x) __builtin_clzl(x)
55# define __kernel_ctpop(x) __builtin_popcountl(x)
56# else
57# define __kernel_cttz(x) \
58 ({ unsigned long __kir; \
59 __asm__("cttz %1,%0" : "=r"(__kir) : "r"(x)); \
60 __kir; })
61# define __kernel_ctlz(x) \
62 ({ unsigned long __kir; \
63 __asm__("ctlz %1,%0" : "=r"(__kir) : "r"(x)); \
64 __kir; })
65# define __kernel_ctpop(x) \
66 ({ unsigned long __kir; \
67 __asm__("ctpop %1,%0" : "=r"(__kir) : "r"(x)); \
68 __kir; })
69# endif
70#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070071# define __kernel_cttz(x) \
72 ({ unsigned long __kir; \
Ivan Kokshaysky88ed39b2007-04-16 22:53:21 -070073 __asm__(".arch ev67; cttz %1,%0" : "=r"(__kir) : "r"(x)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 __kir; })
75# define __kernel_ctlz(x) \
76 ({ unsigned long __kir; \
Ivan Kokshaysky88ed39b2007-04-16 22:53:21 -070077 __asm__(".arch ev67; ctlz %1,%0" : "=r"(__kir) : "r"(x)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 __kir; })
79# define __kernel_ctpop(x) \
80 ({ unsigned long __kir; \
Ivan Kokshaysky88ed39b2007-04-16 22:53:21 -070081 __asm__(".arch ev67; ctpop %1,%0" : "=r"(__kir) : "r"(x)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 __kir; })
83#endif
84
85
86/*
87 * Beginning with EGCS 1.1, GCC defines __alpha_bwx__ when the BWX
88 * extension is enabled. Previous versions did not define anything
89 * we could test during compilation -- too bad, so sad.
90 */
91
92#if defined(__alpha_bwx__)
93#define __kernel_ldbu(mem) (mem)
94#define __kernel_ldwu(mem) (mem)
95#define __kernel_stb(val,mem) ((mem) = (val))
96#define __kernel_stw(val,mem) ((mem) = (val))
97#else
98#define __kernel_ldbu(mem) \
99 ({ unsigned char __kir; \
Ivan Kokshaysky88ed39b2007-04-16 22:53:21 -0700100 __asm__(".arch ev56; \
101 ldbu %0,%1" : "=r"(__kir) : "m"(mem)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 __kir; })
103#define __kernel_ldwu(mem) \
104 ({ unsigned short __kir; \
Ivan Kokshaysky88ed39b2007-04-16 22:53:21 -0700105 __asm__(".arch ev56; \
106 ldwu %0,%1" : "=r"(__kir) : "m"(mem)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 __kir; })
Ivan Kokshaysky88ed39b2007-04-16 22:53:21 -0700108#define __kernel_stb(val,mem) \
109 __asm__(".arch ev56; \
110 stb %1,%0" : "=m"(mem) : "r"(val))
111#define __kernel_stw(val,mem) \
112 __asm__(".arch ev56; \
113 stw %1,%0" : "=m"(mem) : "r"(val))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#endif
115
David Woodhouse7f9d77d2006-09-16 12:15:49 -0700116#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/* Some idiots over in <linux/compiler.h> thought inline should imply
118 always_inline. This breaks stuff. We'll include this file whenever
119 we run into such problems. */
120
121#include <linux/compiler.h>
122#undef inline
123#undef __inline__
124#undef __inline
Ivan Kokshaysky7243cc02005-09-22 21:43:58 -0700125#undef __always_inline
126#define __always_inline inline __attribute__((always_inline))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
David Woodhouse7f9d77d2006-09-16 12:15:49 -0700128#endif /* __KERNEL__ */
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#endif /* __ALPHA_COMPILER_H */