diff options
author | Michael Ellerman <michael@ellerman.id.au> | 2006-03-23 07:32:24 -0500 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2006-03-26 22:48:10 -0500 |
commit | e3f94b85f98a346c5eb0ac0d9539b71cb7057143 (patch) | |
tree | 69cc1fcb75d5af9e89c6a28264547bfc5deadd1b /include | |
parent | af308377e204e25f1f58627d05fe0f483703b514 (diff) |
[PATCH] powerpc: Make BUG_ON & WARN_ON play nice with compile-time optimisations
Change BUG_ON and WARN_ON to give the compiler a chance to perform
compile-time optimsations. Depending on the complexity of the condition,
the compiler may not do this very well, so if it's important check the
object code.
Current GCC's (4.x) produce good code as long as the condition does not
include a function call, including a static inline.
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-powerpc/bug.h | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/include/asm-powerpc/bug.h b/include/asm-powerpc/bug.h index 99817a802ca4..8003997ddc73 100644 --- a/include/asm-powerpc/bug.h +++ b/include/asm-powerpc/bug.h | |||
@@ -30,6 +30,12 @@ struct bug_entry *find_bug(unsigned long bugaddr); | |||
30 | 30 | ||
31 | #ifdef CONFIG_BUG | 31 | #ifdef CONFIG_BUG |
32 | 32 | ||
33 | /* | ||
34 | * BUG_ON() and WARN_ON() do their best to cooperate with compile-time | ||
35 | * optimisations. However depending on the complexity of the condition | ||
36 | * some compiler versions may not produce optimal results. | ||
37 | */ | ||
38 | |||
33 | #define BUG() do { \ | 39 | #define BUG() do { \ |
34 | __asm__ __volatile__( \ | 40 | __asm__ __volatile__( \ |
35 | "1: twi 31,0,0\n" \ | 41 | "1: twi 31,0,0\n" \ |
@@ -40,17 +46,36 @@ struct bug_entry *find_bug(unsigned long bugaddr); | |||
40 | } while (0) | 46 | } while (0) |
41 | 47 | ||
42 | #define BUG_ON(x) do { \ | 48 | #define BUG_ON(x) do { \ |
43 | __asm__ __volatile__( \ | 49 | if (__builtin_constant_p(x)) { \ |
50 | if (x) \ | ||
51 | BUG(); \ | ||
52 | } else { \ | ||
53 | __asm__ __volatile__( \ | ||
44 | "1: "PPC_TLNEI" %0,0\n" \ | 54 | "1: "PPC_TLNEI" %0,0\n" \ |
45 | ".section __bug_table,\"a\"\n" \ | 55 | ".section __bug_table,\"a\"\n" \ |
46 | "\t"PPC_LONG" 1b,%1,%2,%3\n" \ | 56 | "\t"PPC_LONG" 1b,%1,%2,%3\n" \ |
47 | ".previous" \ | 57 | ".previous" \ |
48 | : : "r" ((long)(x)), "i" (__LINE__), \ | 58 | : : "r" ((long)(x)), "i" (__LINE__), \ |
49 | "i" (__FILE__), "i" (__FUNCTION__)); \ | 59 | "i" (__FILE__), "i" (__FUNCTION__)); \ |
60 | } \ | ||
50 | } while (0) | 61 | } while (0) |
51 | 62 | ||
52 | #define WARN_ON(x) do { \ | 63 | #define WARN() do { \ |
53 | __asm__ __volatile__( \ | 64 | __asm__ __volatile__( \ |
65 | "1: twi 31,0,0\n" \ | ||
66 | ".section __bug_table,\"a\"\n" \ | ||
67 | "\t"PPC_LONG" 1b,%0,%1,%2\n" \ | ||
68 | ".previous" \ | ||
69 | : : "i" (__LINE__ + BUG_WARNING_TRAP), \ | ||
70 | "i" (__FILE__), "i" (__FUNCTION__)); \ | ||
71 | } while (0) | ||
72 | |||
73 | #define WARN_ON(x) do { \ | ||
74 | if (__builtin_constant_p(x)) { \ | ||
75 | if (x) \ | ||
76 | WARN(); \ | ||
77 | } else { \ | ||
78 | __asm__ __volatile__( \ | ||
54 | "1: "PPC_TLNEI" %0,0\n" \ | 79 | "1: "PPC_TLNEI" %0,0\n" \ |
55 | ".section __bug_table,\"a\"\n" \ | 80 | ".section __bug_table,\"a\"\n" \ |
56 | "\t"PPC_LONG" 1b,%1,%2,%3\n" \ | 81 | "\t"PPC_LONG" 1b,%1,%2,%3\n" \ |
@@ -58,6 +83,7 @@ struct bug_entry *find_bug(unsigned long bugaddr); | |||
58 | : : "r" ((long)(x)), \ | 83 | : : "r" ((long)(x)), \ |
59 | "i" (__LINE__ + BUG_WARNING_TRAP), \ | 84 | "i" (__LINE__ + BUG_WARNING_TRAP), \ |
60 | "i" (__FILE__), "i" (__FUNCTION__)); \ | 85 | "i" (__FILE__), "i" (__FUNCTION__)); \ |
86 | } \ | ||
61 | } while (0) | 87 | } while (0) |
62 | 88 | ||
63 | #define HAVE_ARCH_BUG | 89 | #define HAVE_ARCH_BUG |