diff mbox series

[1/2] riscv: simply longjmp

Message ID 20210321101947.54746-2-xypron.glpk@gmx.de
State Superseded, archived
Delegated to: Andes
Headers show
Series riscv: simply longjmp() | expand

Commit Message

Heinrich Schuchardt March 21, 2021, 10:19 a.m. UTC
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.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 arch/riscv/lib/setjmp.S | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

--
2.30.2

Comments

Sean Anderson March 22, 2021, 4:56 a.m. UTC | #1
On 3/21/21 6:19 AM, Heinrich Schuchardt wrote:
> 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.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>   arch/riscv/lib/setjmp.S | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/riscv/lib/setjmp.S b/arch/riscv/lib/setjmp.S
> index 72bc9241f6..99d6195827 100644
> --- a/arch/riscv/lib/setjmp.S
> +++ b/arch/riscv/lib/setjmp.S
> @@ -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
> 

Reviewed-by: Sean Anderson <seanga2@gmail.com>
Heinrich Schuchardt March 22, 2021, 10:03 a.m. UTC | #2
On 22.03.21 05:56, Sean Anderson wrote:
> On 3/21/21 6:19 AM, Heinrich Schuchardt wrote:
>> 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.
>>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> ---
>>   arch/riscv/lib/setjmp.S | 8 ++------
>>   1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/arch/riscv/lib/setjmp.S b/arch/riscv/lib/setjmp.S
>> index 72bc9241f6..99d6195827 100644
>> --- a/arch/riscv/lib/setjmp.S
>> +++ b/arch/riscv/lib/setjmp.S
>> @@ -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
>>
>
> Reviewed-by: Sean Anderson <seanga2@gmail.com>

The title should be corrected to "Simplify longjmp".
diff mbox series

Patch

diff --git a/arch/riscv/lib/setjmp.S b/arch/riscv/lib/setjmp.S
index 72bc9241f6..99d6195827 100644
--- a/arch/riscv/lib/setjmp.S
+++ b/arch/riscv/lib/setjmp.S
@@ -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