Linux-RISC-V Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] riscv: export __lshrti3
@ 2019-12-17  0:30 Olof Johansson
  2019-12-17  1:54 ` Olof Johansson
  2019-12-17  4:06 ` [PATCH] riscv: Less inefficient gcc tishift helpers (and export their symbols) Olof Johansson
  0 siblings, 2 replies; 4+ messages in thread
From: Olof Johansson @ 2019-12-17  0:30 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: Olof Johansson, linux-riscv, linux-kernel

ARM64 exports it already, and recently it started showing up as needed
with allmodconfig.

To keep things building as expected, let's export on riscv as well.

Signed-off-by: Olof Johansson <olof@lixom.net>
---

It'd be nice to see this go in through 5.5-rc, since the breakage showed
up this merge window. It was triggered by ce5c31db3645 ("lib/ubsan:
don't serialize UBSAN report"), but I think that was just coincidental.

 arch/riscv/lib/tishift.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/riscv/lib/tishift.S b/arch/riscv/lib/tishift.S
index 15f9d54c7db63..8ecb7db331cfe 100644
--- a/arch/riscv/lib/tishift.S
+++ b/arch/riscv/lib/tishift.S
@@ -35,3 +35,4 @@ ENTRY(__lshrti3)
 	addi	sp,sp,16
 	ret
 ENDPROC(__lshrti3)
+EXPORT_SYMBOL(__lshrti3)
-- 
2.11.0



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

* Re: [PATCH] riscv: export __lshrti3
  2019-12-17  0:30 [PATCH] riscv: export __lshrti3 Olof Johansson
@ 2019-12-17  1:54 ` Olof Johansson
  2019-12-17  4:06 ` [PATCH] riscv: Less inefficient gcc tishift helpers (and export their symbols) Olof Johansson
  1 sibling, 0 replies; 4+ messages in thread
From: Olof Johansson @ 2019-12-17  1:54 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: linux-riscv, Linux Kernel Mailing List

On Mon, Dec 16, 2019 at 4:31 PM Olof Johansson <olof@lixom.net> wrote:
>
> ARM64 exports it already, and recently it started showing up as needed
> with allmodconfig.
>
> To keep things building as expected, let's export on riscv as well.
>
> Signed-off-by: Olof Johansson <olof@lixom.net>
> ---
>
> It'd be nice to see this go in through 5.5-rc, since the breakage showed
> up this merge window. It was triggered by ce5c31db3645 ("lib/ubsan:
> don't serialize UBSAN report"), but I think that was just coincidental.

Nevermind, I built the wrong config when I tested this. Need to pick
up some of the generic helpers also. Posting new patch separately.


-Olof



-Olof


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

* [PATCH] riscv: Less inefficient gcc tishift helpers (and export their symbols)
  2019-12-17  0:30 [PATCH] riscv: export __lshrti3 Olof Johansson
  2019-12-17  1:54 ` Olof Johansson
@ 2019-12-17  4:06 ` Olof Johansson
  2020-01-19  3:45   ` Paul Walmsley
  1 sibling, 1 reply; 4+ messages in thread
From: Olof Johansson @ 2019-12-17  4:06 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: Olof Johansson, linux-riscv, linux-kernel

The existing __lshrti3 was really inefficient, and the other two helpers
are also needed to compile some modules.

Add the missing versions, and export all of the symbols like arm64
already does.

This fixes a build break triggered by ubsan:

riscv64-unknown-linux-gnu-ld: lib/ubsan.o: in function `.L2':
ubsan.c:(.text.unlikely+0x38): undefined reference to `__ashlti3'
riscv64-unknown-linux-gnu-ld: ubsan.c:(.text.unlikely+0x42): undefined reference to `__ashrti3'

Signed-off-by: Olof Johansson <olof@lixom.net>
---
 arch/riscv/include/asm/asm-prototypes.h |  4 ++
 arch/riscv/lib/tishift.S                | 71 +++++++++++++++++++++++++--------
 2 files changed, 59 insertions(+), 16 deletions(-)

diff --git a/arch/riscv/include/asm/asm-prototypes.h b/arch/riscv/include/asm/asm-prototypes.h
index dd62b691c443d..27e005fca5849 100644
--- a/arch/riscv/include/asm/asm-prototypes.h
+++ b/arch/riscv/include/asm/asm-prototypes.h
@@ -5,4 +5,8 @@
 #include <linux/ftrace.h>
 #include <asm-generic/asm-prototypes.h>
 
+long long __lshrti3(long long a, int b);
+long long __ashrti3(long long a, int b);
+long long __ashlti3(long long a, int b);
+
 #endif /* _ASM_RISCV_PROTOTYPES_H */
diff --git a/arch/riscv/lib/tishift.S b/arch/riscv/lib/tishift.S
index 15f9d54c7db63..64a7b6abd38fb 100644
--- a/arch/riscv/lib/tishift.S
+++ b/arch/riscv/lib/tishift.S
@@ -4,34 +4,73 @@
  */
 
 #include <linux/linkage.h>
+#include <asm-generic/export.h>
 
 ENTRY(__lshrti3)
 	beqz	a2, .L1
 	li	a5,64
 	sub	a5,a5,a2
-	addi	sp,sp,-16
 	sext.w	a4,a5
 	blez	a5, .L2
 	sext.w	a2,a2
-	sll	a4,a1,a4
 	srl	a0,a0,a2
-	srl	a1,a1,a2
+	sll	a4,a1,a4
+	srl	a2,a1,a2
 	or	a0,a0,a4
-	sd	a1,8(sp)
-	sd	a0,0(sp)
-	ld	a0,0(sp)
-	ld	a1,8(sp)
-	addi	sp,sp,16
-	ret
+	mv	a1,a2
 .L1:
 	ret
 .L2:
-	negw	a4,a4
-	srl	a1,a1,a4
-	sd	a1,0(sp)
-	sd	zero,8(sp)
-	ld	a0,0(sp)
-	ld	a1,8(sp)
-	addi	sp,sp,16
+	negw	a0,a4
+	li	a2,0
+	srl	a0,a1,a0
+	mv	a1,a2
 	ret
 ENDPROC(__lshrti3)
+EXPORT_SYMBOL(__lshrti3)
+
+ENTRY(__ashrti3)
+	beqz	a2, .L3
+	li	a5,64
+	sub	a5,a5,a2
+	sext.w	a4,a5
+	blez	a5, .L4
+	sext.w	a2,a2
+	srl	a0,a0,a2
+	sll	a4,a1,a4
+	sra	a2,a1,a2
+	or	a0,a0,a4
+	mv	a1,a2
+.L3:
+	ret
+.L4:
+	negw	a0,a4
+	srai	a2,a1,0x3f
+	sra	a0,a1,a0
+	mv	a1,a2
+	ret
+ENDPROC(__ashrti3)
+EXPORT_SYMBOL(__ashrti3)
+
+ENTRY(__ashlti3)
+	beqz	a2, .L5
+	li	a5,64
+	sub	a5,a5,a2
+	sext.w	a4,a5
+	blez	a5, .L6
+	sext.w	a2,a2
+	sll	a1,a1,a2
+	srl	a4,a0,a4
+	sll	a2,a0,a2
+	or	a1,a1,a4
+	mv	a0,a2
+.L5:
+	ret
+.L6:
+	negw	a1,a4
+	li	a2,0
+	sll	a1,a0,a1
+	mv	a0,a2
+	ret
+ENDPROC(__ashlti3)
+EXPORT_SYMBOL(__ashlti3)
-- 
2.11.0



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

* Re: [PATCH] riscv: Less inefficient gcc tishift helpers (and export their symbols)
  2019-12-17  4:06 ` [PATCH] riscv: Less inefficient gcc tishift helpers (and export their symbols) Olof Johansson
@ 2020-01-19  3:45   ` Paul Walmsley
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Walmsley @ 2020-01-19  3:45 UTC (permalink / raw)
  To: Olof Johansson; +Cc: linux-riscv, Albert Ou, Palmer Dabbelt, linux-kernel

On Mon, 16 Dec 2019, Olof Johansson wrote:

> The existing __lshrti3 was really inefficient, and the other two helpers
> are also needed to compile some modules.
> 
> Add the missing versions, and export all of the symbols like arm64
> already does.
> 
> This fixes a build break triggered by ubsan:
> 
> riscv64-unknown-linux-gnu-ld: lib/ubsan.o: in function `.L2':
> ubsan.c:(.text.unlikely+0x38): undefined reference to `__ashlti3'
> riscv64-unknown-linux-gnu-ld: ubsan.c:(.text.unlikely+0x42): undefined reference to `__ashrti3'
> 
> Signed-off-by: Olof Johansson <olof@lixom.net>

Thanks Olof.  I modified the patch description to note that the code is 
based on libgcc per our off-list discussion, and to use 
SYM_PROC_ENTRY/EXIT per commit ffedeeb780dc5 ("linkage: Introduce new 
macros for assembler symbols"), and have queued the following patch.


- Paul


From: Olof Johansson <olof@lixom.net>
Date: Mon, 16 Dec 2019 20:06:31 -0800
Subject: [PATCH] riscv: Less inefficient gcc tishift helpers (and export their
 symbols)

The existing __lshrti3 was really inefficient, and the other two helpers
are also needed to compile some modules.

Add the missing versions, and export all of the symbols like arm64
already does.

This code is based on the assembly generated by libgcc builds.

This fixes a build break triggered by ubsan:

riscv64-unknown-linux-gnu-ld: lib/ubsan.o: in function `.L2':
ubsan.c:(.text.unlikely+0x38): undefined reference to `__ashlti3'
riscv64-unknown-linux-gnu-ld: ubsan.c:(.text.unlikely+0x42): undefined reference to `__ashrti3'

Signed-off-by: Olof Johansson <olof@lixom.net>
[paul.walmsley@sifive.com: use SYM_FUNC_{START,END} instead of ENTRY/ENDPROC; note
 libgcc origin]
Signed-off-by: Paul Walmsley <paul.walmsley@sifive.com>
---
 arch/riscv/include/asm/asm-prototypes.h |  4 ++
 arch/riscv/lib/tishift.S                | 75 +++++++++++++++++++------
 2 files changed, 61 insertions(+), 18 deletions(-)

diff --git a/arch/riscv/include/asm/asm-prototypes.h b/arch/riscv/include/asm/asm-prototypes.h
index dd62b691c443..27e005fca584 100644
--- a/arch/riscv/include/asm/asm-prototypes.h
+++ b/arch/riscv/include/asm/asm-prototypes.h
@@ -5,4 +5,8 @@
 #include <linux/ftrace.h>
 #include <asm-generic/asm-prototypes.h>
 
+long long __lshrti3(long long a, int b);
+long long __ashrti3(long long a, int b);
+long long __ashlti3(long long a, int b);
+
 #endif /* _ASM_RISCV_PROTOTYPES_H */
diff --git a/arch/riscv/lib/tishift.S b/arch/riscv/lib/tishift.S
index 15f9d54c7db6..ef90075c4b0a 100644
--- a/arch/riscv/lib/tishift.S
+++ b/arch/riscv/lib/tishift.S
@@ -4,34 +4,73 @@
  */
 
 #include <linux/linkage.h>
+#include <asm-generic/export.h>
 
-ENTRY(__lshrti3)
+SYM_FUNC_START(__lshrti3)
 	beqz	a2, .L1
 	li	a5,64
 	sub	a5,a5,a2
-	addi	sp,sp,-16
 	sext.w	a4,a5
 	blez	a5, .L2
 	sext.w	a2,a2
-	sll	a4,a1,a4
 	srl	a0,a0,a2
-	srl	a1,a1,a2
+	sll	a4,a1,a4
+	srl	a2,a1,a2
 	or	a0,a0,a4
-	sd	a1,8(sp)
-	sd	a0,0(sp)
-	ld	a0,0(sp)
-	ld	a1,8(sp)
-	addi	sp,sp,16
-	ret
+	mv	a1,a2
 .L1:
 	ret
 .L2:
-	negw	a4,a4
-	srl	a1,a1,a4
-	sd	a1,0(sp)
-	sd	zero,8(sp)
-	ld	a0,0(sp)
-	ld	a1,8(sp)
-	addi	sp,sp,16
+	negw	a0,a4
+	li	a2,0
+	srl	a0,a1,a0
+	mv	a1,a2
+	ret
+SYM_FUNC_END(__lshrti3)
+EXPORT_SYMBOL(__lshrti3)
+
+SYM_FUNC_START(__ashrti3)
+	beqz	a2, .L3
+	li	a5,64
+	sub	a5,a5,a2
+	sext.w	a4,a5
+	blez	a5, .L4
+	sext.w	a2,a2
+	srl	a0,a0,a2
+	sll	a4,a1,a4
+	sra	a2,a1,a2
+	or	a0,a0,a4
+	mv	a1,a2
+.L3:
+	ret
+.L4:
+	negw	a0,a4
+	srai	a2,a1,0x3f
+	sra	a0,a1,a0
+	mv	a1,a2
+	ret
+SYM_FUNC_END(__ashrti3)
+EXPORT_SYMBOL(__ashrti3)
+
+SYM_FUNC_START(__ashlti3)
+	beqz	a2, .L5
+	li	a5,64
+	sub	a5,a5,a2
+	sext.w	a4,a5
+	blez	a5, .L6
+	sext.w	a2,a2
+	sll	a1,a1,a2
+	srl	a4,a0,a4
+	sll	a2,a0,a2
+	or	a1,a1,a4
+	mv	a0,a2
+.L5:
+	ret
+.L6:
+	negw	a1,a4
+	li	a2,0
+	sll	a1,a0,a1
+	mv	a0,a2
 	ret
-ENDPROC(__lshrti3)
+SYM_FUNC_END(__ashlti3)
+EXPORT_SYMBOL(__ashlti3)
-- 
2.25.0.rc2




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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-17  0:30 [PATCH] riscv: export __lshrti3 Olof Johansson
2019-12-17  1:54 ` Olof Johansson
2019-12-17  4:06 ` [PATCH] riscv: Less inefficient gcc tishift helpers (and export their symbols) Olof Johansson
2020-01-19  3:45   ` Paul Walmsley

Linux-RISC-V Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-riscv/0 linux-riscv/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-riscv linux-riscv/ https://lore.kernel.org/linux-riscv \
		linux-riscv@lists.infradead.org
	public-inbox-index linux-riscv

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-riscv


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