From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUxY1-0000dq-5I for qemu-devel@nongnu.org; Tue, 01 Apr 2014 08:12:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUxXv-0006Uu-10 for qemu-devel@nongnu.org; Tue, 01 Apr 2014 08:12:09 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:44840 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUxXu-0006Un-R9 for qemu-devel@nongnu.org; Tue, 01 Apr 2014 08:12:02 -0400 References: <1396052834-26834-1-git-send-email-rth@twiddle.net> <1396052834-26834-3-git-send-email-rth@twiddle.net> From: Alex =?utf-8?Q?Benn=C3=A9e?= In-reply-to: <1396052834-26834-3-git-send-email-rth@twiddle.net> Date: Tue, 01 Apr 2014 13:12:32 +0100 Message-ID: <87lhvps0y7.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 2/8] tcg: Avoid stores to unaligned addresses List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org, aurelien@aurel32.net Richard Henderson writes: > From: Peter Maydell > > Avoid stores to unaligned addresses in TCG code generation, by using the > usual memcpy() approach. (Using bswap.h would drag a lot of QEMU baggage > into TCG, so it's simpler just to do direct memcpy() here.) I notice bswap.h has an interesting exultation to the efficiency of inline memcpy's which I hope is justified. Reviewed-by: Alex Bennée > > Signed-off-by: Peter Maydell > Signed-off-by: Richard Henderson > --- > tcg/tcg.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/tcg/tcg.c b/tcg/tcg.c > index f1e0763..60f06c5 100644 > --- a/tcg/tcg.c > +++ b/tcg/tcg.c > @@ -125,21 +125,21 @@ static inline void tcg_out8(TCGContext *s, uint8_t v) > static inline void tcg_out16(TCGContext *s, uint16_t v) > { > uint8_t *p = s->code_ptr; > - *(uint16_t *)p = v; > + memcpy(p, &v, sizeof(v)); > s->code_ptr = p + 2; > } > > static inline void tcg_out32(TCGContext *s, uint32_t v) > { > uint8_t *p = s->code_ptr; > - *(uint32_t *)p = v; > + memcpy(p, &v, sizeof(v)); > s->code_ptr = p + 4; > } > > static inline void tcg_out64(TCGContext *s, uint64_t v) > { > uint8_t *p = s->code_ptr; > - *(uint64_t *)p = v; > + memcpy(p, &v, sizeof(v)); > s->code_ptr = p + 8; > } -- Alex Bennée