bswap: Clean prototypes of st* functions
PATCH 1/2 bswap: Modify prototype of stb_p (avoid type conversions)
In reply to Stefan WeilThe 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
@@ -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
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
PATCH 2/2 bswap: Modify prototypes of st[wl]_{le, be}_p (avoid type conversions)
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
@@ -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
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_toruint32_tvalues, 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
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.
Michael Tokarev
AppliedQuoted 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