Re: [PATCH 2/2] Define and use new SPICE_MAGIC_CONST macro

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Aug 07, 2015 at 01:29:57PM +0100, Frediano Ziglio wrote:
> This macro allow to define magic constants without using weird
> memory tweacks.
> This remove some possible warning from some compiler and
> make code more optimized as compiler is able to compute the
> constant.
> 
> Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
> ---
>  spice/controller_prot.h   | 2 +-
>  spice/foreign_menu_prot.h | 2 +-
>  spice/macros.h            | 6 ++++++
>  spice/protocol.h          | 2 +-
>  spice/qxl_dev.h           | 4 ++--
>  spice/stats.h             | 2 +-
>  spice/vdi_dev.h           | 2 +-
>  7 files changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/spice/macros.h b/spice/macros.h
> index 018ff32..4647ee3 100644
> --- a/spice/macros.h
> +++ b/spice/macros.h
> @@ -359,5 +359,11 @@
>  #  define SPICE_BYTESWAP64(val) (SPICE_BYTESWAP64_CONSTANT (val))
>  #endif /* generic */
>  
> +#if SPICE_ENDIAN == SPICE_ENDIAN_LITTLE
> +#define SPICE_MAGIC_CONST(s) ((uint32_t)(s[0]+s[1]*0x100u+s[2]*0x10000u+s[3]*0x1000000u))
> +#else
> +#define SPICE_MAGIC_CONST(s) ((uint32_t)(s[3]+s[2]*0x100u+s[1]*0x10000u+s[0]*0x1000000u))
> +#endif
> +

If I'm not mistaken, we can keep the (*(const uint32_t*)"QXRO") method
for little-endian (or are you avoiding -Wcast-align warnings at
the same time)? This could potentially use SPICE_BYTESWAP32_CONSTANT
(but I assume there is still this -Wcast-align warning to take care of?)
What about SPICE_ENDIAN_PDP, I believe this is not going to be correct?
(I would just error out at compile time if we find out the endianness is
PDP). I'd favour << and | over +/* for what it's worth, and make sure we
are operating on unsigned chars.

Christophe

Attachment: pgp0xiYTHfNTy.pgp
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]