linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mathieu Malaterre <malat@debian.org>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mathieu Malaterre <malat@debian.org>,
	Joel Stanley <joel@jms.id.au>,
	Segher Boessenkool <segher@kernel.crashing.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2] lib/mpi: fix build with clang
Date: Fri, 21 Jun 2019 21:55:54 +0200	[thread overview]
Message-ID: <20190621195555.20615-1-malat@debian.org> (raw)
In-Reply-To: <20190621071342.17897-1-malat@debian.org>

Remove superfluous casts on output operands to avoid warnings on the
following macros:

* add_ssaaaa(sh, sl, ah, al, bh, bl)
* sub_ddmmss(sh, sl, ah, al, bh, bl)
* umul_ppmm(ph, pl, m0, m1)

Special care has been taken to keep the diff as minimal as possible from
the original header file `longlong.h` from gcc, only importing the
minimal change to make the compilation with clang pass.

Silence the following warnings triggered using W=1:

    CC      lib/mpi/generic_mpih-mul1.o
  ../lib/mpi/generic_mpih-mul1.c:37:13: error: invalid use of a cast in a inline asm context requiring an l-value: remove the cast or build with
        -fheinous-gnu-extensions
                  umul_ppmm(prod_high, prod_low, s1_ptr[j], s2_limb);
                  ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../lib/mpi/longlong.h:824:20: note: expanded from macro 'umul_ppmm'
          : "=r" ((USItype) ph) \
                  ~~~~~~~~~~^~

and

    CC      lib/mpi/generic_mpih-mul2.o
  ../lib/mpi/generic_mpih-mul2.c:36:13: error: invalid use of a cast in a inline asm context requiring an l-value: remove the cast or build with
        -fheinous-gnu-extensions
                  umul_ppmm(prod_high, prod_low, s1_ptr[j], s2_limb);
                  ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../lib/mpi/longlong.h:824:20: note: expanded from macro 'umul_ppmm'
          : "=r" ((USItype) ph) \
                  ~~~~~~~~~~^~

  1 warning generated.
    CC      lib/mpi/generic_mpih-mul3.o
  ../lib/mpi/generic_mpih-mul3.c:36:13: error: invalid use of a cast in a inline asm context requiring an l-value: remove the cast or build with
        -fheinous-gnu-extensions
                  umul_ppmm(prod_high, prod_low, s1_ptr[j], s2_limb);
                  ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../lib/mpi/longlong.h:824:20: note: expanded from macro 'umul_ppmm'
          : "=r" ((USItype) ph) \
                  ~~~~~~~~~~^~

Or even:

  ../lib/mpi/mpih-div.c:99:16: error: invalid use of a cast in a inline asm context requiring an l-value: remove the cast or build with -fheinous-gnu-extensions
                                  sub_ddmmss(n1, n0, n1, n0, d1, d0);
                                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~

Inspiration is taken from commit b682c8692442 ("powerpc/math-emu: Update
macros from GCC").

Suggested-by: Joel Stanley <joel@jms.id.au>
Cc: Segher Boessenkool <segher@kernel.crashing.org>
Signed-off-by: Mathieu Malaterre <malat@debian.org>
---
v2: Instead of passing compat flag to clang to behave as gcc, remove the superfluous cast

 lib/mpi/longlong.h | 105 +++++++++++++++------------------------------
 1 file changed, 35 insertions(+), 70 deletions(-)

diff --git a/lib/mpi/longlong.h b/lib/mpi/longlong.h
index 08c60d10747f..f5503dfa42ed 100644
--- a/lib/mpi/longlong.h
+++ b/lib/mpi/longlong.h
@@ -753,79 +753,44 @@ do {									\
 	***************************************/
 #if (defined(_ARCH_PPC) || defined(_IBMR2)) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
-do { \
-	if (__builtin_constant_p(bh) && (bh) == 0) \
-		__asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
-		: "=r" ((USItype)(sh)), \
-		"=&r" ((USItype)(sl)) \
-		: "%r" ((USItype)(ah)), \
-		"%r" ((USItype)(al)), \
-		"rI" ((USItype)(bl))); \
-	else if (__builtin_constant_p(bh) && (bh) == ~(USItype) 0) \
-		__asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
-		: "=r" ((USItype)(sh)), \
-		"=&r" ((USItype)(sl)) \
-		: "%r" ((USItype)(ah)), \
-		"%r" ((USItype)(al)), \
-		"rI" ((USItype)(bl))); \
-	else \
-		__asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
-		: "=r" ((USItype)(sh)), \
-		"=&r" ((USItype)(sl)) \
-		: "%r" ((USItype)(ah)), \
-		"r" ((USItype)(bh)), \
-		"%r" ((USItype)(al)), \
-		"rI" ((USItype)(bl))); \
-} while (0)
+  do {									\
+    if (__builtin_constant_p (bh) && (bh) == 0)				\
+      __asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2"		\
+	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
+    else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0)		\
+      __asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2"		\
+	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
+    else								\
+      __asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3"		\
+	     : "=r" (sh), "=&r" (sl)					\
+	     : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl));		\
+  } while (0)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
-do { \
-	if (__builtin_constant_p(ah) && (ah) == 0) \
-		__asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
-		: "=r" ((USItype)(sh)), \
-		"=&r" ((USItype)(sl)) \
-		: "r" ((USItype)(bh)), \
-		"rI" ((USItype)(al)), \
-		"r" ((USItype)(bl))); \
-	else if (__builtin_constant_p(ah) && (ah) == ~(USItype) 0) \
-		__asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
-		: "=r" ((USItype)(sh)), \
-		"=&r" ((USItype)(sl)) \
-		: "r" ((USItype)(bh)), \
-		"rI" ((USItype)(al)), \
-		"r" ((USItype)(bl))); \
-	else if (__builtin_constant_p(bh) && (bh) == 0) \
-		__asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
-		: "=r" ((USItype)(sh)), \
-		"=&r" ((USItype)(sl)) \
-		: "r" ((USItype)(ah)), \
-		"rI" ((USItype)(al)), \
-		"r" ((USItype)(bl))); \
-	else if (__builtin_constant_p(bh) && (bh) == ~(USItype) 0) \
-		__asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
-		: "=r" ((USItype)(sh)), \
-		"=&r" ((USItype)(sl)) \
-		: "r" ((USItype)(ah)), \
-		"rI" ((USItype)(al)), \
-		"r" ((USItype)(bl))); \
-	else \
-		__asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
-		: "=r" ((USItype)(sh)), \
-		"=&r" ((USItype)(sl)) \
-		: "r" ((USItype)(ah)), \
-		"r" ((USItype)(bh)), \
-		"rI" ((USItype)(al)), \
-		"r" ((USItype)(bl))); \
-} while (0)
+  do {									\
+    if (__builtin_constant_p (ah) && (ah) == 0)				\
+      __asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2"	\
+	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
+    else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0)		\
+      __asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2"	\
+	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
+    else if (__builtin_constant_p (bh) && (bh) == 0)			\
+      __asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2"		\
+	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
+    else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0)		\
+      __asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2"		\
+	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
+    else								\
+      __asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2"	\
+	       : "=r" (sh), "=&r" (sl)					\
+	       : "r" (ah), "r" (bh), "rI" (al), "r" (bl));		\
+  } while (0)
 #if defined(_ARCH_PPC)
 #define umul_ppmm(ph, pl, m0, m1) \
-do { \
-	USItype __m0 = (m0), __m1 = (m1); \
-	__asm__ ("mulhwu %0,%1,%2" \
-	: "=r" ((USItype) ph) \
-	: "%r" (__m0), \
-	"r" (__m1)); \
-	(pl) = __m0 * __m1; \
-} while (0)
+  do {									\
+    USItype __m0 = (m0), __m1 = (m1);					\
+    __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
+    (pl) = __m0 * __m1;							\
+  } while (0)
 #define UMUL_TIME 15
 #define smul_ppmm(ph, pl, m0, m1) \
 do { \
-- 
2.20.1


  parent reply	other threads:[~2019-06-21 19:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-21  7:13 [PATCH] crypto: Fix build for clang Mathieu Malaterre
2019-06-21  7:29 ` Joel Stanley
2019-06-21  7:44   ` Mathieu Malaterre
2019-06-21 19:55 ` Mathieu Malaterre [this message]
2019-06-25  4:03   ` [PATCH v2] lib/mpi: fix build with clang Joel Stanley
2019-06-25 18:15   ` Segher Boessenkool

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=20190621195555.20615-1-malat@debian.org \
    --to=malat@debian.org \
    --cc=joel@jms.id.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=segher@kernel.crashing.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).