summarylogtreecommitdiffstats
path: root/wine-list.h-linked-list-cache-line-prefetching.patch
blob: a0cb54bd488e82963cc7e831948bf8b7a12f950d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nils Kuhnhenn <kuhnhenn.nils@gmail.com>
Date: Wed, 24 Aug 2016 19:44:37 +0200
Subject: [PATCH 3/7] wine/list.h: linked list cache line prefetching

---
 include/wine/list.h | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/include/wine/list.h b/include/wine/list.h
index b4d681fe0f..49b1e23a39 100644
--- a/include/wine/list.h
+++ b/include/wine/list.h
@@ -105,7 +105,8 @@ static inline void list_remove( struct list *elem )
 static inline struct list *list_next( const struct list *list, const struct list *elem )
 {
     struct list *ret = elem->next;
-    if (elem->next == list) ret = NULL;
+    if (ret == list) return NULL;
+    __builtin_prefetch(ret->next, 0, 1);
     return ret;
 }
 
@@ -113,7 +114,8 @@ static inline struct list *list_next( const struct list *list, const struct list
 static inline struct list *list_prev( const struct list *list, const struct list *elem )
 {
     struct list *ret = elem->prev;
-    if (elem->prev == list) ret = NULL;
+    if (ret == list) return NULL;
+    __builtin_prefetch(ret->prev, 0, 1);
     return ret;
 }
 
@@ -176,51 +178,53 @@ static inline void list_move_head( struct list *dst, struct list *src )
 
 /* iterate through the list */
 #define LIST_FOR_EACH(cursor,list) \
-    for ((cursor) = (list)->next; (cursor) != (list); (cursor) = (cursor)->next)
+    for ((cursor) = (list)->next, __builtin_prefetch((cursor)->next, 0, 1); \
+         (cursor) != (list); (cursor) = (cursor)->next, __builtin_prefetch((cursor)->next, 0, 1))
 
 /* iterate through the list, with safety against removal */
 #define LIST_FOR_EACH_SAFE(cursor, cursor2, list) \
-    for ((cursor) = (list)->next, (cursor2) = (cursor)->next; \
+    for ((cursor) = (list)->next, (cursor2) = (cursor)->next, __builtin_prefetch((cursor2)->next, 0, 1); \
          (cursor) != (list); \
-         (cursor) = (cursor2), (cursor2) = (cursor)->next)
+         (cursor) = (cursor2), (cursor2) = (cursor)->next, __builtin_prefetch((cursor2)->next, 0, 1))
 
 /* iterate through the list using a list entry */
 #define LIST_FOR_EACH_ENTRY(elem, list, type, field) \
-    for ((elem) = LIST_ENTRY((list)->next, type, field); \
+    for ((elem) = LIST_ENTRY((list)->next, type, field), __builtin_prefetch((elem)->field.next, 0, 1); \
          &(elem)->field != (list); \
-         (elem) = LIST_ENTRY((elem)->field.next, type, field))
+         (elem) = LIST_ENTRY((elem)->field.next, type, field), __builtin_prefetch((elem)->field.next, 0, 1))
 
 /* iterate through the list using a list entry, with safety against removal */
 #define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field) \
     for ((cursor) = LIST_ENTRY((list)->next, type, field), \
-         (cursor2) = LIST_ENTRY((cursor)->field.next, type, field); \
+         (cursor2) = LIST_ENTRY((cursor)->field.next, type, field), __builtin_prefetch((cursor2)->field.next, 0, 1); \
          &(cursor)->field != (list); \
          (cursor) = (cursor2), \
-         (cursor2) = LIST_ENTRY((cursor)->field.next, type, field))
+         (cursor2) = LIST_ENTRY((cursor)->field.next, type, field), __builtin_prefetch((cursor2)->field.next, 0, 1))
 
 /* iterate through the list in reverse order */
 #define LIST_FOR_EACH_REV(cursor,list) \
-    for ((cursor) = (list)->prev; (cursor) != (list); (cursor) = (cursor)->prev)
+    for ((cursor) = (list)->prev, __builtin_prefetch((cursor)->prev, 0, 1); \
+         (cursor) != (list); (cursor) = (cursor)->prev, __builtin_prefetch((cursor)->prev, 0, 1))
 
 /* iterate through the list in reverse order, with safety against removal */
 #define LIST_FOR_EACH_SAFE_REV(cursor, cursor2, list) \
-    for ((cursor) = (list)->prev, (cursor2) = (cursor)->prev; \
+    for ((cursor) = (list)->prev, (cursor2) = (cursor)->prev, __builtin_prefetch((cursor2)->prev, 0, 1); \
          (cursor) != (list); \
-         (cursor) = (cursor2), (cursor2) = (cursor)->prev)
+         (cursor) = (cursor2), (cursor2) = (cursor)->prev, __builtin_prefetch((cursor2)->prev, 0, 1))
 
 /* iterate through the list in reverse order using a list entry */
 #define LIST_FOR_EACH_ENTRY_REV(elem, list, type, field) \
-    for ((elem) = LIST_ENTRY((list)->prev, type, field); \
+    for ((elem) = LIST_ENTRY((list)->prev, type, field), __builtin_prefetch((elem)->field.prev, 0, 1); \
          &(elem)->field != (list); \
-         (elem) = LIST_ENTRY((elem)->field.prev, type, field))
+         (elem) = LIST_ENTRY((elem)->field.prev, type, field), __builtin_prefetch((elem)->field.prev, 0, 1))
 
 /* iterate through the list in reverse order using a list entry, with safety against removal */
 #define LIST_FOR_EACH_ENTRY_SAFE_REV(cursor, cursor2, list, type, field) \
     for ((cursor) = LIST_ENTRY((list)->prev, type, field), \
-         (cursor2) = LIST_ENTRY((cursor)->field.prev, type, field); \
+         (cursor2) = LIST_ENTRY((cursor)->field.prev, type, field), __builtin_prefetch((cursor2)->field.prev, 0, 1); \
          &(cursor)->field != (list); \
          (cursor) = (cursor2), \
-         (cursor2) = LIST_ENTRY((cursor)->field.prev, type, field))
+         (cursor2) = LIST_ENTRY((cursor)->field.prev, type, field), __builtin_prefetch((cursor2)->field.prev, 0, 1))
 
 /* macros for statically initialized lists */
 #undef LIST_INIT
-- 
2.12.2