From patchwork Tue Jun 10 23:13:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 4332671 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7B88DBEEAA for ; Tue, 10 Jun 2014 23:14:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 92B162012F for ; Tue, 10 Jun 2014 23:14:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C54C20295 for ; Tue, 10 Jun 2014 23:14:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753001AbaFJXNw (ORCPT ); Tue, 10 Jun 2014 19:13:52 -0400 Received: from terminus.zytor.com ([198.137.202.10]:38711 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751998AbaFJXNt (ORCPT ); Tue, 10 Jun 2014 19:13:49 -0400 Received: from tazenda.hos.anvin.org ([IPv6:2601:9:7280:900:e269:95ff:fe35:9f3c]) (authenticated bits=0) by mail.zytor.com (8.14.7/8.14.5) with ESMTP id s5ANDPqh008133 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 10 Jun 2014 16:13:25 -0700 Received: from tazenda.hos.anvin.org (localhost [127.0.0.1]) by tazenda.hos.anvin.org (8.14.8/8.14.5) with ESMTP id s5ANDJap016832; Tue, 10 Jun 2014 16:13:19 -0700 Received: (from hpa@localhost) by tazenda.hos.anvin.org (8.14.8/8.14.8/Submit) id s5ANDJTx016831; Tue, 10 Jun 2014 16:13:19 -0700 From: "H. Peter Anvin" To: Sam Ravnborg , linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-arch@vger.kernel.org Cc: Andy Lutomirski , Andrew Morton , Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" Subject: [PATCH RFC 01/10] tools: Remove double-underscore symbols from user space byteshift functions Date: Tue, 10 Jun 2014 16:13:05 -0700 Message-Id: <1402441994-16780-2-git-send-email-hpa@zytor.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1402441994-16780-1-git-send-email-hpa@zytor.com> References: <1402441994-16780-1-git-send-email-hpa@zytor.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We should not use double-underscore (or underscore-capital) symbols in arbitrary user space code, and these include files are specifically used for user space compilation. Furthermore, the indirection is completely unnecessary in this case. Also, reorder the littleendian put macros to allow the compiler to generate better code on some architectures (stores in sequence.) Signed-off-by: H. Peter Anvin --- tools/include/tools/be_byteshift.h | 62 ++++++++++++++------------------------ tools/include/tools/le_byteshift.h | 62 ++++++++++++++------------------------ 2 files changed, 44 insertions(+), 80 deletions(-) diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h index 84c17d836578..9850c7df2667 100644 --- a/tools/include/tools/be_byteshift.h +++ b/tools/include/tools/be_byteshift.h @@ -3,68 +3,50 @@ #include -static inline uint16_t __get_unaligned_be16(const uint8_t *p) +static inline uint16_t get_unaligned_be16(const void *_p) { - return p[0] << 8 | p[1]; -} + const uint8_t *p = _p; -static inline uint32_t __get_unaligned_be32(const uint8_t *p) -{ - return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; + return p[0] << 8 | p[1]; } -static inline uint64_t __get_unaligned_be64(const uint8_t *p) +static inline uint32_t get_unaligned_be32(const void *_p) { - return (uint64_t)__get_unaligned_be32(p) << 32 | - __get_unaligned_be32(p + 4); -} + const uint8_t *p = _p; -static inline void __put_unaligned_be16(uint16_t val, uint8_t *p) -{ - *p++ = val >> 8; - *p++ = val; + return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; } -static inline void __put_unaligned_be32(uint32_t val, uint8_t *p) +static inline uint64_t get_unaligned_be64(const void *_p) { - __put_unaligned_be16(val >> 16, p); - __put_unaligned_be16(val, p + 2); -} + const uint8_t *p = _p; -static inline void __put_unaligned_be64(uint64_t val, uint8_t *p) -{ - __put_unaligned_be32(val >> 32, p); - __put_unaligned_be32(val, p + 4); + return (uint64_t)get_unaligned_be32(p) << 32 | + get_unaligned_be32(p + 4); } -static inline uint16_t get_unaligned_be16(const void *p) +static inline void put_unaligned_be16(uint16_t val, void *_p) { - return __get_unaligned_be16((const uint8_t *)p); -} + uint8_t *p = _p; -static inline uint32_t get_unaligned_be32(const void *p) -{ - return __get_unaligned_be32((const uint8_t *)p); + *p++ = val >> 8; + *p++ = val; } -static inline uint64_t get_unaligned_be64(const void *p) +static inline void put_unaligned_be32(uint32_t val, void *_p) { - return __get_unaligned_be64((const uint8_t *)p); -} + uint8_t *p = _p; -static inline void put_unaligned_be16(uint16_t val, void *p) -{ - __put_unaligned_be16(val, p); + put_unaligned_be16(val >> 16, p); + put_unaligned_be16(val, p + 2); } -static inline void put_unaligned_be32(uint32_t val, void *p) +static inline void put_unaligned_be64(uint64_t val, void *_p) { - __put_unaligned_be32(val, p); -} + uint8_t *p = _p; -static inline void put_unaligned_be64(uint64_t val, void *p) -{ - __put_unaligned_be64(val, p); + put_unaligned_be32(val >> 32, p); + put_unaligned_be32(val, p + 4); } #endif /* _TOOLS_BE_BYTESHIFT_H */ diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h index 8fe9f2488ec7..819ba186ede5 100644 --- a/tools/include/tools/le_byteshift.h +++ b/tools/include/tools/le_byteshift.h @@ -3,68 +3,50 @@ #include -static inline uint16_t __get_unaligned_le16(const uint8_t *p) +static inline uint16_t get_unaligned_le16(const void *_p) { - return p[0] | p[1] << 8; -} + const uint8_t *p = _p; -static inline uint32_t __get_unaligned_le32(const uint8_t *p) -{ - return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; + return p[0] | p[1] << 8; } -static inline uint64_t __get_unaligned_le64(const uint8_t *p) +static inline uint32_t get_unaligned_le32(const void *_p) { - return (uint64_t)__get_unaligned_le32(p + 4) << 32 | - __get_unaligned_le32(p); -} + const uint8_t *p = _p; -static inline void __put_unaligned_le16(uint16_t val, uint8_t *p) -{ - *p++ = val; - *p++ = val >> 8; + return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; } -static inline void __put_unaligned_le32(uint32_t val, uint8_t *p) +static inline uint64_t get_unaligned_le64(const void *_p) { - __put_unaligned_le16(val >> 16, p + 2); - __put_unaligned_le16(val, p); -} + const uint8_t *p = _p; -static inline void __put_unaligned_le64(uint64_t val, uint8_t *p) -{ - __put_unaligned_le32(val >> 32, p + 4); - __put_unaligned_le32(val, p); + return (uint64_t)get_unaligned_le32(p + 4) << 32 | + get_unaligned_le32(p); } -static inline uint16_t get_unaligned_le16(const void *p) +static inline void put_unaligned_le16(uint16_t val, void *_p) { - return __get_unaligned_le16((const uint8_t *)p); -} + uint8_t *p = _p; -static inline uint32_t get_unaligned_le32(const void *p) -{ - return __get_unaligned_le32((const uint8_t *)p); + *p++ = val; + *p++ = val >> 8; } -static inline uint64_t get_unaligned_le64(const void *p) +static inline void put_unaligned_le32(uint32_t val, void *_p) { - return __get_unaligned_le64((const uint8_t *)p); -} + uint8_t *p = _p; -static inline void put_unaligned_le16(uint16_t val, void *p) -{ - __put_unaligned_le16(val, p); + put_unaligned_le16(val, p); + put_unaligned_le16(val >> 16, p + 2); } -static inline void put_unaligned_le32(uint32_t val, void *p) +static inline void put_unaligned_le64(uint64_t val, void *_p) { - __put_unaligned_le32(val, p); -} + uint8_t *p = _p; -static inline void put_unaligned_le64(uint64_t val, void *p) -{ - __put_unaligned_le64(val, p); + put_unaligned_le32(val, p); + put_unaligned_le32(val >> 32, p + 4); } #endif /* _TOOLS_LE_BYTESHIFT_H */