Skip to content

Commit 344159e

Browse files
authored
Merge pull request ceph#65354 from sunyuechi/main
inline_memory: optimize mem_is_zero for riscv using RISC-V Vector (RVV) intrinsics
2 parents d1afa98 + 60e95db commit 344159e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/include/inline_memory.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Ceph - scalable distributed file system
55
*
66
* Copyright (C) 2004-2006 Sage Weil <[email protected]>
7+
* Copyright (C) 2025 Sun Yuechi <[email protected]>
78
*
89
* This is free software; you can redistribute it and/or
910
* modify it under the terms of the GNU Lesser General Public
@@ -170,6 +171,31 @@ static inline bool mem_is_zero(const char *data, size_t len) {
170171
return true;
171172
}
172173

174+
#elif defined(__riscv_v_intrinsic)
175+
176+
#include <riscv_vector.h>
177+
178+
static inline bool mem_is_zero(const char *data, size_t len) {
179+
const uint8_t *p = reinterpret_cast<const uint8_t *>(data);
180+
181+
while (len > 0) {
182+
size_t vector_len = __riscv_vsetvl_e8m8(len);
183+
184+
vuint8m8_t v = __riscv_vle8_v_u8m8(p, vector_len);
185+
vbool1_t mask = __riscv_vmsne_vx_u8m8_b1(v, 0, vector_len);
186+
187+
long idx = __riscv_vfirst_m_b1(mask, vector_len);
188+
if (idx >= 0) {
189+
return false;
190+
}
191+
192+
p += vector_len;
193+
len -= vector_len;
194+
}
195+
196+
return true;
197+
}
198+
173199
#else // gcc and x86_64
174200

175201
static inline bool mem_is_zero(const char *data, size_t len) {

0 commit comments

Comments
 (0)