Linux-MIPS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] lib/mpi: Eliminate unused umul_ppmm definitions for MIPS
@ 2019-08-12 19:32 Nathan Chancellor
  2019-08-12 19:37 ` Nick Desaulniers
  2019-08-22  5:55 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Nathan Chancellor @ 2019-08-12 19:32 UTC (permalink / raw)
  To: Ralf Baechle, James Hogan, Herbert Xu
  Cc: linux-mips, linux-crypto, linux-kernel, clang-built-linux,
	Nathan Chancellor, Nick Desaulniers

Clang errors out when building this macro:

lib/mpi/generic_mpih-mul1.c:37:24: 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:652:20: note: expanded from macro 'umul_ppmm'
        : "=l" ((USItype)(w0)), \
                ~~~~~~~~~~^~~
lib/mpi/generic_mpih-mul1.c:37:3: error: invalid output constraint '=h'
in asm
                umul_ppmm(prod_high, prod_low, s1_ptr[j], s2_limb);
                ^
lib/mpi/longlong.h:653:7: note: expanded from macro 'umul_ppmm'
             "=h" ((USItype)(w1)) \
             ^
2 errors generated.

The C version that is used for GCC 4.4 and up works well with clang;
however, it is not currently being used because Clang masks itself
as GCC 4.2.1 for compatibility reasons. As Nick points out, we require
GCC 4.6 and newer in the kernel so we can eliminate all of the
versioning checks and just use the C version of umul_ppmm for all
supported compilers.

Link: https://github.com/ClangBuiltLinux/linux/issues/605
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---

This supersedes the following two patches:

https://lore.kernel.org/lkml/20190812033120.43013-4-natechancellor@gmail.com/

https://lore.kernel.org/lkml/20190812033120.43013-5-natechancellor@gmail.com/

I labelled this as a v2 so those don't get applied.

 lib/mpi/longlong.h | 36 +-----------------------------------
 1 file changed, 1 insertion(+), 35 deletions(-)

diff --git a/lib/mpi/longlong.h b/lib/mpi/longlong.h
index 3bb6260d8f42..2dceaca27489 100644
--- a/lib/mpi/longlong.h
+++ b/lib/mpi/longlong.h
@@ -639,30 +639,12 @@ do { \
 	**************  MIPS  *****************
 	***************************************/
 #if defined(__mips__) && W_TYPE_SIZE == 32
-#if (__GNUC__ >= 5) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 4)
 #define umul_ppmm(w1, w0, u, v)			\
 do {						\
 	UDItype __ll = (UDItype)(u) * (v);	\
 	w1 = __ll >> 32;			\
 	w0 = __ll;				\
 } while (0)
-#elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7
-#define umul_ppmm(w1, w0, u, v) \
-	__asm__ ("multu %2,%3" \
-	: "=l" ((USItype)(w0)), \
-	     "=h" ((USItype)(w1)) \
-	: "d" ((USItype)(u)), \
-	     "d" ((USItype)(v)))
-#else
-#define umul_ppmm(w1, w0, u, v) \
-	__asm__ ("multu %2,%3\n" \
-	   "mflo %0\n" \
-	   "mfhi %1" \
-	: "=d" ((USItype)(w0)), \
-	     "=d" ((USItype)(w1)) \
-	: "d" ((USItype)(u)), \
-	     "d" ((USItype)(v)))
-#endif
 #define UMUL_TIME 10
 #define UDIV_TIME 100
 #endif /* __mips__ */
@@ -687,7 +669,7 @@ do {									\
 		 : "d" ((UDItype)(u)),					\
 		   "d" ((UDItype)(v)));					\
 } while (0)
-#elif (__GNUC__ >= 5) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 4)
+#else
 #define umul_ppmm(w1, w0, u, v) \
 do {									\
 	typedef unsigned int __ll_UTItype __attribute__((mode(TI)));	\
@@ -695,22 +677,6 @@ do {									\
 	w1 = __ll >> 64;						\
 	w0 = __ll;							\
 } while (0)
-#elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7
-#define umul_ppmm(w1, w0, u, v) \
-	__asm__ ("dmultu %2,%3" \
-	: "=l" ((UDItype)(w0)), \
-	     "=h" ((UDItype)(w1)) \
-	: "d" ((UDItype)(u)), \
-	     "d" ((UDItype)(v)))
-#else
-#define umul_ppmm(w1, w0, u, v) \
-	__asm__ ("dmultu %2,%3\n" \
-	   "mflo %0\n" \
-	   "mfhi %1" \
-	: "=d" ((UDItype)(w0)), \
-	     "=d" ((UDItype)(w1)) \
-	: "d" ((UDItype)(u)), \
-	     "d" ((UDItype)(v)))
 #endif
 #define UMUL_TIME 20
 #define UDIV_TIME 140
-- 
2.23.0.rc2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] lib/mpi: Eliminate unused umul_ppmm definitions for MIPS
  2019-08-12 19:32 [PATCH v2] lib/mpi: Eliminate unused umul_ppmm definitions for MIPS Nathan Chancellor
@ 2019-08-12 19:37 ` Nick Desaulniers
  2019-08-22  5:55 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Nick Desaulniers @ 2019-08-12 19:37 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Ralf Baechle, James Hogan, Herbert Xu, linux-mips,
	open list:HARDWARE RANDOM NUMBER GENERATOR CORE, LKML,
	clang-built-linux

On Mon, Aug 12, 2019 at 12:36 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> Clang errors out when building this macro:
>
> lib/mpi/generic_mpih-mul1.c:37:24: 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:652:20: note: expanded from macro 'umul_ppmm'
>         : "=l" ((USItype)(w0)), \
>                 ~~~~~~~~~~^~~
> lib/mpi/generic_mpih-mul1.c:37:3: error: invalid output constraint '=h'
> in asm
>                 umul_ppmm(prod_high, prod_low, s1_ptr[j], s2_limb);
>                 ^
> lib/mpi/longlong.h:653:7: note: expanded from macro 'umul_ppmm'
>              "=h" ((USItype)(w1)) \
>              ^
> 2 errors generated.
>
> The C version that is used for GCC 4.4 and up works well with clang;
> however, it is not currently being used because Clang masks itself
> as GCC 4.2.1 for compatibility reasons. As Nick points out, we require
> GCC 4.6 and newer in the kernel so we can eliminate all of the
> versioning checks and just use the C version of umul_ppmm for all
> supported compilers.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/605
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

LGTM thanks Nathan.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>
> This supersedes the following two patches:
>
> https://lore.kernel.org/lkml/20190812033120.43013-4-natechancellor@gmail.com/
>
> https://lore.kernel.org/lkml/20190812033120.43013-5-natechancellor@gmail.com/
>
> I labelled this as a v2 so those don't get applied.
>
>  lib/mpi/longlong.h | 36 +-----------------------------------
>  1 file changed, 1 insertion(+), 35 deletions(-)
>
> diff --git a/lib/mpi/longlong.h b/lib/mpi/longlong.h
> index 3bb6260d8f42..2dceaca27489 100644
> --- a/lib/mpi/longlong.h
> +++ b/lib/mpi/longlong.h
> @@ -639,30 +639,12 @@ do { \
>         **************  MIPS  *****************
>         ***************************************/
>  #if defined(__mips__) && W_TYPE_SIZE == 32
> -#if (__GNUC__ >= 5) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 4)
>  #define umul_ppmm(w1, w0, u, v)                        \
>  do {                                           \
>         UDItype __ll = (UDItype)(u) * (v);      \
>         w1 = __ll >> 32;                        \
>         w0 = __ll;                              \
>  } while (0)
> -#elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7
> -#define umul_ppmm(w1, w0, u, v) \
> -       __asm__ ("multu %2,%3" \
> -       : "=l" ((USItype)(w0)), \
> -            "=h" ((USItype)(w1)) \
> -       : "d" ((USItype)(u)), \
> -            "d" ((USItype)(v)))
> -#else
> -#define umul_ppmm(w1, w0, u, v) \
> -       __asm__ ("multu %2,%3\n" \
> -          "mflo %0\n" \
> -          "mfhi %1" \
> -       : "=d" ((USItype)(w0)), \
> -            "=d" ((USItype)(w1)) \
> -       : "d" ((USItype)(u)), \
> -            "d" ((USItype)(v)))
> -#endif
>  #define UMUL_TIME 10
>  #define UDIV_TIME 100
>  #endif /* __mips__ */
> @@ -687,7 +669,7 @@ do {                                                                        \
>                  : "d" ((UDItype)(u)),                                  \
>                    "d" ((UDItype)(v)));                                 \
>  } while (0)
> -#elif (__GNUC__ >= 5) || (__GNUC__ >= 4 && __GNUC_MINOR__ >= 4)
> +#else
>  #define umul_ppmm(w1, w0, u, v) \
>  do {                                                                   \
>         typedef unsigned int __ll_UTItype __attribute__((mode(TI)));    \
> @@ -695,22 +677,6 @@ do {                                                                       \
>         w1 = __ll >> 64;                                                \
>         w0 = __ll;                                                      \
>  } while (0)
> -#elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7
> -#define umul_ppmm(w1, w0, u, v) \
> -       __asm__ ("dmultu %2,%3" \
> -       : "=l" ((UDItype)(w0)), \
> -            "=h" ((UDItype)(w1)) \
> -       : "d" ((UDItype)(u)), \
> -            "d" ((UDItype)(v)))
> -#else
> -#define umul_ppmm(w1, w0, u, v) \
> -       __asm__ ("dmultu %2,%3\n" \
> -          "mflo %0\n" \
> -          "mfhi %1" \
> -       : "=d" ((UDItype)(w0)), \
> -            "=d" ((UDItype)(w1)) \
> -       : "d" ((UDItype)(u)), \
> -            "d" ((UDItype)(v)))
>  #endif
>  #define UMUL_TIME 20
>  #define UDIV_TIME 140
> --
> 2.23.0.rc2
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] lib/mpi: Eliminate unused umul_ppmm definitions for MIPS
  2019-08-12 19:32 [PATCH v2] lib/mpi: Eliminate unused umul_ppmm definitions for MIPS Nathan Chancellor
  2019-08-12 19:37 ` Nick Desaulniers
@ 2019-08-22  5:55 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2019-08-22  5:55 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Ralf Baechle, James Hogan, linux-mips, linux-crypto,
	linux-kernel, clang-built-linux, Nick Desaulniers

On Mon, Aug 12, 2019 at 12:32:57PM -0700, Nathan Chancellor wrote:
> Clang errors out when building this macro:
> 
> lib/mpi/generic_mpih-mul1.c:37:24: 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:652:20: note: expanded from macro 'umul_ppmm'
>         : "=l" ((USItype)(w0)), \
>                 ~~~~~~~~~~^~~
> lib/mpi/generic_mpih-mul1.c:37:3: error: invalid output constraint '=h'
> in asm
>                 umul_ppmm(prod_high, prod_low, s1_ptr[j], s2_limb);
>                 ^
> lib/mpi/longlong.h:653:7: note: expanded from macro 'umul_ppmm'
>              "=h" ((USItype)(w1)) \
>              ^
> 2 errors generated.
> 
> The C version that is used for GCC 4.4 and up works well with clang;
> however, it is not currently being used because Clang masks itself
> as GCC 4.2.1 for compatibility reasons. As Nick points out, we require
> GCC 4.6 and newer in the kernel so we can eliminate all of the
> versioning checks and just use the C version of umul_ppmm for all
> supported compilers.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/605
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
> 
> This supersedes the following two patches:
> 
> https://lore.kernel.org/lkml/20190812033120.43013-4-natechancellor@gmail.com/
> 
> https://lore.kernel.org/lkml/20190812033120.43013-5-natechancellor@gmail.com/
> 
> I labelled this as a v2 so those don't get applied.
> 
>  lib/mpi/longlong.h | 36 +-----------------------------------
>  1 file changed, 1 insertion(+), 35 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 19:32 [PATCH v2] lib/mpi: Eliminate unused umul_ppmm definitions for MIPS Nathan Chancellor
2019-08-12 19:37 ` Nick Desaulniers
2019-08-22  5:55 ` Herbert Xu

Linux-MIPS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mips/0 linux-mips/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mips linux-mips/ https://lore.kernel.org/linux-mips \
		linux-mips@vger.kernel.org linux-mips@archiver.kernel.org
	public-inbox-index linux-mips


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-mips


AGPL code for this site: git clone https://public-inbox.org/ public-inbox