Skip to content

Commit bf1a1ba

Browse files
committed
Merge tag 'riscv-for-linus-6.3-mw2' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull more RISC-V updates from Palmer Dabbelt: - Some cleanups and fixes for the Zbb-optimized string routines - Support for custom (vendor or implementation defined) perf events - COMMAND_LINE_SIZE has been increased to 1024 * tag 'riscv-for-linus-6.3-mw2' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: Bump COMMAND_LINE_SIZE value to 1024 drivers/perf: RISC-V: Allow programming custom firmware events riscv, lib: Fix Zbb strncmp RISC-V: improve string-function assembly
2 parents 271d893 + 61fc1ee commit bf1a1ba

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

arch/riscv/include/uapi/asm/setup.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
2+
3+
#ifndef _UAPI_ASM_RISCV_SETUP_H
4+
#define _UAPI_ASM_RISCV_SETUP_H
5+
6+
#define COMMAND_LINE_SIZE 1024
7+
8+
#endif /* _UAPI_ASM_RISCV_SETUP_H */

arch/riscv/lib/strcmp.S

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ SYM_FUNC_START(strcmp)
4040
ret
4141

4242
/*
43-
* Variant of strcmp using the ZBB extension if available
43+
* Variant of strcmp using the ZBB extension if available.
44+
* The code was published as part of the bitmanip manual
45+
* in Appendix A.
4446
*/
4547
#ifdef CONFIG_RISCV_ISA_ZBB
4648
strcmp_zbb:
@@ -57,7 +59,7 @@ strcmp_zbb:
5759
* a1 - string2
5860
*
5961
* Clobbers
60-
* t0, t1, t2, t3, t4, t5
62+
* t0, t1, t2, t3, t4
6163
*/
6264

6365
or t2, a0, a1

arch/riscv/lib/strlen.S

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ strlen_zbb:
9696
* of valid bytes in this chunk.
9797
*/
9898
srli a0, t1, 3
99-
bgtu t3, a0, 3f
99+
bgtu t3, a0, 2f
100100

101101
/* Prepare for the word comparison loop. */
102102
addi t2, t0, SZREG
@@ -112,20 +112,20 @@ strlen_zbb:
112112
addi t0, t0, SZREG
113113
orc.b t1, t1
114114
beq t1, t3, 1b
115-
2:
115+
116116
not t1, t1
117117
CZ t1, t1
118+
srli t1, t1, 3
118119

119-
/* Get number of processed words. */
120+
/* Get number of processed bytes. */
120121
sub t2, t0, t2
121122

122123
/* Add number of characters in the first word. */
123124
add a0, a0, t2
124-
srli t1, t1, 3
125125

126126
/* Add number of characters in the last word. */
127127
add a0, a0, t1
128-
3:
128+
2:
129129
ret
130130

131131
.option pop

arch/riscv/lib/strncmp.S

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,21 @@ strncmp_zbb:
7070
li t5, -1
7171
and t2, t2, SZREG-1
7272
add t4, a0, a2
73-
bnez t2, 4f
73+
bnez t2, 3f
7474

7575
/* Adjust limit for fast-path. */
7676
andi t6, t4, -SZREG
7777

7878
/* Main loop for aligned string. */
7979
.p2align 3
8080
1:
81-
bgt a0, t6, 3f
81+
bge a0, t6, 3f
8282
REG_L t0, 0(a0)
8383
REG_L t1, 0(a1)
8484
orc.b t3, t0
8585
bne t3, t5, 2f
86+
orc.b t3, t1
87+
bne t3, t5, 2f
8688
addi a0, a0, SZREG
8789
addi a1, a1, SZREG
8890
beq t0, t1, 1b
@@ -114,23 +116,21 @@ strncmp_zbb:
114116
ret
115117

116118
/* Simple loop for misaligned strings. */
117-
3:
118-
/* Restore limit for slow-path. */
119119
.p2align 3
120-
4:
121-
bge a0, t4, 6f
120+
3:
121+
bge a0, t4, 5f
122122
lbu t0, 0(a0)
123123
lbu t1, 0(a1)
124124
addi a0, a0, 1
125125
addi a1, a1, 1
126-
bne t0, t1, 5f
127-
bnez t0, 4b
126+
bne t0, t1, 4f
127+
bnez t0, 3b
128128

129-
5:
129+
4:
130130
sub a0, t0, t1
131131
ret
132132

133-
6:
133+
5:
134134
li a0, 0
135135
ret
136136

drivers/perf/riscv_pmu_sbi.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,8 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig)
436436
bSoftware = config >> 63;
437437
raw_config_val = config & RISCV_PMU_RAW_EVENT_MASK;
438438
if (bSoftware) {
439-
if (raw_config_val < SBI_PMU_FW_MAX)
440-
ret = (raw_config_val & 0xFFFF) |
441-
(SBI_PMU_EVENT_TYPE_FW << 16);
442-
else
443-
return -EINVAL;
439+
ret = (raw_config_val & 0xFFFF) |
440+
(SBI_PMU_EVENT_TYPE_FW << 16);
444441
} else {
445442
ret = RISCV_PMU_RAW_EVENT_IDX;
446443
*econfig = raw_config_val;

0 commit comments

Comments
 (0)