| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-mrvv-vector-bits=scalable -march=rv32gcv -mabi=ilp32 -fno-tree-vectorize -fno-schedule-insns -fno-schedule-insns2" } */ |
| 3 |
|
| 4 |
#include "riscv_vector.h" |
| 5 |
|
| 6 |
int byte_mac_vec(unsigned char *a, unsigned char *b, int len) { |
| 7 |
size_t vlmax = __riscv_vsetvlmax_e8m1(); |
| 8 |
vint32m4_t vec_s = __riscv_vmv_v_x_i32m4(0, vlmax); |
| 9 |
vint32m1_t vec_zero = __riscv_vmv_v_x_i32m1(0, vlmax); |
| 10 |
int k = len; |
| 11 |
|
| 12 |
for (size_t vl; k > 0; k -= vl, a += vl, b += vl) { |
| 13 |
vl = __riscv_vsetvl_e8m1(k); |
| 14 |
|
| 15 |
vuint8m1_t a8s = __riscv_vle8_v_u8m1(a, vl); |
| 16 |
vuint8m1_t b8s = __riscv_vle8_v_u8m1(b, vl); |
| 17 |
vuint32m4_t a8s_extended = __riscv_vzext_vf4_u32m4(a8s, vl); |
| 18 |
vuint32m4_t b8s_extended = __riscv_vzext_vf4_u32m4(a8s, vl); |
| 19 |
|
| 20 |
vint32m4_t a8s_as_i32 = __riscv_vreinterpret_v_u32m4_i32m4(a8s_extended); |
| 21 |
vint32m4_t b8s_as_i32 = __riscv_vreinterpret_v_u32m4_i32m4(b8s_extended); |
| 22 |
|
| 23 |
vec_s = __riscv_vmacc_vv_i32m4_tu(vec_s, a8s_as_i32, b8s_as_i32, vl); |
| 24 |
} |
| 25 |
|
| 26 |
vint32m1_t vec_sum = __riscv_vredsum_vs_i32m4_i32m1(vec_s, vec_zero, __riscv_vsetvl_e32m4(len)); |
| 27 |
int sum = __riscv_vmv_x_s_i32m1_i32(vec_sum); |
| 28 |
|
| 29 |
return sum; |
| 30 |
} |
| 31 |
|
| 32 |
/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*[a-x0-9]+,\s*e32,\s*m1,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-Oz" no-opts "-g" no-opts "-funroll-loops" } } } } */ |
| 33 |
/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*m4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-Oz" no-opts "-g" no-opts "-funroll-loops" } } } } */ |
| 34 |
/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*[a-x0-9]+,\s*e32,\s*m4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-Oz" no-opts "-g" no-opts "-funroll-loops" } } } } */ |
| 35 |
/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*[a-x0-9]+,\s*e32,\s*m4,\s*tu,\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-Oz" no-opts "-g" no-opts "-funroll-loops" } } } } */ |
| 36 |
/* { dg-final { scan-assembler-times {vsetvli} 4 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-Oz" no-opts "-g" no-opts "-funroll-loops" } } } } */ |