Re: [PATCH 02/25] MPILIB: Provide count_leading/trailing_zeros() based on arch functions

2012-09-13 Thread Kasatkin, Dmitry
O

On Thu, Sep 13, 2012 at 8:14 AM, James Morris  wrote:
> On Mon, 10 Sep 2012, Kasatkin, Dmitry wrote:
>
>> > Signed-off-by: David Howells 
>> > Cc: David S. Miller 
>> > Cc: Dmitry Kasatkin 
>> > Cc: Arnd Bergmann 
>>
>> Hi James,
>>
>> Can you please apply this?
>
> Could you send me this and any other outstanding changes as patches
> against my -next branch, tested and signed-off ?
>
> Or, perhaps Mimi could do that as maintainer of the integrity subsystem.
>
>

Ok. let's do it with other collection of patches...

> - James
> --
> James Morris
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/25] MPILIB: Provide count_leading/trailing_zeros() based on arch functions

2012-09-12 Thread James Morris
On Mon, 10 Sep 2012, Kasatkin, Dmitry wrote:

> > Signed-off-by: David Howells 
> > Cc: David S. Miller 
> > Cc: Dmitry Kasatkin 
> > Cc: Arnd Bergmann 
> 
> Hi James,
> 
> Can you please apply this?

Could you send me this and any other outstanding changes as patches 
against my -next branch, tested and signed-off ?

Or, perhaps Mimi could do that as maintainer of the integrity subsystem.


- James
-- 
James Morris

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 02/25] MPILIB: Provide count_leading/trailing_zeros() based on arch functions

2012-09-10 Thread Kasatkin, Dmitry
On Thu, Aug 16, 2012 at 4:34 AM, David Howells  wrote:
> Provide count_leading/trailing_zeros() macros based on extant arch bit 
> scanning
> functions rather than reimplementing from scratch in MPILIB.
>
> Whilst we're at it, turn count_foo_zeros(n, x) into n = count_foo_zeros(x).
>
> Also move the definition to asm-generic as other people may be interested in
> using it.
>
> Signed-off-by: David Howells 
> Cc: David S. Miller 
> Cc: Dmitry Kasatkin 
> Cc: Arnd Bergmann 

Hi James,

Can you please apply this?


Acked-by: Dmitry Kasatkin 


> ---
>
>  include/asm-generic/bitops/count_zeros.h |   57 
>  lib/mpi/longlong.h   |  138 
> --
>  lib/mpi/mpi-bit.c|2
>  lib/mpi/mpi-pow.c|4 -
>  4 files changed, 62 insertions(+), 139 deletions(-)
>  create mode 100644 include/asm-generic/bitops/count_zeros.h
>
>
> diff --git a/include/asm-generic/bitops/count_zeros.h 
> b/include/asm-generic/bitops/count_zeros.h
> new file mode 100644
> index 000..97520d2
> --- /dev/null
> +++ b/include/asm-generic/bitops/count_zeros.h
> @@ -0,0 +1,57 @@
> +/* Count leading and trailing zeros functions
> + *
> + * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
> + * Written by David Howells (dhowe...@redhat.com)
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public Licence
> + * as published by the Free Software Foundation; either version
> + * 2 of the Licence, or (at your option) any later version.
> + */
> +
> +#ifndef _ASM_GENERIC_BITOPS_COUNT_ZEROS_H_
> +#define _ASM_GENERIC_BITOPS_COUNT_ZEROS_H_
> +
> +#include 
> +
> +/**
> + * count_leading_zeros - Count the number of zeros from the MSB back
> + * @x: The value
> + *
> + * Count the number of leading zeros from the MSB going towards the LSB in 
> @x.
> + *
> + * If the MSB of @x is set, the result is 0.
> + * If only the LSB of @x is set, then the result is BITS_PER_LONG-1.
> + * If @x is 0 then the result is COUNT_LEADING_ZEROS_0.
> + */
> +static inline int count_leading_zeros(unsigned long x)
> +{
> +   if (sizeof(x) == 4)
> +   return BITS_PER_LONG - fls(x);
> +   else
> +   return BITS_PER_LONG - fls64(x);
> +}
> +
> +#define COUNT_LEADING_ZEROS_0 BITS_PER_LONG
> +
> +/**
> + * count_trailing_zeros - Count the number of zeros from the LSB forwards
> + * @x: The value
> + *
> + * Count the number of trailing zeros from the LSB going towards the MSB in 
> @x.
> + *
> + * If the LSB of @x is set, the result is 0.
> + * If only the MSB of @x is set, then the result is BITS_PER_LONG-1.
> + * If @x is 0 then the result is COUNT_TRAILING_ZEROS_0.
> + */
> +static inline int count_trailing_zeros(unsigned long x)
> +{
> +#define COUNT_TRAILING_ZEROS_0 (-1)
> +
> +   if (sizeof(x) == 4)
> +   return ffs(x);
> +   else
> +   return (x != 0) ? __ffs(x) : COUNT_TRAILING_ZEROS_0;
> +}
> +
> +#endif /* _ASM_GENERIC_BITOPS_COUNT_ZEROS_H_ */
> diff --git a/lib/mpi/longlong.h b/lib/mpi/longlong.h
> index 29f9862..678ce4f 100644
> --- a/lib/mpi/longlong.h
> +++ b/lib/mpi/longlong.h
> @@ -19,6 +19,8 @@
>   * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
>   * MA 02111-1307, USA. */
>
> +#include 
> +
>  /* You have to define the following before including this file:
>   *
>   * UWtype -- An unsigned type, default type for operations (typically a 
> "word")
> @@ -146,12 +148,6 @@ do { \
> : "1" ((USItype)(n1)), \
> "r" ((USItype)(n0)), \
> "r" ((USItype)(d)))
> -
> -#define count_leading_zeros(count, x) \
> -   __asm__ ("clz %0,%1" \
> -   : "=r" ((USItype)(count)) \
> -   : "r" ((USItype)(x)))
> -#define COUNT_LEADING_ZEROS_0 32
>  #endif /* __a29k__ */
>
>  #if defined(__alpha) && W_TYPE_SIZE == 64
> @@ -298,11 +294,6 @@ extern UDItype __udiv_qrnnd();
> : "1" ((USItype)(nh)), \
> "0" ((USItype)(nl)), \
> "g" ((USItype)(d)))
> -#define count_leading_zeros(count, x) \
> -   __asm__ ("bsch/1 %1,%0" \
> -   : "=g" (count) \
> -   : "g" ((USItype)(x)), \
> -"0" ((USItype)0))
>  #endif
>
>  /***
> @@ -354,27 +345,6 @@ do { USItype __r; \
>  } while (0)
>  extern USItype __udiv_qrnnd();
>  #endif /* LONGLONG_STANDALONE */
> -#define count_leading_zeros(count, x) \
> -do { \
> -   USItype __tmp; \
> -   __asm__ ( \
> -   "ldi 1,%0\n" \
> -   "extru,=%1,15,16,%%r0  ; Bits 31..16 zero?\n" \
> -   "extru,tr   %1,15,16,%1; No.  Shift down, skip add.\n" \
> -   "ldo16(%0),%0  ; Yes.   Perform add.\n" \
> -   "extru,=%1,23,8,%%r0   ; Bits 15..8 zero?\n" \
> -   "extru,tr   %1,23,8,%1 ; No.  Shift down, skip add.\n" \
> -   "ldo8(%0),%0   ; Yes.   Perfor

[PATCH 02/25] MPILIB: Provide count_leading/trailing_zeros() based on arch functions

2012-08-15 Thread David Howells
Provide count_leading/trailing_zeros() macros based on extant arch bit scanning
functions rather than reimplementing from scratch in MPILIB.

Whilst we're at it, turn count_foo_zeros(n, x) into n = count_foo_zeros(x).

Also move the definition to asm-generic as other people may be interested in
using it.

Signed-off-by: David Howells 
Cc: David S. Miller 
Cc: Dmitry Kasatkin 
Cc: Arnd Bergmann 
---

 include/asm-generic/bitops/count_zeros.h |   57 
 lib/mpi/longlong.h   |  138 --
 lib/mpi/mpi-bit.c|2 
 lib/mpi/mpi-pow.c|4 -
 4 files changed, 62 insertions(+), 139 deletions(-)
 create mode 100644 include/asm-generic/bitops/count_zeros.h


diff --git a/include/asm-generic/bitops/count_zeros.h 
b/include/asm-generic/bitops/count_zeros.h
new file mode 100644
index 000..97520d2
--- /dev/null
+++ b/include/asm-generic/bitops/count_zeros.h
@@ -0,0 +1,57 @@
+/* Count leading and trailing zeros functions
+ *
+ * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowe...@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_GENERIC_BITOPS_COUNT_ZEROS_H_
+#define _ASM_GENERIC_BITOPS_COUNT_ZEROS_H_
+
+#include 
+
+/**
+ * count_leading_zeros - Count the number of zeros from the MSB back
+ * @x: The value
+ *
+ * Count the number of leading zeros from the MSB going towards the LSB in @x.
+ *
+ * If the MSB of @x is set, the result is 0.
+ * If only the LSB of @x is set, then the result is BITS_PER_LONG-1.
+ * If @x is 0 then the result is COUNT_LEADING_ZEROS_0.
+ */
+static inline int count_leading_zeros(unsigned long x)
+{
+   if (sizeof(x) == 4)
+   return BITS_PER_LONG - fls(x);
+   else
+   return BITS_PER_LONG - fls64(x);
+}
+
+#define COUNT_LEADING_ZEROS_0 BITS_PER_LONG
+
+/**
+ * count_trailing_zeros - Count the number of zeros from the LSB forwards
+ * @x: The value
+ *
+ * Count the number of trailing zeros from the LSB going towards the MSB in @x.
+ *
+ * If the LSB of @x is set, the result is 0.
+ * If only the MSB of @x is set, then the result is BITS_PER_LONG-1.
+ * If @x is 0 then the result is COUNT_TRAILING_ZEROS_0.
+ */
+static inline int count_trailing_zeros(unsigned long x)
+{
+#define COUNT_TRAILING_ZEROS_0 (-1)
+
+   if (sizeof(x) == 4)
+   return ffs(x);
+   else
+   return (x != 0) ? __ffs(x) : COUNT_TRAILING_ZEROS_0;
+}
+
+#endif /* _ASM_GENERIC_BITOPS_COUNT_ZEROS_H_ */
diff --git a/lib/mpi/longlong.h b/lib/mpi/longlong.h
index 29f9862..678ce4f 100644
--- a/lib/mpi/longlong.h
+++ b/lib/mpi/longlong.h
@@ -19,6 +19,8 @@
  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  * MA 02111-1307, USA. */
 
+#include 
+
 /* You have to define the following before including this file:
  *
  * UWtype -- An unsigned type, default type for operations (typically a "word")
@@ -146,12 +148,6 @@ do { \
: "1" ((USItype)(n1)), \
"r" ((USItype)(n0)), \
"r" ((USItype)(d)))
-
-#define count_leading_zeros(count, x) \
-   __asm__ ("clz %0,%1" \
-   : "=r" ((USItype)(count)) \
-   : "r" ((USItype)(x)))
-#define COUNT_LEADING_ZEROS_0 32
 #endif /* __a29k__ */
 
 #if defined(__alpha) && W_TYPE_SIZE == 64
@@ -298,11 +294,6 @@ extern UDItype __udiv_qrnnd();
: "1" ((USItype)(nh)), \
"0" ((USItype)(nl)), \
"g" ((USItype)(d)))
-#define count_leading_zeros(count, x) \
-   __asm__ ("bsch/1 %1,%0" \
-   : "=g" (count) \
-   : "g" ((USItype)(x)), \
-"0" ((USItype)0))
 #endif
 
 /***
@@ -354,27 +345,6 @@ do { USItype __r; \
 } while (0)
 extern USItype __udiv_qrnnd();
 #endif /* LONGLONG_STANDALONE */
-#define count_leading_zeros(count, x) \
-do { \
-   USItype __tmp; \
-   __asm__ ( \
-   "ldi 1,%0\n" \
-   "extru,=%1,15,16,%%r0  ; Bits 31..16 zero?\n" \
-   "extru,tr   %1,15,16,%1; No.  Shift down, skip add.\n" \
-   "ldo16(%0),%0  ; Yes.   Perform add.\n" \
-   "extru,=%1,23,8,%%r0   ; Bits 15..8 zero?\n" \
-   "extru,tr   %1,23,8,%1 ; No.  Shift down, skip add.\n" \
-   "ldo8(%0),%0   ; Yes.   Perform add.\n" \
-   "extru,=%1,27,4,%%r0   ; Bits 7..4 zero?\n" \
-   "extru,tr   %1,27,4,%1 ; No.  Shift down, skip add.\n" \
-   "ldo4(%0),%0   ; Yes.   Perform add.\n" \
-   "extru,=%1,29,2,%%r0   ; Bits 3..2 zero?\n" \
-   "extru,tr   %1,29,2,%1 ; No.  Shift down, skip add.\n" \
-   "ldo2(%0),%0   ; Yes.   Perform a