Skip to content

Commit b0687c1

Browse files
goldsteinnakpm00
authored andcommitted
lib/rbtree: use '+' instead of '|' for setting color.
This has a slight benefit for x86 and has no effect on other targets. The benefit to x86 is it change the codegen for setting a node to block from `mov %r0, %r1; or $RB_BLACK, %r1` to `lea RB_BLACK(%r0), %r1` which saves an instructions. In all other cases it just replace ALU with ALU (or -> and) which perform the same on all machines I am aware of. Total instructions in rbtree.o: Before - 802 After - 782 so it saves about 20 `mov` instructions. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Noah Goldstein <[email protected]> Cc: Michel Lespinasse <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1be2edb commit b0687c1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

include/linux/rbtree_augmented.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ RB_DECLARE_CALLBACKS(RBSTATIC, RBNAME, \
156156

157157
static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p)
158158
{
159-
rb->__rb_parent_color = rb_color(rb) | (unsigned long)p;
159+
rb->__rb_parent_color = rb_color(rb) + (unsigned long)p;
160160
}
161161

162162
static inline void rb_set_parent_color(struct rb_node *rb,
163163
struct rb_node *p, int color)
164164
{
165-
rb->__rb_parent_color = (unsigned long)p | color;
165+
rb->__rb_parent_color = (unsigned long)p + color;
166166
}
167167

168168
static inline void

lib/rbtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
static inline void rb_set_black(struct rb_node *rb)
6060
{
61-
rb->__rb_parent_color |= RB_BLACK;
61+
rb->__rb_parent_color += RB_BLACK;
6262
}
6363

6464
static inline struct rb_node *rb_red_parent(struct rb_node *red)

0 commit comments

Comments
 (0)