Skip to contentSkip to conversation

riscv: simply longjmp()

PATCH New Heinrich Schuchardt 2 participants 5 messages Mar 21, 2021 – Mar 22, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

cover riscv: simply longjmp()

The implementation of longjmp() is simplified.
A unit test for longjmp() is provided.

For testing use

CONFIG_UNIT_TEST=y
CONFIG_CMD_SETEXPR=n

and execute

ut lib

Heinrich Schuchardt (2):
riscv: simply longjmp
test: unit test for longjmp

 arch/riscv/lib/setjmp.S |  8 ++------
 test/lib/Makefile       |  1 +
 test/lib/longjmp.c      | 45 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 6 deletions(-)
 create mode 100644 test/lib/longjmp.c

--
2.30.2

#1 lore raw

PATCH 1/2 riscv: simply longjmp

The value returned by setjmp must be nonzero. If zero is passed as parameter it must be replaced by 1.

This patch reduces the code size a bit.

---
 arch/riscv/lib/setjmp.S | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
arch/riscv/lib/setjmp.S +2 -6
index 72bc9241f6..99d6195827 100644
@@ -54,12 +54,8 @@ ENTRY(longjmp)
 	LOAD_IDX(sp, 13)
 
 	/* Move the return value in place, but return 1 if passed 0. */
-	beq a1, zero, longjmp_1
-	mv a0, a1
-	ret
-
-	longjmp_1:
-	li a0, 1
+	seqz a0, a1
+	add a0, a0, a1
 	ret
 ENDPROC(longjmp)
 .popsection

--
2.30.2

#2 lore raw

PATCH 1/2 riscv: simply longjmp

Quoted 30 lines · Heinrich Schuchardt

The value returned by setjmp must be nonzero. If zero is passed as parameter it must be replaced by 1.

This patch reduces the code size a bit.

---
  arch/riscv/lib/setjmp.S | 8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)
arch/riscv/lib/setjmp.S +2 -7
index 72bc9241f6..99d6195827 100644
@@ -54,12 +54,8 @@ ENTRY(longjmp)
  	LOAD_IDX(sp, 13)
 
  	/* Move the return value in place, but return 1 if passed 0. */
-	beq a1, zero, longjmp_1
-	mv a0, a1
-	ret
-
-	longjmp_1:
-	li a0, 1
+	seqz a0, a1
+	add a0, a0, a1
  	ret
  ENDPROC(longjmp)
  .popsection
--
Quoted 2 lines

2.30.2

#3 lore raw

PATCH 1/2 riscv: simply longjmp

Quoted 27 lines · Sean Anderson
Quoted 26 lines · Heinrich Schuchardt

The value returned by setjmp must be nonzero. If zero is passed as parameter it must be replaced by 1.

This patch reduces the code size a bit.

---
? arch/riscv/lib/setjmp.S | 8 ++------
? 1 file changed, 2 insertions(+), 6 deletions(-)

arch/riscv/lib/setjmp.S +0 -0
index 72bc9241f6..99d6195827 100644
@@ -54,12 +54,8 @@ ENTRY(longjmp)
 ????? LOAD_IDX(sp, 13)
 

????? /* Move the return value in place, but return 1 if passed 0. */ -??? beq a1, zero, longjmp_1
-??? mv a0, a1
-??? ret
-
-??? longjmp_1:
-??? li a0, 1
+??? seqz a0, a1
+??? add a0, a0, a1

Quoted 8 lines
Quoted 6 lines

????? ret
? ENDPROC(longjmp)
? .popsection
--
2.30.2

The title should be corrected to "Simplify longjmp".

#4 lore raw

PATCH 2/2 test: unit test for longjmp

In reply to Heinrich Schuchardt

Provide a unit test for the longjmp() library function

---
 test/lib/Makefile  |  1 +
 test/lib/longjmp.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100644 test/lib/longjmp.c
test/lib/Makefile +1 -0
index 97c11e35a8..a30f615aa9 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_EFI_LOADER) += efi_device_path.o
 obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o
 obj-y += hexdump.o
 obj-y += lmb.o
+obj-y += longjmp.o
 obj-$(CONFIG_CONSOLE_RECORD) += test_print.o
 obj-$(CONFIG_SSCANF) += sscanf.o
 obj-y += string.o
test/lib/longjmp.c new file +44 -0

44 lines not on this page · raw message

--
2.30.2