Skip to contentSkip to conversation

bswap: Clean prototypes of st* functions

PATCH Applied Stefan Weil 3 participants 6 messages Feb 19, 2014 – Feb 22, 2014

lore
Share & tools
lore
#0 lore raw

cover bswap: Clean prototypes of st* functions

These modifications avoid type conversions for non optimized code.

ld* function prototypes will follow later.

[PATCH 1/2] bswap: Modify prototype of stb_p (avoid type [PATCH 2/2] bswap: Modify prototypes of st[wl]_{le,be}_p (avoid type

#1 lore raw

PATCH 1/2 bswap: Modify prototype of stb_p (avoid type conversions)

The function uses an uint8_t value, so show this in the function prototype. Non-optimizing compilers will avoid unnecessary type conversions from (u)int8_t to int and back to uint8_t when generating calls of this inline function.

stw_p, stl_p and stq_p already use similar prototypes.

---
 include/qemu/bswap.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/bswap.h +1 -1
index 437b8e0..0cc11a5 100644
@@ -228,7 +228,7 @@ static inline int ldsb_p(const void *ptr)
     return *(int8_t *)ptr;
 }
 
-static inline void stb_p(void *ptr, int v)
+static inline void stb_p(void *ptr, uint8_t v)
 {
     *(uint8_t *)ptr = v;
 }
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/2 bswap: Modify prototypes of st[wl]_{le, be}_p (avoid type conversions)

In reply to Stefan Weil

The function use uint16_t or uint32_t values, so show this in the function prototypes. Non-optimizing compilers will avoid unnecessary type conversions when generating calls of these inline function.

stq_le_p, stq_be_p already use similar prototypes.

---
 include/qemu/bswap.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/qemu/bswap.h +4 -4
index 0cc11a5..0cb7c05 100644
@@ -300,12 +300,12 @@ static inline uint64_t ldq_le_p(const void *ptr)
     return le_bswap(ldq_p(ptr), 64);
 }
 
-static inline void stw_le_p(void *ptr, int v)
+static inline void stw_le_p(void *ptr, uint16_t v)
 {
     stw_p(ptr, le_bswap(v, 16));
 }
 
-static inline void stl_le_p(void *ptr, int v)
+static inline void stl_le_p(void *ptr, uint32_t v)
 {
     stl_p(ptr, le_bswap(v, 32));
 }
@@ -365,12 +365,12 @@ static inline uint64_t ldq_be_p(const void *ptr)
     return be_bswap(ldq_p(ptr), 64);
 }
 
-static inline void stw_be_p(void *ptr, int v)
+static inline void stw_be_p(void *ptr, uint16_t v)
 {
     stw_p(ptr, be_bswap(v, 16));
 }
 
-static inline void stl_be_p(void *ptr, int v)
+static inline void stl_be_p(void *ptr, uint32_t v)
 {
     stl_p(ptr, be_bswap(v, 32));
 }
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] bswap: Modify prototypes of st[wl]_{le, be}_p (avoid type conversions)

Am 19.02.2014 06:11, schrieb Stefan Weil:

Quoted 1 line

The function use uint16_t or uint32_t values, so show this in the function

The functions ...

Quoted 2 lines

prototypes. Non-optimizing compilers will avoid unnecessary type conversions when generating calls of these inline function.

... inline functions.

Maybe these typos can be fixed during the commit.

Thanks,
Stefan

Reviewed-by on the v1 series
#4 lore raw
In reply to Stefan Weil
Quoted 7 lines · Stefan Weil

These modifications avoid type conversions for non optimized code.

ld* function prototypes will follow later.

[PATCH 1/2] bswap: Modify prototype of stb_p (avoid type [PATCH 2/2] bswap: Modify prototypes of st[wl]_{le,be}_p (avoid type

It probably wouldn't hurt to audit all call sites, but it does look reasonable.

#5 lore raw
In reply to Stefan Weil
Quoted 6 lines · Stefan Weil

These modifications avoid type conversions for non optimized code.

ld* function prototypes will follow later.

[PATCH 1/2] bswap: Modify prototype of stb_p (avoid type [PATCH 2/2] bswap: Modify prototypes of st[wl]_{le,be}_p (avoid type

Thanks, applied to the trivial patches queue, with s/function/functions/ change in description for the second patch.

/mjt