Index: cdefs.h
===================================================================
RCS file: /space2/ncvs/src/sys/sys/cdefs.h,v
retrieving revision 1.75
diff -u -p -r1.75 cdefs.h
--- cdefs.h	25 Jul 2003 18:40:36 -0000	1.75
+++ cdefs.h	26 Sep 2003 21:22:25 -0000
@@ -49,6 +49,16 @@
 #endif
 
 /*
+ * Macro to test if we're using a specific version of gcc or later.
+ */
+#ifdef __GNUC__
+#define	__GNUC_PREREQ__(ma, mi)	\
+        ((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)))
+#else
+#define	__GNUC_PREREQ__(ma, mi)	0
+#endif
+
+/*
  * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
  * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
  * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
@@ -121,42 +131,38 @@
 #define	__packed
 #define	__aligned(x)
 #define	__section(x)
-#else
-#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 5
+#elif !__GNUC_PREREQ__(2, 5)
 #define	__dead2
 #define	__pure2
 #define	__unused
-#endif
-#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7
+#elif __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7
 #define	__dead2		__attribute__((__noreturn__))
 #define	__pure2		__attribute__((__const__))
 #define	__unused
 /* XXX Find out what to do for __packed, __aligned and __section */
-#endif
-#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ == 3
+#elif __GNUC_PREREQ__(2, 7)__
 #define	__dead2		__attribute__((__noreturn__))
 #define	__pure2		__attribute__((__const__))
 #define	__unused	__attribute__((__unused__))
 #define	__packed	__attribute__((__packed__))
 #define	__aligned(x)	__attribute__((__aligned__(x)))
 #define	__section(x)	__attribute__((__section__(x)))
-#endif
-#endif
+#endif	/* lint */
 
-#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ >= 4
+#if __GNUC_PREREQ__(3, 1)
 #define	__always_inline	__attribute__((__always_inline__))
 #else
 #define	__always_inline
 #endif
 
-#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ >= 4
+#if __GNUC_PREREQ__(3, 3)
 #define __nonnull(x)	__attribute__((__nonnull__(x)))
 #else
 #define __nonnull(x)
 #endif
 
 /* XXX: should use `#if __STDC_VERSION__ < 199901'. */
-#if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3)
+#if !__GNUC_PREREQ__(2, 7)
 #define	__func__	NULL
 #endif
 
@@ -179,6 +185,42 @@
 #endif
 
 /*
+ * GNU C version 2.96 adds explicit branch prediction so that
+ * the CPU back-end can hint the processor and also so that
+ * code blocks can be reordered such that the predicted path
+ * sees a more linear flow, thus improving cache behavior, etc.
+ *
+ * The following two macros provide us with a way to utilize this
+ * compiler feature.  Use __predict_true() if you expect the expression
+ * to evaluate to true, and __predict_false() if you expect the
+ * expression to evaluate to false.
+ *
+ * A few notes about usage:
+ *
+ *	* Generally, __predict_false() error condition checks (unless
+ *	  you have some _strong_ reason to do otherwise, in which case
+ *	  document it), and/or __predict_true() `no-error' condition
+ *	  checks, assuming you want to optimize for the no-error case.
+ *
+ *	* Other than that, if you don't know the likelihood of a test
+ *	  succeeding from empirical or other `hard' evidence, don't
+ *	  make predictions.
+ *
+ *	* These are meant to be used in places that are run `a lot'.
+ *	  It is wasteful to make predictions in code that is run
+ *	  seldomly (e.g. at subsystem initialization time) as the
+ *	  basic block reordering that this affects can often generate
+ *	  larger code.
+ */
+#if __GNUC_PREREQ__(2, 96)
+#define __predict_true(exp)     __builtin_expect((exp), 1)
+#define __predict_false(exp)    __builtin_expect((exp), 0)
+#else
+#define __predict_true(exp)     (exp)
+#define __predict_false(exp)    (exp)
+#endif
+
+/*
  * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
  * require it.
  */
@@ -190,7 +232,7 @@
  * that are known to support the features properly (old versions of gcc-2
  * didn't permit keeping the keywords out of the application namespace).
  */
-#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 7
+#if !__GNUC_PREREQ__(2, 7)
 #define	__printflike(fmtarg, firstvararg)
 #define	__scanflike(fmtarg, firstvararg)
 #else
Index: systm.h
===================================================================
RCS file: /space2/ncvs/src/sys/sys/systm.h,v
retrieving revision 1.197
diff -u -p -r1.197 systm.h
--- systm.h	22 Jul 2003 06:01:11 -0000	1.197
+++ systm.h	26 Sep 2003 21:07:41 -0000
@@ -45,6 +45,7 @@
 #include <machine/atomic.h>
 #include <machine/cpufunc.h>
 #include <sys/callout.h>
+#include <sys/cdefs.h>
 #include <sys/queue.h>
 #include <sys/stdint.h>		/* for people using printf mainly */
 
@@ -77,7 +78,10 @@ extern int bootverbose;		/* nonzero to p
 extern int maxusers;		/* system tune hint */
 
 #ifdef	INVARIANTS		/* The option is always available */
-#define	KASSERT(exp,msg)	do { if (!(exp)) panic msg; } while (0)
+#define	KASSERT(exp,msg) do {						\
+	if (__predict_false(!(exp)))					\
+		panic msg;						\
+} while (0)
 #else
 #define	KASSERT(exp,msg)
 #endif
