From patchwork Tue Jun 10 23:13:14 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: 4332831 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 01CF99F333 for ; Tue, 10 Jun 2014 23:17:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3CDE320154 for ; Tue, 10 Jun 2014 23:17:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4D0052015E for ; Tue, 10 Jun 2014 23:17:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753539AbaFJXOE (ORCPT ); Tue, 10 Jun 2014 19:14:04 -0400 Received: from terminus.zytor.com ([198.137.202.10]:38713 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752087AbaFJXNu (ORCPT ); Tue, 10 Jun 2014 19:13:50 -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 s5ANDRuo008154 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 10 Jun 2014 16:13:27 -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 s5ANDMoZ016868; Tue, 10 Jun 2014 16:13:22 -0700 Received: (from hpa@localhost) by tazenda.hos.anvin.org (8.14.8/8.14.8/Submit) id s5ANDMsZ016867; Tue, 10 Jun 2014 16:13:22 -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 10/10] tools: Use reasonable defaults for the default access Date: Tue, 10 Jun 2014 16:13:14 -0700 Message-Id: <1402441994-16780-11-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 By default, as long as we are using gcc, use struct access for the native byte order and byte swap it for the reverse byte order. This works well on most gcc targets. If we are not compiling with gcc, then we cannot assume that struct access is safe, and so fall back to the most generic portable form ([bl]e_byteshift.h). However, there are some architectures on which this generates poor code even with gcc, and so some architectures may want to implement specific overrides in this header file. Signed-off-by: H. Peter Anvin --- tools/include/tools/unaligned.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/include/tools/unaligned.h b/tools/include/tools/unaligned.h index a3d43989bd25..1ef19a1ca9b4 100644 --- a/tools/include/tools/unaligned.h +++ b/tools/include/tools/unaligned.h @@ -30,7 +30,21 @@ struct _packed_u64_struct { #endif /* __GNUC__ */ -#include -#include +#if defined(__GNUC__) && (__BYTE_ORDER == __LITTLE_ENDIAN) + +# include +# include + +#elif defined(__GNUC__) && (__BYTE_ORDER == __BIG_ENDIAN) + +# include +# include + +#else /* No idea what we actually are dealing with */ + +# include +# include + +#endif #endif /* TOOLS_UNALIGNED_H */