| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
#include <riscv_vector.h> |
| 13 |
|
| 14 |
#include "xnnpack/common.h" |
| 15 |
#include "xnnpack/vunary.h" |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
void xnn_f32_vrsqrt_ukernel__rvv_rsqrt_u1v( |
| 39 |
size_t batch, |
| 40 |
const float* input, |
| 41 |
float* output, |
| 42 |
const struct xnn_f32_default_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 43 |
{ |
| 44 |
assert(batch != 0); |
| 45 |
assert(batch % sizeof(float) == 0); |
| 46 |
assert(input != NULL); |
| 47 |
assert(output != NULL); |
| 48 |
|
| 49 |
batch >>= XNN_LOG2_SIZEOF_FLOAT; |
| 50 |
|
| 51 |
vfloat32m1_t onephalf_f32v = __riscv_vfmv_v_f_f32m1(1.5f, __riscv_vsetvl_e32m1(batch)); |
| 52 |
for (; batch > 0; ) { |
| 53 |
int32_t n = __riscv_vsetvl_e32m1(batch); batch -= n; |
| 54 |
vfloat32m1_t in_f32v = __riscv_vle32_v_f32m1(input, n); input += n; |
| 55 |
|
| 56 |
vfloat32m1_t t0_f32v = __riscv_vfrsqrt7_v_f32m1(in_f32v, n); |
| 57 |
vfloat32m1_t in_half_f32v = __riscv_vfmul_vf_f32m1(in_f32v, 0.5f, n); |
| 58 |
|
| 59 |
|
| 60 |
vfloat32m1_t t1_f32v = __riscv_vfmul_vv_f32m1(t0_f32v, t0_f32v, n); |
| 61 |
vfloat32m1_t t2_f32v = __riscv_vfnmsub_vv_f32m1(in_half_f32v, t1_f32v, onephalf_f32v, n); |
| 62 |
t0_f32v = __riscv_vfmul_vv_f32m1(t0_f32v, t2_f32v, n); |
| 63 |
|
| 64 |
|
| 65 |
t1_f32v = __riscv_vfmul_vv_f32m1(t0_f32v, t0_f32v, n); |
| 66 |
t2_f32v = __riscv_vfnmsub_vv_f32m1(in_half_f32v, t1_f32v, onephalf_f32v, n); |
| 67 |
vfloat32m1_t y_f32v = __riscv_vfmul_vv_f32m1(t0_f32v, t2_f32v, n); |
| 68 |
|
| 69 |
__riscv_vse32_v_f32m1(output, y_f32v, n); output += n; |
| 70 |
} |
| 71 |
} |