From patchwork Sat Jan 5 00:39:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 209593 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6FA8E2C0084 for ; Sat, 5 Jan 2013 12:30:54 +1100 (EST) Received: from localhost ([::1]:53864 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrHoe-0001fe-86 for incoming@patchwork.ozlabs.org; Fri, 04 Jan 2013 19:40:48 -0500 Received: from eggs.gnu.org ([208.118.235.92]:60694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrHnd-00085b-4C for qemu-devel@nongnu.org; Fri, 04 Jan 2013 19:39:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TrHnZ-0008Kz-AU for qemu-devel@nongnu.org; Fri, 04 Jan 2013 19:39:45 -0500 Received: from mail-ia0-f180.google.com ([209.85.210.180]:37618) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrHnZ-0008Kq-5x for qemu-devel@nongnu.org; Fri, 04 Jan 2013 19:39:41 -0500 Received: by mail-ia0-f180.google.com with SMTP id t4so14571855iag.11 for ; Fri, 04 Jan 2013 16:39:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=1co3hFCODKd26DruG5qeiYV1RcgTr9MTaNDPYBBCAs0=; b=UMpGjLfxZ6IkLa8nkY91W45aMd1HumNDSOS5j14ccTxQiUb3dpWzhOnahEPQwJKt7e 01CH+mZaDKo6uHKo7Iz5GEh+VSr59X1X9+UeF5DMiIs9HUanhah/TYHW737TLfATIkPw cQxxbKmBiclTvPPBzJjdvNzZt7wEI5vshdoYxlcjD88VOlHCjeXTSlbw0xh81qmVRR5v LTI/So+lSg9pk6/uCkKYU8ZQj7smTXaZuESz76TxImitRoCXXLvAOtUqyYkNnphvoal1 yhplHquja86ShFcAsyRtOm/YNrzsEpQsJtVS/DOz3sCxDp5HqZ2a1faDi3/IwHEZHd9v fc2w== X-Received: by 10.50.220.202 with SMTP id py10mr164942igc.109.1357346380672; Fri, 04 Jan 2013 16:39:40 -0800 (PST) Received: from anchor.twiddle.home.com (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPS id as6sm940417igc.8.2013.01.04.16.39.39 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 04 Jan 2013 16:39:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 4 Jan 2013 16:39:28 -0800 Message-Id: <1357346373-13898-4-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1357346373-13898-1-git-send-email-rth@twiddle.net> References: <1357346373-13898-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.180 Cc: Blue Swirl , Riku Voipio Subject: [Qemu-devel] [PATCH 3/8] bswap: Add host endian unaligned access functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Richard Henderson --- include/qemu/bswap.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index b2a8f94..381554b 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -226,6 +226,8 @@ static inline uint32_t qemu_bswap_len(uint32_t value, int len) return bswap32(value) >> (32 - 8 * len); } +/* Unions for reinterpreting between floats and integers. */ + typedef union { float32 f; uint32_t l; @@ -309,7 +311,7 @@ typedef union { * q: 64 bits * * endian is: - * (empty): 8 bit access + * (empty): host endian * be : big endian * le : little endian */ @@ -328,6 +330,53 @@ static inline void stb_p(void *ptr, int v) *(uint8_t *)ptr = v; } +/* Any compiler worth its salt will turn these memcpy into native unaligned + operations. Thus we don't need to play games with packed attributes, or + inline byte-by-byte stores. */ + +static inline int lduw_p(const void *ptr) +{ + uint16_t r; + memcpy(&r, ptr, sizeof(r)); + return r; +} + +static inline int ldsw_p(const void *ptr) +{ + int16_t r; + memcpy(&r, ptr, sizeof(r)); + return r; +} + +static inline void stw_p(void *ptr, uint16_t v) +{ + memcpy(ptr, &v, sizeof(v)); +} + +static inline int ldl_p(const void *ptr) +{ + int32_t r; + memcpy(&r, ptr, sizeof(r)); + return r; +} + +static inline void stl_p(void *ptr, uint32_t v) +{ + memcpy(ptr, &v, sizeof(v)); +} + +static inline uint64_t ldq_p(const void *ptr) +{ + uint64_t r; + memcpy(&r, ptr, sizeof(r)); + return r; +} + +static inline void stq_p(void *ptr, uint64_t v) +{ + memcpy(ptr, &v, sizeof(v)); +} + /* NOTE: on arm, putting 2 in /proc/sys/debug/alignment so that the kernel handles unaligned load/stores may give better results, but it is a system wide setting : bad */