Skip to content

Commit

Permalink
Merge pull request #31 from rivosinc/dev/ptpt/expint1
Browse files Browse the repository at this point in the history
added FP64 exponential integral function expint1
  • Loading branch information
PingTakPeterTang authored Jun 5, 2024
2 parents 1f8d20f + d562849 commit 0a6c0c0
Show file tree
Hide file tree
Showing 10 changed files with 760 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ set(PROJECT_SOURCES
src/rvvlm_exp10DI.c
src/rvvlm_expm1D.c
src/rvvlm_expm1DI.c
src/rvvlm_expint1D.c
src/rvvlm_expint1DI.c
src/rvvlm_logD_tbl.c
src/rvvlm_logD.c
src/rvvlm_logDI.c
Expand Down
54 changes: 45 additions & 9 deletions include/rvvlm.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,31 @@ union sui64_fp64 {

#define KNUTH2SUM(X, Y, S, s, vlen) \
do { \
S = __riscv_vfadd((X), (Y), (vlen)); \
(S) = __riscv_vfadd((X), (Y), (vlen)); \
VFLOAT X_hat = __riscv_vfsub((S), (Y), (vlen)); \
s = __riscv_vfadd( \
(s) = __riscv_vfadd( \
__riscv_vfsub((X), X_hat, (vlen)), \
__riscv_vfsub((Y), __riscv_vfsub((S), X_hat, (vlen)), (vlen)), \
(vlen)); \
} while (0)

#define FIX2FLT(X, scale, y_hi, y_lo, vlen) \
do { \
(y_hi) = __riscv_vfcvt_f((X), (vlen)); \
(y_lo) = __riscv_vfcvt_f( \
__riscv_vsub((X), __riscv_vfcvt_x((y_hi), (vlen)), (vlen)), (vlen)); \
(y_hi) = __riscv_vfmul((y_hi), (scale), (vlen)); \
(y_lo) = __riscv_vfmul((y_lo), (scale), (vlen)); \
} while (0)

#define FLT2FIX(x_hi, x_lo, scale, Y, vlen) \
do { \
(Y) = __riscv_vfcvt_x(__riscv_vfmul((x_hi), (scale), (vlen)), (vlen)); \
(Y) = __riscv_vadd( \
(Y), __riscv_vfcvt_x(__riscv_vfmul((x_lo), (scale), (vlen)), (vlen)), \
(vlen)); \
} while (0)

#define PROD_X1Y1(x, y, prod_hi, prod_lo, vlen) \
do { \
(prod_hi) = __riscv_vfmul((x), (y), (vlen)); \
Expand All @@ -158,6 +175,14 @@ union sui64_fp64 {
(prod_lo) = __riscv_vfmacc((prod_lo), (x_lo), (y_hi), (vlen)); \
} while (0)

#define SQR_X2(x_hi, x_lo, prod_hi, prod_lo, vlen) \
do { \
(prod_hi) = __riscv_vfmul((x_hi), (x_hi), (vlen)); \
(prod_lo) = __riscv_vfmsub((x_hi), (x_hi), (prod_hi), (vlen)); \
(prod_lo) = __riscv_vfmacc((prod_lo), (x_hi), (x_lo), (vlen)); \
(prod_lo) = __riscv_vfmacc((prod_lo), (x_lo), (x_hi), (vlen)); \
} while (0)

#define DIV_N1D2(numer, denom, delta_d, Q, q, vlen) \
do { \
Q = __riscv_vfdiv((numer), (denom), (vlen)); \
Expand Down Expand Up @@ -233,13 +258,13 @@ union sui64_fp64 {

#define FAST_LDEXP(num, exp, vlen) \
do { \
VINT n1 = __riscv_vsra((exp), 1, (vlen)); \
VINT n2 = __riscv_vsub((exp), n1, (vlen)); \
n1 = __riscv_vsll(n1, MAN_LEN, (vlen)); \
num = I_AS_F(__riscv_vadd(F_AS_I((num)), n1, (vlen))); \
n2 = __riscv_vadd(n2, EXP_BIAS, (vlen)); \
n2 = __riscv_vsll(n2, MAN_LEN, (vlen)); \
num = __riscv_vfmul((num), I_AS_F(n2), (vlen)); \
VINT _n1 = __riscv_vsra((exp), 1, (vlen)); \
VINT _n2 = __riscv_vsub((exp), _n1, (vlen)); \
_n1 = __riscv_vsll(_n1, MAN_LEN, (vlen)); \
(num) = I_AS_F(__riscv_vadd(F_AS_I((num)), _n1, (vlen))); \
_n2 = __riscv_vadd(_n2, EXP_BIAS, (vlen)); \
_n2 = __riscv_vsll(_n2, MAN_LEN, (vlen)); \
(num) = __riscv_vfmul((num), I_AS_F(_n2), (vlen)); \
} while (0)

// Some of the functions have multiple implementations using different
Expand Down Expand Up @@ -414,6 +439,13 @@ union sui64_fp64 {
#define RVVLM_EXPM1DI_VSET_CONFIG "rvvlm_fp64m2.h"
#define RVVLM_EXPM1DI_STD_EPSIM rvvlm_expm1I

// FP64 expint1 function configuration
#define RVVLM_EXPINT1D_VSET_CONFIG "rvvlm_fp64m1.h"
#define RVVLM_EXPINT1D_STD rvvlm_expint1

#define RVVLM_EXPINT1DI_VSET_CONFIG "rvvlm_fp64m1.h"
#define RVVLM_EXPINT1DI_STD rvvlm_expint1I

// FP64 log function configuration
#define RVVLM_LOGD_VSET_CONFIG "rvvlm_fp64m2.h"
#define RVVLM_LOGD_TBL128 rvvlm_logD_tbl128
Expand Down Expand Up @@ -671,6 +703,10 @@ void RVVLM_EXPM1D_STD_EPSIM(size_t x_len, const double *x, double *y);
void RVVLM_EXPM1DI_STD_EPSIM(size_t x_len, const double *x, size_t stride_x,
double *y, size_t stride_y);

void RVVLM_EXPINT1D_STD(size_t x_len, const double *x, double *y);
void RVVLM_EXPINT1DI_STD(size_t x_len, const double *x, size_t stride_x,
double *y, size_t stride_y);

void RVVLM_LOGD_TBL128(size_t x_len, const double *x, double *y);
void RVVLM_LOGDI_TBL128(size_t x_len, const double *x, size_t stride_x,
double *y, size_t stride_y);
Expand Down
Loading

0 comments on commit 0a6c0c0

Please sign in to comment.