Skip to content

Commit

Permalink
[PATCH] powerpc: Make BUG_ON & WARN_ON play nice with compile-time op…
Browse files Browse the repository at this point in the history
…timisations

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>
  • Loading branch information
Michael Ellerman authored and Paul Mackerras committed Mar 27, 2006
1 parent af30837 commit e3f94b8
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions include/asm-powerpc/bug.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ struct bug_entry *find_bug(unsigned long bugaddr);

#ifdef CONFIG_BUG

/*
* BUG_ON() and WARN_ON() do their best to cooperate with compile-time
* optimisations. However depending on the complexity of the condition
* some compiler versions may not produce optimal results.
*/

#define BUG() do { \
__asm__ __volatile__( \
"1: twi 31,0,0\n" \
Expand All @@ -40,24 +46,44 @@ struct bug_entry *find_bug(unsigned long bugaddr);
} while (0)

#define BUG_ON(x) do { \
__asm__ __volatile__( \
if (__builtin_constant_p(x)) { \
if (x) \
BUG(); \
} else { \
__asm__ __volatile__( \
"1: "PPC_TLNEI" %0,0\n" \
".section __bug_table,\"a\"\n" \
"\t"PPC_LONG" 1b,%1,%2,%3\n" \
".previous" \
: : "r" ((long)(x)), "i" (__LINE__), \
"i" (__FILE__), "i" (__FUNCTION__)); \
} \
} while (0)

#define WARN_ON(x) do { \
#define WARN() do { \
__asm__ __volatile__( \
"1: twi 31,0,0\n" \
".section __bug_table,\"a\"\n" \
"\t"PPC_LONG" 1b,%0,%1,%2\n" \
".previous" \
: : "i" (__LINE__ + BUG_WARNING_TRAP), \
"i" (__FILE__), "i" (__FUNCTION__)); \
} while (0)

#define WARN_ON(x) do { \
if (__builtin_constant_p(x)) { \
if (x) \
WARN(); \
} else { \
__asm__ __volatile__( \
"1: "PPC_TLNEI" %0,0\n" \
".section __bug_table,\"a\"\n" \
"\t"PPC_LONG" 1b,%1,%2,%3\n" \
".previous" \
: : "r" ((long)(x)), \
"i" (__LINE__ + BUG_WARNING_TRAP), \
"i" (__FILE__), "i" (__FUNCTION__)); \
} \
} while (0)

#define HAVE_ARCH_BUG
Expand Down

0 comments on commit e3f94b8

Please sign in to comment.