From patchwork Tue Jun 10 23:13:09 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: 4332631 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 83677BEEAA for ; Tue, 10 Jun 2014 23:14:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A95D12028D for ; Tue, 10 Jun 2014 23:14:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C98DB2012F for ; Tue, 10 Jun 2014 23:14:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752290AbaFJXNu (ORCPT ); Tue, 10 Jun 2014 19:13:50 -0400 Received: from terminus.zytor.com ([198.137.202.10]:38708 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752030AbaFJXNt (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 s5ANDQ2j008146 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 10 Jun 2014 16:13:26 -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 s5ANDL5F016848; Tue, 10 Jun 2014 16:13:21 -0700 Received: (from hpa@localhost) by tazenda.hos.anvin.org (8.14.8/8.14.8/Submit) id s5ANDKMG016847; Tue, 10 Jun 2014 16:13:20 -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 05/10] tools: Add libc support for unaligned references Date: Tue, 10 Jun 2014 16:13:09 -0700 Message-Id: <1402441994-16780-6-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 Add support for the byteswap macros for unaligned references. Signed-off-by: H. Peter Anvin --- tools/include/tools/unaligned/be_endian.h | 40 +++++++++++++++++++++++++++++++ tools/include/tools/unaligned/le_endian.h | 40 +++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tools/include/tools/unaligned/be_endian.h create mode 100644 tools/include/tools/unaligned/le_endian.h diff --git a/tools/include/tools/unaligned/be_endian.h b/tools/include/tools/unaligned/be_endian.h new file mode 100644 index 000000000000..4106c082855e --- /dev/null +++ b/tools/include/tools/unaligned/be_endian.h @@ -0,0 +1,40 @@ +#ifndef _TOOLS_BE_ENDIAN_H +#define _TOOLS_BE_ENDIAN_H + +#ifndef _BSD_SOURCE +# define _BSD_SOURCE 1 +#endif +#include +#include + +static inline uint16_t get_unaligned_be16(const void *_p) +{ + return be16toh(get_unaligned_le16(_p)); +} + +static inline uint32_t get_unaligned_be32(const void *_p) +{ + return be32toh(get_unaligned_le32(_p)); +} + +static inline uint64_t get_unaligned_be64(const void *_p) +{ + return be64toh(get_unaligned_le64(_p)); +} + +static inline void put_unaligned_be16(uint16_t val, void *_p) +{ + put_unaligned_le16(htobe16(val), _p); +} + +static inline void put_unaligned_be32(uint32_t val, void *_p) +{ + put_unaligned_le32(htobe32(val), _p); +} + +static inline void put_unaligned_be64(uint64_t val, void *_p) +{ + put_unaligned_le64(htobe64(val), _p); +} + +#endif /* _TOOLS_BE_ENDIAN_H */ diff --git a/tools/include/tools/unaligned/le_endian.h b/tools/include/tools/unaligned/le_endian.h new file mode 100644 index 000000000000..0429f1b29250 --- /dev/null +++ b/tools/include/tools/unaligned/le_endian.h @@ -0,0 +1,40 @@ +#ifndef _TOOLS_LE_ENDIAN_H +#define _TOOLS_LE_ENDIAN_H + +#ifndef _BSD_SOURCE +# define _BSD_SOURCE 1 +#endif +#include +#include + +static inline uint16_t get_unaligned_le16(const void *_p) +{ + return le16toh(get_unaligned_be16(_p)); +} + +static inline uint32_t get_unaligned_le32(const void *_p) +{ + return le32toh(get_unaligned_be32(_p)); +} + +static inline uint64_t get_unaligned_le64(const void *_p) +{ + return le64toh(get_unaligned_be64(_p)); +} + +static inline void put_unaligned_le16(uint16_t val, void *_p) +{ + put_unaligned_be16(htole16(val), _p); +} + +static inline void put_unaligned_le32(uint32_t val, void *_p) +{ + put_unaligned_be32(htole32(val), _p); +} + +static inline void put_unaligned_le64(uint64_t val, void *_p) +{ + put_unaligned_be64(htole64(val), _p); +} + +#endif /* _TOOLS_LE_ENDIAN_H */