Skip to content

Commit 68cef1a

Browse files
author
shuzhuo
committed
NMSIS/DSP: add rvv fp32/fp16 math function(exp,logf,sin,cos,pow,tanh, etc.)
1 parent a214b7b commit 68cef1a

File tree

14 files changed

+1081
-90
lines changed

14 files changed

+1081
-90
lines changed

NMSIS/DSP/Include/riscv_helium_utils.h

Lines changed: 0 additions & 75 deletions
This file was deleted.

NMSIS/DSP/Include/riscv_math.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
#include "riscv_math_f16.h"
140140
#endif /* defined (RISCV_FLOAT16_SUPPORTED) */
141141

142+
#if defined(RISCV_MATH_VECTOR)
143+
#include "riscv_vec_math.h"
144+
#endif /* defined(RISCV_MATH_VECTOR) */
142145

143146

144147
#ifdef __cplusplus

NMSIS/DSP/Include/riscv_vec_math.h

Lines changed: 536 additions & 1 deletion
Large diffs are not rendered by default.

NMSIS/DSP/Include/riscv_vec_math_f16.h

Lines changed: 372 additions & 4 deletions
Large diffs are not rendered by default.

NMSIS/DSP/PrivateInclude/riscv_vec_fft.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#define _RISCV_VEC_FFT_H_
2828

2929
#include "riscv_math.h"
30-
#include "riscv_helium_utils.h"
3130

3231
#ifdef __cplusplus
3332
extern "C"

NMSIS/DSP/PrivateInclude/riscv_vec_filtering.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#define _RISCV_VEC_FILTERING_H_
2828

2929
#include "riscv_math.h"
30-
#include "riscv_helium_utils.h"
3130

3231
#ifdef __cplusplus
3332
extern "C"

NMSIS/DSP/Source/FastMathFunctions/riscv_vexp_f16.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333

3434
#include "riscv_common_tables.h"
3535

36+
#if defined(RISCV_MATH_VECTOR)
3637
#include "riscv_vec_math_f16.h"
38+
#endif /* defined(RISCV_MATH_VECTOR) */
3739

3840
/**
3941
@addtogroup vexp
@@ -53,6 +55,18 @@ RISCV_DSP_ATTRIBUTE void riscv_vexp_f16(
5355
{
5456
uint32_t blkCnt;
5557

58+
#if defined(RISCV_MATH_VECTOR)
59+
size_t l;
60+
blkCnt = blockSize;
61+
vfloat16m8_t vx, vy;
62+
for (; (l = __riscv_vsetvl_e16m8(blkCnt)) > 0; blkCnt -= l) {
63+
vx = __riscv_vle16_v_f16m8(pSrc, l);
64+
pSrc += l;
65+
vy = exp_ps_f16_m8(vx, l);
66+
__riscv_vse16_v_f16m8(pDst, vy, l);
67+
pDst += l;
68+
}
69+
#else
5670
blkCnt = blockSize;
5771

5872
while (blkCnt > 0U)
@@ -65,10 +79,11 @@ RISCV_DSP_ATTRIBUTE void riscv_vexp_f16(
6579
/* Decrement loop counter */
6680
blkCnt--;
6781
}
82+
#endif /* defined(RISCV_MATH_VECTOR) */
6883
}
6984

7085
#endif /* #if defined(RISCV_FLOAT16_SUPPORTED) */
7186

7287
/**
7388
@} end of vexp group
74-
*/
89+
*/

NMSIS/DSP/Source/FastMathFunctions/riscv_vexp_f32.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#include "dsp/fast_math_functions.h"
3131
#include "riscv_common_tables.h"
3232

33+
#if defined(RISCV_MATH_VECTOR)
34+
#include "riscv_vec_math.h"
35+
#endif /* defined(RISCV_MATH_VECTOR) */
3336

3437
/**
3538
@ingroup groupFastMath
@@ -59,6 +62,18 @@ RISCV_DSP_ATTRIBUTE void riscv_vexp_f32(
5962
{
6063
uint32_t blkCnt;
6164

65+
#if defined(RISCV_MATH_VECTOR)
66+
size_t l;
67+
blkCnt = blockSize;
68+
vfloat32m8_t vx, vy;
69+
for (; (l = __riscv_vsetvl_e32m8(blkCnt)) > 0; blkCnt -= l) {
70+
vx = __riscv_vle32_v_f32m8(pSrc, l);
71+
pSrc += l;
72+
vy = exp_ps_m8(vx, l);
73+
__riscv_vse32_v_f32m8(pDst, vy, l);
74+
pDst += l;
75+
}
76+
#else
6277
blkCnt = blockSize;
6378

6479
while (blkCnt > 0U)
@@ -71,8 +86,9 @@ RISCV_DSP_ATTRIBUTE void riscv_vexp_f32(
7186
/* Decrement loop counter */
7287
blkCnt--;
7388
}
89+
#endif /* defined(RISCV_MATH_VECTOR) */
7490
}
7591

7692
/**
7793
@} end of vexp group
78-
*/
94+
*/

NMSIS/DSP/Source/FastMathFunctions/riscv_vlog_f16.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232

3333
#if defined(RISCV_FLOAT16_SUPPORTED)
3434

35+
#if defined(RISCV_MATH_VECTOR)
36+
#include "riscv_vec_math_f16.h"
37+
#endif /* defined(RISCV_MATH_VECTOR) */
38+
39+
3540
/* Degree of the polynomial approximation */
3641
#define NB_DEG_LOGF16 3
3742

@@ -128,6 +133,18 @@ RISCV_DSP_ATTRIBUTE void riscv_vlog_f16(
128133
{
129134
uint32_t blkCnt;
130135

136+
#if defined(RISCV_MATH_VECTOR)
137+
size_t l;
138+
blkCnt = blockSize;
139+
vfloat16m8_t vx, vy;
140+
for (; (l = __riscv_vsetvl_e16m8(blkCnt)) > 0; blkCnt -= l) {
141+
vx = __riscv_vle16_v_f16m8(pSrc, l);
142+
pSrc += l;
143+
vy = log_ps_f16_m8(vx, l);
144+
__riscv_vse16_v_f16m8(pDst, vy, l);
145+
pDst += l;
146+
}
147+
#else
131148
blkCnt = blockSize;
132149

133150
while (blkCnt > 0U)
@@ -140,6 +157,7 @@ RISCV_DSP_ATTRIBUTE void riscv_vlog_f16(
140157
/* Decrement loop counter */
141158
blkCnt--;
142159
}
160+
#endif /* defined(RISCV_MATH_VECTOR) */
143161
}
144162

145163

NMSIS/DSP/Source/FastMathFunctions/riscv_vlog_f32.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
#include "dsp/fast_math_functions.h"
3131
#include "riscv_common_tables.h"
3232

33+
#if defined(RISCV_MATH_VECTOR)
34+
#include "riscv_vec_math.h"
35+
#endif /* defined(RISCV_MATH_VECTOR) */
3336

37+
#include <stdio.h>
3438
/**
3539
@ingroup groupFastMath
3640
*/
@@ -54,8 +58,20 @@ RISCV_DSP_ATTRIBUTE void riscv_vlog_f32(
5458
float32_t * pDst,
5559
uint32_t blockSize)
5660
{
57-
uint32_t blkCnt;
61+
uint32_t blkCnt;
5862

63+
#if defined(RISCV_MATH_VECTOR)
64+
size_t l;
65+
blkCnt = blockSize;
66+
vfloat32m8_t vx, vy;
67+
for (; (l = __riscv_vsetvl_e32m8(blkCnt)) > 0; blkCnt -= l) {
68+
vx = __riscv_vle32_v_f32m8(pSrc, l);
69+
pSrc += l;
70+
vy = log_ps_m8(vx, l);
71+
__riscv_vse32_v_f32m8(pDst, vy, l);
72+
pDst += l;
73+
}
74+
#else
5975
blkCnt = blockSize;
6076

6177
while (blkCnt > 0U)
@@ -68,6 +84,7 @@ RISCV_DSP_ATTRIBUTE void riscv_vlog_f32(
6884
/* Decrement loop counter */
6985
blkCnt--;
7086
}
87+
#endif /* defined(RISCV_MATH_VECTOR) */
7188
}
7289

7390
/**

0 commit comments

Comments
 (0)