diff mbox

[1/3] scripts: add muldiv64() checking coccinelle scripts

Message ID 1462367048-20997-2-git-send-email-lvivier@redhat.com
State New
Headers show

Commit Message

Laurent Vivier May 4, 2016, 1:04 p.m. UTC
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 scripts/coccinelle/remove_muldiv64.cocci |  6 +++++
 scripts/coccinelle/swap_muldiv64.cocci   | 46 ++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
 create mode 100644 scripts/coccinelle/remove_muldiv64.cocci
 create mode 100644 scripts/coccinelle/swap_muldiv64.cocci
diff mbox

Patch

diff --git a/scripts/coccinelle/remove_muldiv64.cocci b/scripts/coccinelle/remove_muldiv64.cocci
new file mode 100644
index 0000000..4c10bd5
--- /dev/null
+++ b/scripts/coccinelle/remove_muldiv64.cocci
@@ -0,0 +1,6 @@ 
+// replace muldiv64(a, 1, b) by "a / b"
+@@
+expression a, b;
+@@
+-muldiv64(a, 1, b)
++a / b
diff --git a/scripts/coccinelle/swap_muldiv64.cocci b/scripts/coccinelle/swap_muldiv64.cocci
new file mode 100644
index 0000000..39a278d
--- /dev/null
+++ b/scripts/coccinelle/swap_muldiv64.cocci
@@ -0,0 +1,46 @@ 
+// replace muldiv64(i32, i64, x) by muldiv64(i64, i32, x)
+@filter@
+typedef uint64_t;
+typedef int64_t;
+typedef uint32_t;
+typedef int32_t;
+uint64_t u64;
+int64_t s64;
+uint32_t u32;
+int32_t s32;
+int si;
+unsigned int ui;
+long sl;
+unsigned long ul;
+expression b;
+position p;
+@@
+	muldiv64(
+(
+si
+|
+ui
+|
+s32
+|
+u32
+)
+,
+(
+sl
+|
+ul
+|
+u64
+|
+s64
+)
+, b)@p
+
+@swap@
+position filter.p;
+expression a, b, c;
+@@
+
+-muldiv64(a,b,c)@p
++muldiv64(b,a,c)