Skip to contentSkip to conversation

coccinelle: orplus: reorganize to improve performance

PATCH In review Julia Lawall 2 participants 2 messages Nov 13, 2017 – Nov 16, 2017 Coccinelle/Semantic Patches (SmPL)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 coccinelle: orplus: reorganize to improve performance

Adding two #define constants is less common than performing & and | operations on them, so put the addition first to reduce the set of cases that have to be considered in detail. At the same time, add & and | patterns for both arguments of +, to account for commutativity and obtain more results.

Running time is divided by 3 when applying this to the whole kernel on my laptop with an Intel i5-6200U CPU.

---

v2: added SOB and fixed typos in the commit message

scripts/coccinelle/misc/orplus.cocci +29 -14
index 81fabf3..08de5be 100644
@@ -14,7 +14,19 @@ virtual report
 virtual context
 
 @r@
-constant c;
+constant c,c1;
+identifier i,i1;
+position p;
+@@
+
+(
+ c1 + c - 1
+|
+ c1 at i1 + at p c at i
+)
+
+ at s@
+constant r.c, r.c1;
 identifier i;
 expression e;
 @@
@@ -27,28 +39,31 @@ e & c at i
 e |= c at i
 |
 e &= c at i
+|
+e | c1 at i
+|
+e & c1 at i
+|
+e |= c1 at i
+|
+e &= c1 at i
 )
 
- at s@
-constant r.c,c1;
-identifier i1;
-position p;
+ at depends on s@
+position r.p;
+constant c1,c2;
 @@
 
-(
- c1 + c - 1
-|
-*c1 at i1 + at p c
-)
+* c1 + at p c2
 
- at script:python depends on org@
-p << s.p;
+ at script:python depends on s && org@
+p << r.p;
 @@
 
 cocci.print_main("sum of probable bitmasks, consider |",p)
 
- at script:python depends on report@
-p << s.p;
+@script:python depends on s && report@
+p << r.p;
 @@
 
 msg = "WARNING: sum of probable bitmasks, consider |"
#1 lore raw

2017-11-13 14:53 GMT+09:00 Julia Lawall <[email protected]>:

Quoted 6 lines

Adding two #define constants is less common than performing & and | operations on them, so put the addition first to reduce the set of cases that have to be considered in detail. At the same time, add & and | patterns for both arguments of +, to account for commutativity and obtain more results.

Quoted 8 lines

Running time is divided by 3 when applying this to the whole kernel on my laptop with an Intel i5-6200U CPU.

---

v2: added SOB and fixed typos in the commit message

Applied to linux-kbuild/misc. Thanks!

Signature · 2 lines
Best Regards
Masahiro Yamada