Skip to contentSkip to conversation

2.4.22pre10: {,un}likely_p() macros for pointers

PATCH New Chip Salzenberg 1 participant 1 message Aug 4, 2003

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 2.4.22pre10: {,un}likely_p() macros for pointers

GCC is warning about a pointer-to-int conversion when the likely() and unlikely() macros are used with pointer values. So, for architectures where pointers are larger than 'int', I suggest this patch.

PS: This patch was made against 2.4.22pre10 plus many patches from the 'aa' kernel series, so it should be considered an example of the patch that might be required in other kernel versions.

Index: linux/include/linux/compiler.h

include/linux/compiler.h renamed from include/linux/compiler.h.old +4 -2
@@ -11,6 +11,8 @@
 #endif
 
-#define likely(x)	__builtin_expect((x),1)
-#define unlikely(x)	__builtin_expect((x),0)
+#define likely(x)	__builtin_expect((x),      1)
+#define likely_p(x)	__builtin_expect((x) != 0, 1)
+#define unlikely(x)	__builtin_expect((x)      ,0)
+#define unlikely_p(x)	__builtin_expect((x) != 0 ,0)
 
 #endif /* __LINUX_COMPILER_H */

Index: linux/kernel/sched.c

kernel/sched.c renamed from kernel/sched.c.old +1 -1
@@ -477,5 +477,5 @@
 	if (unlikely(!prev->mm)) {
 		prev->active_mm = NULL;
-		if (unlikely(rq->prev_mm)) {
+		if (unlikely_p(rq->prev_mm)) {
 			printk(KERN_ERR "rq->prev_mm was %p set to %p - %s\n", rq->prev_mm, oldmm, current->comm);
 			dump_stack();

Index: linux/mm/filemap.c

mm/filemap.c renamed from mm/filemap.c.old +2 -2
@@ -3749,5 +3749,5 @@
 		pr_debug("attempting to read %lu\n", page->index);
 		io->did_read = 1;
-		if (likely(page->mapping)) {
+		if (likely_p(page->mapping)) {
 			locked = 0;
 			io->err = page->mapping->a_ops->readpage(io->file, page);
@@ -3813,5 +3813,5 @@
 		 */
 		if (!TryLockPage(page)) {
-			if (likely(page->mapping)) {
+			if (likely_p(page->mapping)) {
 				int ret = readpage(io->file, page);
 				if (ret)
Signature · 3 lines
Chip Salzenberg               - a.k.a. -               <[email protected]>
"I wanted to play hopscotch with the impenetrable mystery of existence,
    but he stepped in a wormhole and had to go in early."  // MST3K