From patchwork Sat Jan 5 00:39:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 209586 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 771372C0079 for ; Sat, 5 Jan 2013 12:03:55 +1100 (EST) Received: from localhost ([::1]:53846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrHoQ-0001fQ-E2 for incoming@patchwork.ozlabs.org; Fri, 04 Jan 2013 19:40:34 -0500 Received: from eggs.gnu.org ([208.118.235.92]:60689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrHnc-00085a-Qo for qemu-devel@nongnu.org; Fri, 04 Jan 2013 19:39:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TrHnY-0008Kh-AG for qemu-devel@nongnu.org; Fri, 04 Jan 2013 19:39:44 -0500 Received: from mail-ie0-f171.google.com ([209.85.223.171]:36172) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrHnY-0008Kd-4Q for qemu-devel@nongnu.org; Fri, 04 Jan 2013 19:39:40 -0500 Received: by mail-ie0-f171.google.com with SMTP id 17so20613147iea.30 for ; Fri, 04 Jan 2013 16:39:39 -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=+a2l6s5UZA/VsjQUgndGVLQ8TjUWVIZEZLDErcERDN0=; b=wzjcOOWqiaWF3tmZAC/P2rNnp+pnWT+b3hu+d/oOaJiiuu7P5UrGwxNOuAiwmm950z FwTAlGN8d9RR2+hYq7sMem6/qvi9NAcC5dDs9fjK3EKZBBkTIlLaGoa8zvxgl8pfD25e joIZDl/OieH4n/ZQNfnw9tKjE1sF/ADa1T8q1jSiNVJQH2dhWj6xs7yzPSCte4052IAR ECpplt6gm6uoBdao7+cp1paVK+dvqOvUE/oSs72gr2XLWQhFLbTxCLBvg7emyq66AmY5 3bVQcGRaapb1BoWK/9NA7pejjpoaZC9wQn/eNwurxujAue22udySk/Lw7BcBDYGOYPTO YVkQ== X-Received: by 10.42.63.145 with SMTP id c17mr41276648ici.22.1357346379628; Fri, 04 Jan 2013 16:39:39 -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.38 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 04 Jan 2013 16:39:39 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 4 Jan 2013 16:39:27 -0800 Message-Id: <1357346373-13898-3-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.171 Cc: Blue Swirl , Riku Voipio Subject: [Qemu-devel] [PATCH 2/8] bswap: Tidy base definitions of bswapN 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 Move the bswap_N -> bswapN wrappers inside CONFIG_BYTESWAP_H. Change the ultimate fallback defintions from macros to inline functions. The proper types recieved by the function arguments means we can remove unnecessary casts, making the code more readable. Signed-off-by: Richard Henderson --- include/qemu/bswap.h | 72 ++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index 2006fcd..b2a8f94 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -7,48 +7,11 @@ #include "fpu/softfloat.h" #ifdef CONFIG_MACHINE_BSWAP_H -#include -#include -#include -#else - -#ifdef CONFIG_BYTESWAP_H -#include -#else - -#define bswap_16(x) \ -({ \ - uint16_t __x = (x); \ - ((uint16_t)( \ - (((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \ - (((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \ -}) - -#define bswap_32(x) \ -({ \ - uint32_t __x = (x); \ - ((uint32_t)( \ - (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \ - (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \ - (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \ - (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \ -}) - -#define bswap_64(x) \ -({ \ - uint64_t __x = (x); \ - ((uint64_t)( \ - (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \ - (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ - (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ - (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ - (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ - (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ - (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ - (uint64_t)(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \ -}) - -#endif /* !CONFIG_BYTESWAP_H */ +# include +# include +# include +#elif defined(CONFIG_BYTESWAP_H) +# include static inline uint16_t bswap16(uint16_t x) { @@ -64,7 +27,32 @@ static inline uint64_t bswap64(uint64_t x) { return bswap_64(x); } +# else +static inline uint16_t bswap16(uint16_t x) +{ + return (((x & 0x00ff) << 8) | + ((x & 0xff00) >> 8)); +} +static inline uint32_t bswap32(uint32_t x) +{ + return (((x & 0x000000ffU) << 24) | + ((x & 0x0000ff00U) << 8) | + ((x & 0x00ff0000U) >> 8) | + ((x & 0xff000000U) >> 24)); +} + +static inline uint64_t bswap64(uint64_t x) +{ + return (((x & 0x00000000000000ffULL) << 56) | + ((x & 0x000000000000ff00ULL) << 40) | + ((x & 0x0000000000ff0000ULL) << 24) | + ((x & 0x00000000ff000000ULL) << 8) | + ((x & 0x000000ff00000000ULL) >> 8) | + ((x & 0x0000ff0000000000ULL) >> 24) | + ((x & 0x00ff000000000000ULL) >> 40) | + ((x & 0xff00000000000000ULL) >> 56)); +} #endif /* ! CONFIG_MACHINE_BSWAP_H */ static inline void bswap16s(uint16_t *s)