Skip to contentSkip to conversation

include: Add roundup_pow_of_two helper function

PATCH In review Yuval Shaia 3 participants 3 messages Nov 28, 2016 – Nov 29, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 include: Add roundup_pow_of_two helper function

Move private implementation of rthe function to osdep.h

---
 hw/pci/shpc.c        | 12 +-----------
 include/qemu/osdep.h | 10 ++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)
hw/pci/shpc.c +1 -11
index 3dcd472..4b8982d 100644
@@ -122,16 +122,6 @@
 #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1)
 #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1)
 
-static int roundup_pow_of_two(int x)
-{
-    x |= (x >> 1);
-    x |= (x >> 2);
-    x |= (x >> 4);
-    x |= (x >> 8);
-    x |= (x >> 16);
-    return x + 1;
-}
-
 static uint16_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk)
 {
     uint8_t *status = shpc->config + SHPC_SLOT_STATUS(slot);
@@ -654,7 +644,7 @@ int shpc_init(PCIDevice *d, PCIBus *sec_bus, MemoryRegion *bar, unsigned offset)
 
 int shpc_bar_size(PCIDevice *d)
 {
-    return roundup_pow_of_two(SHPC_SLOT_REG(SHPC_MAX_SLOTS));
+    return round_up_pow_of_two(SHPC_SLOT_REG(SHPC_MAX_SLOTS));
 }
 
 void shpc_cleanup(PCIDevice *d, MemoryRegion *bar)
include/qemu/osdep.h +10 -0
index 689f253..74d5c30 100644
@@ -194,6 +194,16 @@ extern int daemon(int, int);
 #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d))
 #endif
 
+static inline int round_up_pow_of_two(int x)
+{
+	x |= (x >> 1);
+	x |= (x >> 2);
+	x |= (x >> 4);
+	x |= (x >> 8);
+	x |= (x >> 16);
+	return x + 1;
+}
+
 #ifndef DIV_ROUND_UP
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
 #endif
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 1 line · Yuval Shaia

Move private implementation of rthe function to osdep.h

Hi Yuval,

In my opinion we need to use the function in at least two places in order to promote it to a global utility.

You are welcome to try to find another place needing it.

Thanks,
Marcel

Quoted 59 lines
---
 hw/pci/shpc.c        | 12 +-----------
 include/qemu/osdep.h | 10 ++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)
hw/pci/shpc.c +1 -11
index 3dcd472..4b8982d 100644
@@ -122,16 +122,6 @@
 #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1)
 #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1)
 
-static int roundup_pow_of_two(int x)
-{
-    x |= (x >> 1);
-    x |= (x >> 2);
-    x |= (x >> 4);
-    x |= (x >> 8);
-    x |= (x >> 16);
-    return x + 1;
-}
-
 static uint16_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk)
 {
     uint8_t *status = shpc->config + SHPC_SLOT_STATUS(slot);
@@ -654,7 +644,7 @@ int shpc_init(PCIDevice *d, PCIBus *sec_bus, MemoryRegion *bar, unsigned offset)
 
 int shpc_bar_size(PCIDevice *d)
 {
-    return roundup_pow_of_two(SHPC_SLOT_REG(SHPC_MAX_SLOTS));
+    return round_up_pow_of_two(SHPC_SLOT_REG(SHPC_MAX_SLOTS));
 }
 
 void shpc_cleanup(PCIDevice *d, MemoryRegion *bar)
include/qemu/osdep.h +10 -0
index 689f253..74d5c30 100644
@@ -194,6 +194,16 @@ extern int daemon(int, int);
 #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d))
 #endif
 
+static inline int round_up_pow_of_two(int x)
+{
+	x |= (x >> 1);
+	x |= (x >> 2);
+	x |= (x >> 4);
+	x |= (x >> 8);
+	x |= (x >> 16);
+	return x + 1;
+}
+
 #ifndef DIV_ROUND_UP
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
 #endif
#2 lore raw
In reply to Yuval Shaia
Your series seems to have some coding style problems. See output below for more information:

Hi,

Your series seems to have some coding style problems. See output below for more information:

Subject: [Qemu-devel] [PATCH] include: Add roundup_pow_of_two helper function
Type: series
Message-id: [email protected]

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test'
61b93c6 include: Add roundup_pow_of_two helper function

=== OUTPUT BEGIN ===
Checking PATCH 1/1: include: Add roundup_pow_of_two helper function...
ERROR: code indent should never use tabs
#51: FILE: include/qemu/osdep.h:199:
+^Ix |= (x >> 1);$

ERROR: code indent should never use tabs
#52: FILE: include/qemu/osdep.h:200:
+^Ix |= (x >> 2);$

ERROR: code indent should never use tabs
#53: FILE: include/qemu/osdep.h:201:
+^Ix |= (x >> 4);$

ERROR: code indent should never use tabs
#54: FILE: include/qemu/osdep.h:202:
+^Ix |= (x >> 8);$

ERROR: code indent should never use tabs
#55: FILE: include/qemu/osdep.h:203:
+^Ix |= (x >> 16);$

ERROR: code indent should never use tabs
#56: FILE: include/qemu/osdep.h:204:
+^Ireturn x + 1;$

total: 6 errors, 0 warnings, 40 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]