Skip to contentSkip to conversation

muldiv64() trivial fixes

PATCH Superseded Laurent Vivier 2 participants 5 messages May 4, 2016 Coccinelle/Semantic Patches (SmPL)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover muldiv64() trivial fixes

Some fixes in the use of muldiv64()

The patches have been generated with the help of coccinelle.

The first patch contains the scripts used to generate the two following patches. As it is done for linux, I've added the scripts under scripts/coccinelle.

Laurent Vivier (3):
scripts: add muldiv64() checking coccinelle scripts The only 64bit parameter of muldiv64() is the first one. remove useless muldiv64()

 hw/timer/omap_gptimer.c                  |  4 +--
 hw/usb/hcd-ohci.c                        |  2 +-
 scripts/coccinelle/remove_muldiv64.cocci |  6 +++++
 scripts/coccinelle/swap_muldiv64.cocci   | 46 ++++++++++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 3 deletions(-)
 create mode 100644 scripts/coccinelle/remove_muldiv64.cocci
 create mode 100644 scripts/coccinelle/swap_muldiv64.cocci
Signature · 1 line
2.5.5
#1 lore raw

PATCH 1/3 scripts: add muldiv64() checking coccinelle scripts

---
 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
scripts/coccinelle/remove_muldiv64.cocci new file +6 -0
new file mode 100644
index 0000000..4c10bd5
@@ -0,0 +1,6 @@
+// replace muldiv64(a, 1, b) by "a / b"
+@@
+expression a, b;
+@@
+-muldiv64(a, 1, b)
++a / b
scripts/coccinelle/swap_muldiv64.cocci new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.5.5
#2 lore raw

PATCH 2/3 The only 64bit parameter of muldiv64() is the first one.

In reply to Laurent Vivier

muldiv64() is "uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)"

Some time it is used as muldiv64(uint32_t a, uint64_t b, uint32_t c)"

This patch is the result of coccinelle script scripts/coccinelle/swap_muldiv64.cocci to reorder arguments.

---
 hw/timer/omap_gptimer.c | 4 ++--
 hw/usb/hcd-ohci.c       | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/timer/omap_gptimer.c +2 -2
index 3a43863..5e3e8a6 100644
@@ -133,8 +133,8 @@ static inline void omap_gp_timer_update(struct omap_gp_timer_s *timer)
         timer_mod(timer->timer, timer->time + expires);
 
         if (timer->ce && timer->match_val >= timer->val) {
-            matches = muldiv64(timer->match_val - timer->val,
-                            timer->ticks_per_sec, timer->rate);
+            matches = muldiv64(timer->ticks_per_sec,
+                               timer->match_val - timer->val, timer->rate);
             timer_mod(timer->match, timer->time + matches);
         } else
             timer_del(timer->match);
hw/usb/hcd-ohci.c +1 -1
index ffab561..e5b535f 100644
@@ -1474,7 +1474,7 @@ static uint32_t ohci_get_frame_remaining(OHCIState *ohci)
     if (tks >= usb_frame_time)
         return (ohci->frt << 31);
 
-    tks = muldiv64(1, tks, usb_bit_time);
+    tks = muldiv64(tks, 1, usb_bit_time);
     fr = (uint16_t)(ohci->fi - tks);
 
     return (ohci->frt << 31) | fr;
Signature · 1 line
2.5.5
#3 lore raw

PATCH 3/3 remove useless muldiv64()

In reply to Laurent Vivier

muldiv64(a, 1, b) is like "a / b".

This patch is the result of coccinelle script
scripts/coccinelle/remove_muldiv64.cocci.

---
 hw/usb/hcd-ohci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/hcd-ohci.c +1 -1
index e5b535f..2af6c16 100644
@@ -1474,7 +1474,7 @@ static uint32_t ohci_get_frame_remaining(OHCIState *ohci)
     if (tks >= usb_frame_time)
         return (ohci->frt << 31);
 
-    tks = muldiv64(tks, 1, usb_bit_time);
+    tks = tks / usb_bit_time;
     fr = (uint16_t)(ohci->fi - tks);
 
     return (ohci->frt << 31) | fr;
Signature · 1 line
2.5.5
Reviewed-by on the v1 series
#4 lore raw
In reply to Laurent Vivier
Quoted 4 lines · Laurent Vivier

Some fixes in the use of muldiv64()

The patches have been generated with the help of coccinelle.

Quoted 8 lines

The first patch contains the scripts used to generate the two following patches. As it is done for linux, I've added the scripts under scripts/coccinelle.

Laurent Vivier (3):
scripts: add muldiv64() checking coccinelle scripts The only 64bit parameter of muldiv64() is the first one. remove useless muldiv64()

r~