Skip to content

Commit

Permalink
utils: Adopt to use RVV extentions for RISC-V
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Dec 19, 2024
1 parent ca62c70 commit af72083
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/flb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit af72083

Please sign in to comment.