public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: Daryl Van Vorst <daryl@wideray.com>,
	"'BlueZ Mailing List'" <bluez-devel@lists.sourceforge.net>
Subject: Re: [Bluez-devel] Alignment issue
Date: Thu, 20 Jan 2005 14:30:53 +0000	[thread overview]
Message-ID: <1106231454.26551.582.camel@hades.cambridge.redhat.com> (raw)
In-Reply-To: <1092208405.4564.227.camel@pegasus>

[-- Attachment #1: Type: text/plain, Size: 965 bytes --]

On Wed, 2004-08-11 at 09:13 +0200, Marcel Holtmann wrote:
> > The attached patch should fix the problem (it does as far as I can tell).
> > The compiler probably thinks both arguments to memcpy() are aligned and so
> > makes an optimization which breaks the copy (because the destination is not
> > actually aligned). Perhaps this is a compiler bug... I'm using gcc 3.3.3.
> > After googling and reading some discussion on the topic it seems that it's
> > probably not a compiler bug. I'll leave that for someone else to decide. :)
> 
> after checking some more resources, you may be right and the compiler
> optimizes here where it should not. I found a comment about gcc and
> using its __builtin_memcpy. Try to replace the memcpy with memmove and
> see if this works.

That isn't guaranteed to work either. This is the patch I've been
testing in the Fedora RPM since August. It lets the compiler know what's
happening so it can generate optimal code.

-- 
dwmw2

[-- Attachment #2: bluez-libs-2.10-align.patch --]
[-- Type: text/x-patch, Size: 1359 bytes --]

--- bluez-libs-2.10/include/bluetooth.h.align	2004-08-16 20:30:12.998705139 +0100
+++ bluez-libs-2.10/include/bluetooth.h	2004-08-16 20:33:14.933543394 +0100
@@ -88,17 +88,21 @@
 #endif
 
 /* Bluetooth unaligned access */
-#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || defined(__s390__) || defined(__cris__)
-#define bt_get_unaligned(ptr) (*(ptr))
-#define bt_put_unaligned(val, ptr) ((void)( *(ptr) = (val) ))
-#else
-#define bt_get_unaligned(ptr) \
-	({ __typeof__(*(ptr)) __tmp; memmove(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })
-#define bt_put_unaligned(val, ptr) \
-	({ __typeof__(*(ptr)) __tmp = (val); \
-	memmove((ptr), &__tmp, sizeof(*(ptr))); \
-	(void)0; })
-#endif
+#define bt_get_unaligned(ptr)                   \
+({                                              \
+        struct __attribute__((packed)) {        \
+                typeof(*(ptr)) __v;             \
+        }  *__p = (ptr);                        \
+        __p->__v;                               \
+})
+
+#define bt_put_unaligned(val, ptr)		\
+do {                                            \
+        struct __attribute__((packed)) {        \
+                typeof(*(ptr)) __v;             \
+        }  *__p = (ptr);                        \
+        __p->__v = (val);                       \
+} while(0)
 
 /* BD Address */
 typedef struct {

  parent reply	other threads:[~2005-01-20 14:30 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-10 18:38 [Bluez-devel] Alignment issue Daryl Van Vorst
2004-08-10 23:12 ` Marcel Holtmann
2004-08-11  9:20   ` Stephen Crane
2004-08-11 11:08     ` David Woodhouse
2004-08-11 19:33       ` Marcel Holtmann
2004-08-11  7:13 ` Marcel Holtmann
2004-08-11 16:44   ` Daryl Van Vorst
2004-08-11 19:31     ` Marcel Holtmann
2004-08-12  8:34       ` David Woodhouse
2004-08-12  9:27         ` Marcel Holtmann
2004-08-12 10:01           ` David Woodhouse
2004-08-12 10:22             ` Marcel Holtmann
2004-08-12 10:35               ` David Woodhouse
2004-08-12 11:00                 ` Marcel Holtmann
2004-08-12 11:33                   ` David Woodhouse
2004-08-12 11:49                     ` Marcel Holtmann
2004-08-12 12:02                       ` David Woodhouse
2004-08-12 12:29                         ` Marcel Holtmann
2004-08-12 13:36                         ` Marcel Holtmann
2004-08-13  8:07                           ` David Woodhouse
2004-08-13  9:05                             ` Marcel Holtmann
2004-08-13  9:14                               ` David Woodhouse
2004-08-13 11:52                               ` David Woodhouse
2004-08-13 12:40                                 ` Marcel Holtmann
2004-08-12 12:53               ` David Woodhouse
2004-08-13  9:58                 ` Marcel Holtmann
2004-08-13 10:56                   ` David Woodhouse
2004-08-12 10:10           ` Stephen Crane
2004-08-12 10:25             ` Marcel Holtmann
2005-01-20 14:30   ` David Woodhouse [this message]
2005-01-20 14:45     ` Marcel Holtmann
2005-01-20 14:59       ` David Woodhouse
2005-01-20 18:14         ` Marcel Holtmann
2005-01-21  8:26           ` David Woodhouse
2005-01-23  8:12             ` Marcel Holtmann
2005-01-23 11:39         ` Marcel Holtmann
2005-01-23 12:29           ` David Woodhouse
2005-01-23 14:40             ` Marcel Holtmann
2005-01-23 15:11               ` David Woodhouse
2005-01-23 15:22                 ` Marcel Holtmann
2005-01-23 23:16                   ` David Woodhouse
  -- strict thread matches above, loose matches on Subject: below --
2004-08-16  9:48 john smith
2004-08-16 10:15 ` Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1106231454.26551.582.camel@hades.cambridge.redhat.com \
    --to=dwmw2@infradead.org \
    --cc=bluez-devel@lists.sourceforge.net \
    --cc=daryl@wideray.com \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox