Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2331713pxj; Sun, 9 May 2021 23:41:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrWOZh52ObcZt7qjCK6GvoEsEFo0OSjlwHIsEmGiEEYfwv26YZ87HGk1xTscdfj6iV0mFa X-Received: by 2002:a05:6602:2b0a:: with SMTP id p10mr16588372iov.129.1620628898278; Sun, 09 May 2021 23:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620628898; cv=none; d=google.com; s=arc-20160816; b=F07CNu2VhjBK1JGaRwhdwXmBwGcGDwbq40hDTdpcAfJ82p4zAXXOkoOBse/F/mRdU2 h7aNeuGxXJAQIzZMZvTLM3mooNy+GMoMgAApGohOP1JI4SRFruWidgnuJyx2umYjiXSh omfhIiqkV1lnNNxCawF4fe7rJSnqikKo1zNas6b20LbQHOhtUQqgWWMLQse8kKtXVX1M V+zcMdtqxfG3LqXPokTtsdRx26SqAGSf3Y60qfVoM21/TmU0clvf8V2zLjkXOJtIyMTC fkZdoZBov+foY5CBac/wC0AxAVFGaWWAjSKsO4L14MVGb8bChEClO7UwFOoZRkKQ50Qr DdUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=88Ilm7Flv2wT81QtnUpmPqsLyEiLP/hNQ6e6DIypvF8=; b=BYlLAzIP+GOskK8ajp90Giw3/kB17iH5b3/+aRbN6Pm759LYibscVn2fb5dEL4dLPe zrVC1B/gPfNADBd7LvALhq1nO5pUQ6xuhdrg7ZBOsZmYcPLCmyFtYgpBzD35ALbLqFXr sVgkB1M/t96xOhvQyj61Gwqncz6GCSBQAKzCk3igYwvyVeFYSM4nDcFCa6Kc01QK9tlK 3qAIGecZI1KasYmJdhTcG8b6vVmbLAHnZMX2rlYE/3/LWoB/ssHE55t/4/L3aKW7xkVp fyksZGF30U72Gx9jZiAAKt8KStE8swDvAsImp/KMzAEozmOwd1Ixu91dLpq/jMYlbhSX qCuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i23si14626301jam.97.2021.05.09.23.41.25; Sun, 09 May 2021 23:41:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230145AbhEJGkv (ORCPT + 99 others); Mon, 10 May 2021 02:40:51 -0400 Received: from mail-ua1-f46.google.com ([209.85.222.46]:36515 "EHLO mail-ua1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230009AbhEJGkv (ORCPT ); Mon, 10 May 2021 02:40:51 -0400 Received: by mail-ua1-f46.google.com with SMTP id x9so4898906uao.3; Sun, 09 May 2021 23:39:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=88Ilm7Flv2wT81QtnUpmPqsLyEiLP/hNQ6e6DIypvF8=; b=K6W8HKJx59RQTDZYtfrpD9TBufFbMwSPx0C/z/2FXOrNYvEbP1Y3eWc0PESju2+nHL sYngEOrwI2uyxaM1NU4fEiqvgIMUXqa4MYH9OagdfBskKBQ0OxpMGRHRe45zIyBpr2Gc lFXJk608wipaCR+2Jx8X+7k0zevZ4gMQfGFQbh7W2xkEMI34gxcuqbXR8f7oUe+mjCz3 F5sQWFLBZZL7fAJ1oJieYaEM3S58SIbHpHMO/oISvWJQqMYeiMm9MlSbCF8bnkeldn0q 1KuHgSY7LZxdcJrWf1ZayZwESeX9sjUUPw53tIGW99dhjC1iQXocnzdqrJQeFZnhDHow aRmQ== X-Gm-Message-State: AOAM533KVsSdrkbKzQwLe4s4TxjZpN2lIXhUAgQPyhdYsJqe/4+51xDM BRQba4/Z7/xbDxK50JWObv1UxrywCSLTQsdbkvgdRJgO X-Received: by 2002:ab0:59cb:: with SMTP id k11mr3832034uad.100.1620628786270; Sun, 09 May 2021 23:39:46 -0700 (PDT) MIME-Version: 1.0 References: <20210507220813.365382-1-arnd@kernel.org> <20210507220813.365382-13-arnd@kernel.org> In-Reply-To: <20210507220813.365382-13-arnd@kernel.org> From: Geert Uytterhoeven Date: Mon, 10 May 2021 08:39:35 +0200 Message-ID: Subject: Re: [RFC 12/12] asm-generic: simplify asm/unaligned.h To: Arnd Bergmann Cc: Linux-Arch , Linus Torvalds , Vineet Gupta , Arnd Bergmann , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Arnd, On Sat, May 8, 2021 at 12:12 AM Arnd Bergmann wrote: > The get_unaligned()/put_unaligned() implementations are much more complex > than necessary, now that all architectures use the same code. > > Move everything into one file and use a much more compact way to express > the same logic. > > I've compared the binary output using gcc-11 across defconfig builds for > all architectures and found this patch to make no difference, except for > a single function on powerpc that needs two additional register moves > because of random differences in register allocation. > > There are a handful of callers of the low-level __get_unaligned_cpu32, > so leave that in place for the time being even though the common code > no longer uses it. > > This adds a warning for any caller of get_unaligned()/put_unaligned() > that passes in a single-byte pointer, but I've sent patches for all > instances that show up in x86 and randconfig builds. It would be nice > to change the arguments of the endian-specific accessors to take the > matching __be16/__be32/__be64/__le16/__le32/__le64 arguments instead of > a void pointer, but that requires more changes to the rest of the kernel. > > Signed-off-by: Arnd Bergmann Thanks for your patch! > @@ -6,20 +6,132 @@ > * This is the most generic implementation of unaligned accesses > * and should work almost anywhere. > */ > +#include > #include > > -#if defined(__LITTLE_ENDIAN) > -# include > -# include > -# define get_unaligned __get_unaligned_le > -# define put_unaligned __put_unaligned_le > -#elif defined(__BIG_ENDIAN) > -# include > -# include > -# define get_unaligned __get_unaligned_be > -# define put_unaligned __put_unaligned_be > -#else > -# error need to define endianess > -#endif > +#define __get_unaligned_t(type, ptr) ({ \ > + const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ > + __pptr->x; \ Space before tab (cfr. checkpatch). > +}) > + > +#define get_unaligned(ptr) ({ \ > + __auto_type __ptr = (ptr); \ > + __get_unaligned_t(typeof(*__ptr), __ptr); \ > +}) > + > +#define __put_unaligned_t(type, val, ptr) ({ \ > + struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ > + __pptr->x = (val); \ Likewise > +}) > Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds