Skip to content

Commit 2a8e1ae

Browse files
committed
simd: utils: Use macro to avoid magic numbers
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 99c5fc2 commit 2a8e1ae

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

include/fluent-bit/flb_simd.h

+16-10
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ typedef uint32x4_t flb_vector32;
7777
typedef vuint8m1_t flb_vector8;
7878
typedef vuint32m1_t flb_vector32;
7979

80-
/* Currently, VLEN is assumed to 128. */
81-
#define RVV_VEC_INST_LEN (128 / 8) /* 16 */
80+
#define RVV_VEC8_INST_LEN (128 / 8) /* 16 */
81+
#define RVV_VEC32_INST_LEN (128 / 8 / 4) /* 4 */
8282

8383
#else
8484
/*
@@ -116,7 +116,7 @@ static inline void flb_vector8_load(flb_vector8 *v, const uint8_t *s)
116116
#elif defined(FLB_SIMD_NEON)
117117
*v = vld1q_u8(s);
118118
#elif defined(FLB_SIMD_RVV)
119-
*v = __riscv_vle8_v_u8m1(s, 16);
119+
*v = __riscv_vle8_v_u8m1(s, RVV_VEC8_INST_LEN);
120120
#else
121121
memset(v, 0, sizeof(flb_vector8));
122122
#endif
@@ -153,7 +153,7 @@ static inline flb_vector8 flb_vector8_ssub(const flb_vector8 v1, const flb_vecto
153153
#elif defined(FLB_SIMD_NEON)
154154
return vqsubq_u8(v1, v2);
155155
#elif defined(FLB_SIMD_RVV)
156-
return __riscv_vssubu_vv_u8m1(v1, v2, 16);
156+
return __riscv_vssubu_vv_u8m1(v1, v2, RVV_VEC8_INST_LEN);
157157
#endif
158158
}
159159
#endif /* ! FLB_SIMD_NONE */
@@ -170,8 +170,10 @@ static inline flb_vector8 flb_vector8_eq(const flb_vector8 v1, const flb_vector8
170170
#elif defined(FLB_SIMD_NEON)
171171
return vceqq_u8(v1, v2);
172172
#elif defined(FLB_SIMD_RVV)
173-
vbool8_t ret = __riscv_vmseq_vv_u8m1_b8(v1, v2, 16);
174-
return __riscv_vmerge_vvm_u8m1(__riscv_vmv_v_x_u8m1(0, 16), __riscv_vmv_v_x_u8m1(UINT8_MAX, 16), ret, 16);
173+
vbool8_t ret = __riscv_vmseq_vv_u8m1_b8(v1, v2, RVV_VEC8_INST_LEN);
174+
return __riscv_vmerge_vvm_u8m1(__riscv_vmv_v_x_u8m1(0, RVV_VEC8_INST_LEN),
175+
__riscv_vmv_v_x_u8m1(UINT8_MAX, RVV_VEC8_INST_LEN),
176+
ret, RVV_VEC8_INST_LEN);
175177
#endif
176178
}
177179
#endif /* ! FLB_SIMD_NONE */
@@ -184,8 +186,10 @@ static inline flb_vector32 flb_vector32_eq(const flb_vector32 v1, const flb_vect
184186
#elif defined(FLB_SIMD_NEON)
185187
return vceqq_u32(v1, v2);
186188
#elif defined(FLB_SIMD_RVV)
187-
vbool32_t ret = __riscv_vmseq_vv_u32m1_b32(v1, v2, 4);
188-
return __riscv_vmerge_vvm_u32m1(__riscv_vmv_v_x_u32m1(0, 4), __riscv_vmv_v_x_u32m1(UINT32_MAX, 4), ret, 4);
189+
vbool32_t ret = __riscv_vmseq_vv_u32m1_b32(v1, v2, RVV_VEC32_INST_LEN);
190+
return __riscv_vmerge_vvm_u32m1(__riscv_vmv_v_x_u32m1(0, RVV_VEC32_INST_LEN),
191+
__riscv_vmv_v_x_u32m1(UINT32_MAX, RVV_VEC32_INST_LEN),
192+
ret, RVV_VEC32_INST_LEN);
189193
#endif
190194
}
191195
#endif /* ! FLB_SIMD_NONE */
@@ -200,7 +204,7 @@ static inline flb_vector8 flb_vector8_broadcast(const uint8_t c)
200204
#elif defined(FLB_SIMD_NEON)
201205
return vdupq_n_u8(c);
202206
#elif defined(FLB_SIMD_RVV)
203-
return __riscv_vmv_v_x_u8m1(c, 16);
207+
return __riscv_vmv_v_x_u8m1(c, RVV_VEC8_INST_LEN);
204208
#else
205209
return ~UINT64CONST(0) / 0xFF * c;
206210
#endif
@@ -216,7 +220,9 @@ static inline bool flb_vector8_is_highbit_set(const flb_vector8 v)
216220
#elif defined(FLB_SIMD_NEON)
217221
return vmaxvq_u8(v) > 0x7F;
218222
#elif defined(FLB_SIMD_RVV)
219-
return __riscv_vmv_x_s_u8m1_u8(__riscv_vredmaxu_vs_u8m1_u8m1(v, __riscv_vmv_v_x_u8m1(0, 16), 16));
223+
return __riscv_vmv_x_s_u8m1_u8(__riscv_vredmaxu_vs_u8m1_u8m1(v,
224+
__riscv_vmv_v_x_u8m1(0, RVV_VEC8_INST_LEN),
225+
RVV_VEC8_INST_LEN));
220226
#else
221227
return v & flb_vector8_broadcast(0x80);
222228
#endif

src/flb_utils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ int flb_utils_write_str(char *buf, int *off, size_t size, const char *str, size_
802802
char tmp[16];
803803
char *p;
804804
#if defined(FLB_SIMD_RVV)
805-
const size_t inst_len = RVV_VEC_INST_LEN;
805+
const size_t inst_len = RVV_VEC8_INST_LEN;
806806
#else
807807
const size_t inst_len = sizeof(flb_vector8);
808808
#endif

0 commit comments

Comments
 (0)