From af720838a4209f385c8c2012e613cfabc668ec30 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Mon, 16 Dec 2024 20:13:26 +0900 Subject: [PATCH] utils: Adopt to use RVV extentions for RISC-V Signed-off-by: Hiroshi Hatake --- src/flb_utils.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/flb_utils.c b/src/flb_utils.c index 55b5bf6cae8..7ba7da534c5 100644 --- a/src/flb_utils.c +++ b/src/flb_utils.c @@ -801,6 +801,11 @@ int flb_utils_write_str(char *buf, int *off, size_t size, const char *str, size_ off_t offset = 0; char tmp[16]; char *p; +#if defined(FLB_SIMD_RVV) + const size_t inst_len = RVV_VEC_INST_LEN; +#else + const size_t inst_len = sizeof(flb_vector8); +#endif /* to encode codepoints > 0xFFFF */ uint16_t high; @@ -816,10 +821,10 @@ int flb_utils_write_str(char *buf, int *off, size_t size, const char *str, size_ p = buf + *off; /* align length to the nearest multiple of the vector size for safe SIMD processing */ - vlen = str_len & ~(sizeof(flb_vector8) - 1); + vlen = str_len & ~(inst_len - 1); for (i = 0;;) { /* SIMD optimization: Process chunk of input string */ - for (; i < vlen; i += sizeof(flb_vector8)) { + for (; i < vlen; i += inst_len) { flb_vector8 chunk; flb_vector8_load(&chunk, (const uint8_t *)&str[i]); @@ -851,7 +856,7 @@ int flb_utils_write_str(char *buf, int *off, size_t size, const char *str, size_ } /* Process remaining characters one by one */ - for (b = 0; b < sizeof(flb_vector8); b++) { + for (b = 0; b < inst_len; b++) { if (i >= str_len) { /* all characters has been processed */ goto done;