From patchwork Sat Jan 5 00:39:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 209587 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 E1C302C007E for ; Sat, 5 Jan 2013 12:16:04 +1100 (EST) Received: from localhost ([::1]:53859 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrHoX-0001fX-UL for incoming@patchwork.ozlabs.org; Fri, 04 Jan 2013 19:40:41 -0500 Received: from eggs.gnu.org ([208.118.235.92]:60714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrHng-0008E7-Rh 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 1TrHnb-0008LR-Ky for qemu-devel@nongnu.org; Fri, 04 Jan 2013 19:39:48 -0500 Received: from mail-ie0-f172.google.com ([209.85.223.172]:60122) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrHnb-0008LJ-El for qemu-devel@nongnu.org; Fri, 04 Jan 2013 19:39:43 -0500 Received: by mail-ie0-f172.google.com with SMTP id c13so20189375ieb.17 for ; Fri, 04 Jan 2013 16:39:42 -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=zeXqVPtlOgrkCHF1TjTMuksf+P3Kzq1X8EL9Te8lM44=; b=Jl0RfK8S+nOnrYRJiypfqrgC7I5xMuM+v7dUxb81YCGumuRkRh2WSjW+5faNCDR6Cn O0/6QZzOKG3lmBsirAoe1upZpAFpp0GJUu7TZ+s4JICD6fRwn9SfFsZCr2KtudZxfUhr fTtm9imc/BaOXFwG22gnt+krL95qzAYZCV44ABQsR2LKK9UfPz2HRDynKdjvB4Xxrign GXFP4uLLjJQ2VJKlO7CM5xSyRdruT1lA3Chhe0e3hUu9cHqhZn4Jsiu4vmmy75oxlef0 LDGCgt484hJRjLs6DNVB/W3RD4tePg41/Hkc8+1R3Ww1nRf+8p69pu+bZcp2QooUiMnA +8gQ== X-Received: by 10.50.42.170 with SMTP id p10mr227696igl.47.1357346382746; Fri, 04 Jan 2013 16:39:42 -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.41 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 04 Jan 2013 16:39:42 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 4 Jan 2013 16:39:30 -0800 Message-Id: <1357346373-13898-6-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.223.172 Cc: Blue Swirl , Riku Voipio Subject: [Qemu-devel] [PATCH 5/8] bswap: Rewrite cpu_to_u with {ld, st}__p 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 We've now optimized the ld/st versions; reuse that for the "legacy" versions. Always use inlines so that we get the type checking that we expect. Signed-off-by: Richard Henderson --- include/qemu/bswap.h | 147 +++++++++++++++++++-------------------------------- 1 file changed, 53 insertions(+), 94 deletions(-) diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index 68cda6a..be9b035 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -121,100 +121,6 @@ CPU_CONVERT(le, 16, uint16_t) CPU_CONVERT(le, 32, uint32_t) CPU_CONVERT(le, 64, uint64_t) -/* unaligned versions (optimized for frequent unaligned accesses)*/ - -#if defined(__i386__) || defined(_ARCH_PPC) - -#define cpu_to_le16wu(p, v) cpu_to_le16w(p, v) -#define cpu_to_le32wu(p, v) cpu_to_le32w(p, v) -#define le16_to_cpupu(p) le16_to_cpup(p) -#define le32_to_cpupu(p) le32_to_cpup(p) -#define be32_to_cpupu(p) be32_to_cpup(p) - -#define cpu_to_be16wu(p, v) cpu_to_be16w(p, v) -#define cpu_to_be32wu(p, v) cpu_to_be32w(p, v) -#define cpu_to_be64wu(p, v) cpu_to_be64w(p, v) - -#else - -static inline void cpu_to_le16wu(uint16_t *p, uint16_t v) -{ - uint8_t *p1 = (uint8_t *)p; - - p1[0] = v & 0xff; - p1[1] = v >> 8; -} - -static inline void cpu_to_le32wu(uint32_t *p, uint32_t v) -{ - uint8_t *p1 = (uint8_t *)p; - - p1[0] = v & 0xff; - p1[1] = v >> 8; - p1[2] = v >> 16; - p1[3] = v >> 24; -} - -static inline uint16_t le16_to_cpupu(const uint16_t *p) -{ - const uint8_t *p1 = (const uint8_t *)p; - return p1[0] | (p1[1] << 8); -} - -static inline uint32_t le32_to_cpupu(const uint32_t *p) -{ - const uint8_t *p1 = (const uint8_t *)p; - return p1[0] | (p1[1] << 8) | (p1[2] << 16) | (p1[3] << 24); -} - -static inline uint32_t be32_to_cpupu(const uint32_t *p) -{ - const uint8_t *p1 = (const uint8_t *)p; - return p1[3] | (p1[2] << 8) | (p1[1] << 16) | (p1[0] << 24); -} - -static inline void cpu_to_be16wu(uint16_t *p, uint16_t v) -{ - uint8_t *p1 = (uint8_t *)p; - - p1[0] = v >> 8; - p1[1] = v & 0xff; -} - -static inline void cpu_to_be32wu(uint32_t *p, uint32_t v) -{ - uint8_t *p1 = (uint8_t *)p; - - p1[0] = v >> 24; - p1[1] = v >> 16; - p1[2] = v >> 8; - p1[3] = v & 0xff; -} - -static inline void cpu_to_be64wu(uint64_t *p, uint64_t v) -{ - uint8_t *p1 = (uint8_t *)p; - - p1[0] = v >> 56; - p1[1] = v >> 48; - p1[2] = v >> 40; - p1[3] = v >> 32; - p1[4] = v >> 24; - p1[5] = v >> 16; - p1[6] = v >> 8; - p1[7] = v & 0xff; -} - -#endif - -#ifdef HOST_WORDS_BIGENDIAN -#define cpu_to_32wu cpu_to_be32wu -#define leul_to_cpu(v) glue(glue(le,HOST_LONG_BITS),_to_cpu)(v) -#else -#define cpu_to_32wu cpu_to_le32wu -#define leul_to_cpu(v) (v) -#endif - /* len must be one of 1, 2, 4 */ static inline uint32_t qemu_bswap_len(uint32_t value, int len) { @@ -310,6 +216,7 @@ typedef union { * be : big endian * le : little endian */ + static inline int ldub_p(const void *ptr) { return *(uint8_t *)ptr; @@ -502,6 +409,58 @@ static inline void stfq_be_p(void *ptr, float64 v) stq_be_p(ptr, u.ll); } +/* Legacy unaligned versions. Note that we never had a complete set. */ + +static inline void cpu_to_le16wu(uint16_t *p, uint16_t v) +{ + stw_le_p(p, v); +} + +static inline void cpu_to_le32wu(uint32_t *p, uint32_t v) +{ + stl_le_p(p, v); +} + +static inline uint16_t le16_to_cpupu(const uint16_t *p) +{ + return lduw_le_p(p); +} + +static inline uint32_t le32_to_cpupu(const uint32_t *p) +{ + return ldl_le_p(p); +} + +static inline uint32_t be32_to_cpupu(const uint32_t *p) +{ + return ldl_be_p(p); +} + +static inline void cpu_to_be16wu(uint16_t *p, uint16_t v) +{ + stw_be_p(p, v); +} + +static inline void cpu_to_be32wu(uint32_t *p, uint32_t v) +{ + stl_be_p(p, v); +} + +static inline void cpu_to_be64wu(uint64_t *p, uint64_t v) +{ + stq_be_p(p, v); +} + +static inline void cpu_to_32wu(uint32_t *p, uint32_t v) +{ + stl_p(p, v); +} + +static inline unsigned long leul_to_cpu(unsigned long v) +{ + return le_bswap(v, HOST_LONG_BITS); +} + #undef le_bswap #undef be_bswap #undef le_bswaps