linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	David Woodhouse <dwmw2@infradead.org>,
	Arnd Bergmann <arnd@arndb.de>, Dmitry Golovin <dima@golovin.in>,
	Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
	Christoph Lameter <cl@linux.com>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	clang-built-linux <clang-built-linux@googlegroups.com>
Subject: Re: [PATCH] x86: support i386 with Clang
Date: Mon, 11 May 2020 11:24:07 -0700	[thread overview]
Message-ID: <CAHk-=whhCBvjXtRiFM2JEZ4XyBmuPprvdo5tpPVBqUhkRszxiQ@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=wif=_ZomkWJAmQRCUAMHQ72V3NEQ-OteiPE56K7KoSjbQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 612 bytes --]

On Mon, May 11, 2020 at 11:12 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> Would using "__builtin_choose_expr()" be able to avoid this whole issue?

We actually have a fair amount of "pick expression based on size", so
with a few helper macros we could make the code look better than the
case statements too.

Something (ENTIRELY UNTESTED!) like the attached patch, perhaps?

NOTE! I only converted one single use to that "pick_size_xyz()" model.
If this actually works for clang too, we could do the others.

I guess I should just test it, since I have that clang tree.

                  Linus

[-- Attachment #2: patch --]
[-- Type: application/octet-stream, Size: 1855 bytes --]

 arch/x86/include/asm/percpu.h | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 2278797c769d..b479a0e650e5 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -86,6 +86,17 @@
 /* For arch-specific code, we can use direct single-insn ops (they
  * don't give an lvalue though). */
 extern void __bad_percpu_size(void);
+extern void __bad_expr_size(void);
+
+#define pick_type_expression(x, e8, e16, e32, e64)	\
+	__builtin_choose_expr(sizeof(x)==1, e8,		\
+	__builtin_choose_expr(sizeof(x)==2, e16,	\
+	__builtin_choose_expr(sizeof(x)==4, e32,	\
+	__builtin_choose_expr(sizeof(x)==8, e64,	\
+	__bad_expr_size()))))
+
+#define pick_type_statement(x, s8, s16, s32, s64) \
+	pick_type_expression(x, ({s8;0;}), ({s16;0;}),({s32;0;}),({s64;0;}))
 
 #define percpu_to_op(qual, op, var, val)		\
 do {							\
@@ -95,29 +106,19 @@ do {							\
 		pto_tmp__ = (val);			\
 		(void)pto_tmp__;			\
 	}						\
-	switch (sizeof(var)) {				\
-	case 1:						\
+	pick_type_statement(var,			\
 		asm qual (op "b %1,"__percpu_arg(0)	\
 		    : "+m" (var)			\
-		    : "qi" ((pto_T__)(val)));		\
-		break;					\
-	case 2:						\
+		    : "qi" ((pto_T__)(val))),		\
 		asm qual (op "w %1,"__percpu_arg(0)	\
 		    : "+m" (var)			\
-		    : "ri" ((pto_T__)(val)));		\
-		break;					\
-	case 4:						\
+		    : "ri" ((pto_T__)(val))),		\
 		asm qual (op "l %1,"__percpu_arg(0)	\
 		    : "+m" (var)			\
-		    : "ri" ((pto_T__)(val)));		\
-		break;					\
-	case 8:						\
+		    : "ri" ((pto_T__)(val))),		\
 		asm qual (op "q %1,"__percpu_arg(0)	\
 		    : "+m" (var)			\
-		    : "re" ((pto_T__)(val)));		\
-		break;					\
-	default: __bad_percpu_size();			\
-	}						\
+		    : "re" ((pto_T__)(val))));		\
 } while (0)
 
 /*

  reply	other threads:[~2020-05-11 18:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-04 23:03 [PATCH] x86: support i386 with Clang Nick Desaulniers
2020-05-11 17:23 ` Nick Desaulniers
2020-05-11 18:09   ` Brian Gerst
2020-05-11 18:46     ` Nick Desaulniers
2020-05-11 19:34       ` Brian Gerst
2020-05-11 20:18         ` Nick Desaulniers
2020-05-11 22:54         ` Brian Gerst
2020-05-11 18:12   ` Linus Torvalds
2020-05-11 18:24     ` Linus Torvalds [this message]
2020-05-11 18:36       ` Linus Torvalds
2020-05-11 19:52       ` Nick Desaulniers
2020-05-11 20:01         ` Linus Torvalds
2020-05-11 20:03           ` David Woodhouse
2020-05-12 20:35             ` Nick Desaulniers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHk-=whhCBvjXtRiFM2JEZ4XyBmuPprvdo5tpPVBqUhkRszxiQ@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=cl@linux.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=dennis@kernel.org \
    --cc=dima@golovin.in \
    --cc=dwmw2@infradead.org \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).