Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH] MIPS: Implement __arch_bitrev* using bitswap for MIPSr6
@ 2016-05-06 12:35 Paul Burton
  2016-05-06 12:35 ` Paul Burton
  2016-05-09 14:19 ` Ralf Baechle
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Burton @ 2016-05-06 12:35 UTC (permalink / raw)
  To: linux-mips; +Cc: Ralf Baechle, Paul Burton

Release 6 of the MIPS architecture introduced the bitswap instruction,
which reverses the bits within each byte of a word. Make use of this
instruction to implement the __arch_bitrev* functions, which should be
faster for most MIPSr6 CPUs, reduces code size slightly and allows us to
avoid the lookup table used by the generic implementation, saving 256
bytes in the kernel binary by dropping that.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/Kconfig              |  1 +
 arch/mips/include/asm/bitrev.h | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 arch/mips/include/asm/bitrev.h

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index dd2b372..5b8fd2e 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2046,6 +2046,7 @@ config CPU_MIPSR2
 config CPU_MIPSR6
 	bool
 	default y if CPU_MIPS32_R6 || CPU_MIPS64_R6
+	select HAVE_ARCH_BITREVERSE
 	select MIPS_ASID_BITS_VARIABLE
 	select MIPS_SPRAM
 
diff --git a/arch/mips/include/asm/bitrev.h b/arch/mips/include/asm/bitrev.h
new file mode 100644
index 0000000..bc739a4
--- /dev/null
+++ b/arch/mips/include/asm/bitrev.h
@@ -0,0 +1,30 @@
+#ifndef __MIPS_ASM_BITREV_H__
+#define __MIPS_ASM_BITREV_H__
+
+#include <linux/swab.h>
+
+static __always_inline __attribute_const__ u32 __arch_bitrev32(u32 x)
+{
+	u32 ret;
+
+	asm("bitswap	%0, %1" : "=r"(ret) : "r"(__swab32(x)));
+	return ret;
+}
+
+static __always_inline __attribute_const__ u16 __arch_bitrev16(u16 x)
+{
+	u16 ret;
+
+	asm("bitswap	%0, %1" : "=r"(ret) : "r"(__swab16(x)));
+	return ret;
+}
+
+static __always_inline __attribute_const__ u8 __arch_bitrev8(u8 x)
+{
+	u8 ret;
+
+	asm("bitswap	%0, %1" : "=r"(ret) : "r"(x));
+	return ret;
+}
+
+#endif /* __MIPS_ASM_BITREV_H__ */
-- 
2.8.2

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

* [PATCH] MIPS: Implement __arch_bitrev* using bitswap for MIPSr6
  2016-05-06 12:35 [PATCH] MIPS: Implement __arch_bitrev* using bitswap for MIPSr6 Paul Burton
@ 2016-05-06 12:35 ` Paul Burton
  2016-05-09 14:19 ` Ralf Baechle
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Burton @ 2016-05-06 12:35 UTC (permalink / raw)
  To: linux-mips; +Cc: Ralf Baechle, Paul Burton

Release 6 of the MIPS architecture introduced the bitswap instruction,
which reverses the bits within each byte of a word. Make use of this
instruction to implement the __arch_bitrev* functions, which should be
faster for most MIPSr6 CPUs, reduces code size slightly and allows us to
avoid the lookup table used by the generic implementation, saving 256
bytes in the kernel binary by dropping that.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 arch/mips/Kconfig              |  1 +
 arch/mips/include/asm/bitrev.h | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 arch/mips/include/asm/bitrev.h

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index dd2b372..5b8fd2e 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2046,6 +2046,7 @@ config CPU_MIPSR2
 config CPU_MIPSR6
 	bool
 	default y if CPU_MIPS32_R6 || CPU_MIPS64_R6
+	select HAVE_ARCH_BITREVERSE
 	select MIPS_ASID_BITS_VARIABLE
 	select MIPS_SPRAM
 
diff --git a/arch/mips/include/asm/bitrev.h b/arch/mips/include/asm/bitrev.h
new file mode 100644
index 0000000..bc739a4
--- /dev/null
+++ b/arch/mips/include/asm/bitrev.h
@@ -0,0 +1,30 @@
+#ifndef __MIPS_ASM_BITREV_H__
+#define __MIPS_ASM_BITREV_H__
+
+#include <linux/swab.h>
+
+static __always_inline __attribute_const__ u32 __arch_bitrev32(u32 x)
+{
+	u32 ret;
+
+	asm("bitswap	%0, %1" : "=r"(ret) : "r"(__swab32(x)));
+	return ret;
+}
+
+static __always_inline __attribute_const__ u16 __arch_bitrev16(u16 x)
+{
+	u16 ret;
+
+	asm("bitswap	%0, %1" : "=r"(ret) : "r"(__swab16(x)));
+	return ret;
+}
+
+static __always_inline __attribute_const__ u8 __arch_bitrev8(u8 x)
+{
+	u8 ret;
+
+	asm("bitswap	%0, %1" : "=r"(ret) : "r"(x));
+	return ret;
+}
+
+#endif /* __MIPS_ASM_BITREV_H__ */
-- 
2.8.2

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

* Re: [PATCH] MIPS: Implement __arch_bitrev* using bitswap for MIPSr6
  2016-05-06 12:35 [PATCH] MIPS: Implement __arch_bitrev* using bitswap for MIPSr6 Paul Burton
  2016-05-06 12:35 ` Paul Burton
@ 2016-05-09 14:19 ` Ralf Baechle
  1 sibling, 0 replies; 3+ messages in thread
From: Ralf Baechle @ 2016-05-09 14:19 UTC (permalink / raw)
  To: Paul Burton; +Cc: linux-mips

On Fri, May 06, 2016 at 01:35:03PM +0100, Paul Burton wrote:

> Release 6 of the MIPS architecture introduced the bitswap instruction,
> which reverses the bits within each byte of a word. Make use of this
> instruction to implement the __arch_bitrev* functions, which should be
> faster for most MIPSr6 CPUs, reduces code size slightly and allows us to
> avoid the lookup table used by the generic implementation, saving 256
> bytes in the kernel binary by dropping that.
> 
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>

Applied after fixing up a trivial conflict.  It would be a bit cleaner
if <asm/bitrev.h> was including <linux/types.h> itself.  <linux/swab.h>
does so but there's no guarantee for that.

  Ralf

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

end of thread, other threads:[~2016-05-09 14:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-06 12:35 [PATCH] MIPS: Implement __arch_bitrev* using bitswap for MIPSr6 Paul Burton
2016-05-06 12:35 ` Paul Burton
2016-05-09 14:19 ` Ralf Baechle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox