[Spice-devel] [PATCH spice-common v2 1/3] Make the compiler work out better way to write unaligned memory

Frediano Ziglio fziglio at redhat.com
Mon Sep 25 14:22:57 UTC 2017


> 
> On Mon, Sep 25, 2017 at 09:04:16AM -0400, Frediano Ziglio wrote:
> > Yes, intentional and consistent with previous code.
> > The usage of unsigned for BYTESWAP avoid sign extension during arithmetic.
> 
> If BYTESWAP has such issues (and I don't think it does), then this should be
> fixed.
> ack on being consistent with what was done before.
> 
> Christophe
> 

Looking at macro sources do not seem to have such issue.

OT: Looking at macro sources why don't we use asm/swab.h or byteswap.h on Linux?
They provide support for more architectures. Or something like

--- a/spice/macros.h
+++ b/spice/macros.h
@@ -248,7 +248,11 @@
 
 /* Arch specific stuff for speed
  */
-#if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)
+#if defined (__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
+#  define SPICE_BYTESWAP16(val) __builtin_bswap16(val)
+#  define SPICE_BYTESWAP32(val) __builtin_bswap32(val)
+#  define SPICE_BYTESWAP64(val) __builtin_bswap64(val)
+#elif defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)
 #  if defined (__i386__)
 #    define SPICE_BYTESWAP16_IA32(val) \
        (__extension__                                          \

Frediano


More information about the Spice-devel mailing list