Skip to content

Commit

Permalink
enhance test infra and testing; fixed 2 bugs caught by extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PingTakPeterTang committed Nov 6, 2024
1 parent deba355 commit 8e0b4b6
Show file tree
Hide file tree
Showing 20 changed files with 399 additions and 47 deletions.
4 changes: 3 additions & 1 deletion include/rvvlm_powD.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@
vy = __riscv_vfmin_mu(current_cases, vy, vy, 0x1.0p53, vlen); \
vy = __riscv_vfmax_mu(current_cases, vy, vy, -0x1.0p53, vlen); \
VINT y_to_int = __riscv_vfcvt_x(current_cases, vy, vlen); \
/* TODO: y_to_int_fp and y_is_int need to be used */ \
VFLOAT y_to_int_fp = __riscv_vfcvt_f(current_cases, y_to_int, vlen); \
VBOOL y_is_int = __riscv_vmfeq(current_cases, vy, y_to_int_fp, vlen); \
VINT sign_z = __riscv_vsll(y_to_int, 63, vlen); \
VINT zero; \
zero = __riscv_vxor(zero, zero, vlen); \
sign_z = __riscv_vmerge(zero, sign_z, y_is_int, vlen); \
/* the parity is used later on to manipulate sign, hence sll 63 bits \
*/ \
\
Expand Down
1 change: 1 addition & 0 deletions include/rvvlm_sinandcosD.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void F_VER1(API) {
VFLOAT S = __riscv_vfsub(r_hi, A, vlen);
VFLOAT s = __riscv_vfsub(r_hi, S, vlen);
s = __riscv_vfsub(s, A, vlen);
s = __riscv_vfsub(s, a, vlen);
s = __riscv_vfnmsac(s, PIBY2_LO, n_flt, vlen);
r = __riscv_vmerge(r, S, r_small, vlen);
r_delta = __riscv_vmerge(r_delta, s, r_small, vlen);
Expand Down
1 change: 1 addition & 0 deletions include/rvvlm_sincosD.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void F_VER1(API) {
VFLOAT S = __riscv_vfsub(r_hi, A, vlen);
VFLOAT s = __riscv_vfsub(r_hi, S, vlen);
s = __riscv_vfsub(s, A, vlen);
s = __riscv_vfsub(s, a, vlen);
s = __riscv_vfnmsac(s, PIBY2_LO, n_flt, vlen);
r = __riscv_vmerge(r, S, r_small, vlen);
r_delta = __riscv_vmerge(r_delta, s, r_small, vlen);
Expand Down
1 change: 1 addition & 0 deletions include/rvvlm_tanD.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void F_VER1(API) {
VFLOAT S = __riscv_vfsub(r_hi, A, vlen);
VFLOAT s = __riscv_vfsub(r_hi, S, vlen);
s = __riscv_vfsub(s, A, vlen);
s = __riscv_vfsub(s, a, vlen);
s = __riscv_vfnmsac(s, PIBY2_LO, n_flt, vlen);
r = __riscv_vmerge(r, S, r_small, vlen);
r_delta = __riscv_vmerge(r_delta, s, r_small, vlen);
Expand Down
71 changes: 71 additions & 0 deletions test/include/near_NPiby2_tbl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-FileCopyrightText: 2024 Rivos Inc.
//
// SPDX-License-Identifier: Apache-2.0

#define NB_TEST_ARGS 63*3
static const double dbl_near_NPiby2_tbl[NB_TEST_ARGS] = {
0x1.6c6cbc45dc8dep+9,0x1.6c6cbc45dc8dep+10,0x1.6c6cbc45dc8dep+11,
0x1.6c6cbc45dc8dep+12,0x1.635e3d74befcap+14,0x1.67e57cdd4dc54p+15,
0x1.65a1dd290660fp+16,0x1.bf9b3c6059d24p+17,0x1.39c6fd67805a7p+18,
0x1.39c6fd67805a7p+19,0x1.9eb7148f354d6p+20,0x1.9eb7148f354d6p+20,
0x1.d3ecce1f28274p+22,0x1.b951f1572eba5p+23,0x1.b951f1572eba5p+24,
0x1.b951f1572eba5p+25,0x1.b951f1572eba5p+26,0x1.b951f1572eba5p+27,
0x1.b951f1572eba5p+28,0x1.b951f1572eba5p+29,0x1.b951f1572eba5p+30,
0x1.b951f1572eba5p+31,0x1.5c9508c58aafap+32,0x1.5c9508c58aafap+32,
0x1.de5e5054e921bp+34,0x1.46546a5bd73ccp+35,0x1.46546a5bd73ccp+35,
0x1.46546a5bd73ccp+35,0x1.bb23eaa3db16dp+38,0x1.065c829d68730p+39,
0x1.065c829d68730p+39,0x1.065c829d68730p+39,0x1.065c829d68730p+39,
0x1.065c829d68730p+39,0x1.065c829d68730p+40,0x1.065c829d68730p+41,
0x1.f42d52c35675dp+46,0x1.7512069b7430dp+47,0x1.7512069b7430dp+48,
0x1.7512069b7430dp+49,0x1.44630cc2cad9dp+50,0x1.5cba89af1f855p+51,
0x1.5cba89af1f855p+52,0x1.56a4aa740a5a7p+53,0x1.59af9a1194efep+54,
0x1.59af9a1194efep+54,0x1.ae9608c734e12p+56,0x1.ae9608c734e12p+56,
0x1.c3cfa4749cdd7p+58,0x1.c3cfa4749cdd7p+59,0x1.c3cfa4749cdd7p+60,
0x1.c3cfa4749cdd7p+61,0x1.ed814f0220525p+62,0x1.ed814f0220525p+63,
0x1.a7f3bc5a7ed9ep+64,0x1.a7f3bc5a7ed9ep+64,0x1.a7f3bc5a7ed9ep+65,
0x1.782b7a20df6d4p+67,0x1.782b7a20df6d4p+67,0x1.782b7a20df6d4p+67,
0x1.782b7a20df6d4p+68,0x1.782b7a20df6d4p+69,0x1.782b7a20df6d4p+70,
0x1.782b7a20df6d4p+71,0x1.a4ffb379a019cp+74,0x1.308ab84507e83p+75,
0x1.99caa5236feeap+76,0x1.99caa5236feeap+76,0x1.99caa5236feeap+77,
0x1.99caa5236feeap+78,0x1.99caa5236feeap+79,0x1.e0664dbedfec5p+81,
0x1.e0664dbedfec5p+82,0x1.e0664dbedfec5p+83,0x1.e0664dbedfec5p+84,
0x1.f19e5d71b26bap+85,0x1.f19e5d71b26bap+85,0x1.f19e5d71b26bap+86,
0x1.f19e5d71b26bap+87,0x1.d4ab7990f194dp+89,0x1.66bd5424e5655p+90,
0x1.66bd5424e5655p+91,0x1.66bd5424e5655p+92,0x1.66bd5424e5655p+93,
0x1.66bd5424e5655p+94,0x1.c3dc1a597f202p+95,0x1.c3dc1a597f202p+95,
0x1.c3dc1a597f202p+96,0x1.e50fec1788957p+98,0x1.e50fec1788957p+99,
0x1.e50fec1788957p+100,0x1.e50fec1788957p+101,0x1.77d794c891d1cp+102,
0x1.dae3a00451b5fp+103,0x1.dae3a00451b5fp+104,0x1.1c6cc29b3b153p+105,
0x1.d99e1681eada0p+106,0x1.d99e1681eada0p+106,0x1.d99e1681eada0p+106,
0x1.d99e1681eada0p+106,0x1.d99e1681eada0p+106,0x1.d99e1681eada0p+106,
0x1.f8d36a8915598p+112,0x1.ae04fdb542be8p+113,0x1.ae04fdb542be8p+113,
0x1.ae04fdb542be8p+113,0x1.ae04fdb542be8p+113,0x1.ae04fdb542be8p+114,
0x1.ed82892c91569p+118,0x1.47623428452f0p+119,0x1.47623428452f0p+119,
0x1.47623428452f0p+119,0x1.f7e7a76e07787p+122,0x1.f7e7a76e07787p+123,
0x1.e7426933f5760p+124,0x1.e7426933f5760p+124,0x1.e7426933f5760p+124,
0x1.e7426933f5760p+124,0x1.e7426933f5760p+124,0x1.e7426933f5760p+124,
0x1.f91a847a07755p+130,0x1.504cac51f1eafp+131,0x1.504cac51f1eafp+132,
0x1.504cac51f1eafp+133,0x1.504cac51f1eafp+134,0x1.504cac51f1eafp+135,
0x1.504cac51f1eafp+136,0x1.8a56c23d2dfe0p+137,0x1.8a56c23d2dfe0p+137,
0x1.b2e25ce13d6a7p+139,0x1.e42d3528e32a3p+140,0x1.fcd2a14cb60a1p+141,
0x1.fcd2a14cb60a1p+142,0x1.5ad5a62cb1cc9p+143,0x1.5ad5a62cb1cc9p+144,
0x1.5ad5a62cb1cc9p+145,0x1.5ad5a62cb1cc9p+146,0x1.f1cdf37f20ff1p+147,
0x1.a651ccd5e965dp+148,0x1.a651ccd5e965dp+149,0x1.b930d680374c2p+150,
0x1.b930d680374c2p+150,0x1.b930d680374c2p+151,0x1.b930d680374c2p+152,
0x1.641bcd12e3311p+154,0x1.205a1c297f6b9p+155,0x1.205a1c297f6b9p+156,
0x1.205a1c297f6b9p+157,0x1.17e1e60c52f2ep+158,0x1.17e1e60c52f2ep+158,
0x1.ee076da427656p+160,0x1.82f4a9d83d2c2p+161,0x1.82f4a9d83d2c2p+161,
0x1.682ff8e5429ddp+163,0x1.682ff8e5429ddp+164,0x1.682ff8e5429ddp+165,
0x1.682ff8e5429ddp+166,0x1.cca7515e2585cp+167,0x1.cca7515e2585cp+167,
0x1.bdf4d57f7f0c4p+169,0x1.c54e136ed2490p+170,0x1.c54e136ed2490p+170,
0x1.c54e136ed2490p+170,0x1.fc218660d7c2fp+173,0x1.fc218660d7c2fp+174,
0x1.d28d5c4c5e73bp+175,0x1.d28d5c4c5e73bp+176,0x1.d28d5c4c5e73bp+177,
0x1.2722f5d698acep+178,0x1.2722f5d698acep+178,0x1.2722f5d698acep+179,
0x1.76e1ee2edd343p+181,0x1.0539b48d14c55p+182,0x1.0539b48d14c55p+183,
0x1.0539b48d14c55p+184,0x1.0539b48d14c55p+185,0x1.6014d4a7e0086p+186,
0x1.b5441ee104c98p+187,0x1.b5441ee104c98p+187,0x1.f7fd817cb39b5p+189,
0x1.f7fd817cb39b5p+190,0x1.bb4c8e40cbe5dp+191,0x1.bb4c8e40cbe5dp+192,
0x1.3ecf49b990c61p+193,0x1.0090a775f3363p+194,0x1.1faff897c1fe2p+195,
0x1.1faff897c1fe2p+195,0x1.e7e44a78ac18cp+197,0x1.e7e44a78ac18cp+197
};

62 changes: 60 additions & 2 deletions test/include/test_infra.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,53 @@

#include <stdio.h>

#define DBL_NEG_INF (int64_t)0xFFF0000000000000
#define DBL_NEG_GT1 (int64_t)0xBFF0000000000001
#define DBL_NEG_ONE (int64_t)0xBFF0000000000000
#define DBL_NEG_LT1 (int64_t)0xBFEFFFFFFFFFFFFF
#define DBL_NEG_TINY (int64_t)0x800FFFFFFFFFFFFF
#define DBL_NEG_ZERO (int64_t)0x8000000000000000
#define DBL_POS_ZERO (int64_t)0x0000000000000000
#define DBL_POS_TINY (int64_t)0x000FFFFFFFFFFFFF
#define DBL_POS_LT1 (int64_t)0x3FEFFFFFFFFFFFFF
#define DBL_POS_ONE (int64_t)0x3FF0000000000000
#define DBL_POS_GT1 (int64_t)0x3FF0000000000001
#define DBL_POS_INF (int64_t)0x7FF0000000000000
#define DBL_QNAN (int64_t)0x7FF8000000000000
#define DBL_SNAN (int64_t)0x7FF4000000000000

#define NB_TV_FOR_TRIG 4
#define TV_FOR_TRIG \
{DBL_QNAN, DBL_QNAN, DBL_SNAN, DBL_QNAN, \
DBL_NEG_INF, DBL_QNAN, DBL_POS_INF, DBL_QNAN}

#define NB_TV_FOR_EXP 4
#define TV_FOR_EXP \
{DBL_QNAN, DBL_QNAN, DBL_SNAN, DBL_QNAN, \
DBL_NEG_INF, DBL_POS_ZERO, DBL_POS_INF, DBL_POS_INF}

#define NB_TV_FOR_EXPM1 5
#define TV_FOR_EXPM1 \
{DBL_QNAN, DBL_QNAN, DBL_SNAN, DBL_QNAN, DBL_NEG_INF, \
DBL_NEG_ONE, DBL_POS_INF, DBL_POS_INF, DBL_POS_ZERO, DBL_POS_ZERO}

#define NB_TV_FOR_LOG 8
#define TV_FOR_LOG \
{DBL_QNAN, DBL_QNAN, DBL_SNAN, DBL_QNAN, \
DBL_NEG_INF, DBL_QNAN, DBL_NEG_GT1, DBL_QNAN, \
DBL_NEG_TINY, DBL_QNAN, DBL_NEG_ZERO, DBL_NEG_INF, \
DBL_POS_ZERO, DBL_NEG_INF, DBL_POS_INF, DBL_POS_INF}

#define NB_TV_FOR_LOG1P 7
#define TV_FOR_LOG1P \
{DBL_QNAN, DBL_QNAN, DBL_SNAN, DBL_QNAN, DBL_NEG_INF, \
DBL_QNAN, DBL_NEG_GT1, DBL_QNAN, DBL_NEG_ONE, DBL_NEG_INF, \
DBL_POS_ZERO, DBL_POS_ZERO, DBL_POS_INF, DBL_POS_INF}

#define COMMENT(comment) \
{ printf("\n=====\t" comment "\n"); }
{ \
printf("\n=====\t" comment "\n"); \
}

// Most common interface: testing on 1 interval
// for 1-in-1-out unit-stride function
Expand All @@ -20,8 +65,14 @@ void report_err_fp64(void (*test_func)(size_t, const double *, double *,
long double (*ref_func)(long double), int, double, double,
int, double = 1.0);

void report_err_fp64(void (*test_func)(size_t, const double *, double *,
double *),
long double (*ref_func)(long double), int, const double *,
int, double = 1.0);

void report_err_fp64(void (*test_func)(size_t, const double *, double *),
long double (*ref_func)(long double), const double *, int);
long double (*ref_func)(long double), const double *, int,
double = 1.0);

void report_mixederr_fp64(void (*test_func)(size_t, const double *, double *),
long double (*ref_func)(long double), double, double,
Expand Down Expand Up @@ -86,6 +137,13 @@ void show_special2_fp64(void (*test_func)(size_t, const double *,
const double *, double *),
int, char *);

void test_vectors_fp64(void (*test_func)(size_t, const double *, double *),
int64_t *, int);

void test_vectors2_fp64(void (*test_func)(size_t, const double *,
const double *, double *),
int64_t *, int, int);

void trig_2pi_reduction(long double, long double *, int64_t *);

long double acospil(long double);
Expand Down
14 changes: 12 additions & 2 deletions test/src/test_cos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@
#include "test_infra.h"

TEST(cos, special) {
int nb_tv;
int64_t tv_in_out[2 * (NB_TV_FOR_TRIG)] = TV_FOR_TRIG;

nb_tv = NB_TV_FOR_TRIG;

test_vectors_fp64(rvvlm_cos, tv_in_out, nb_tv);
}

TEST(cos, near_NPiby2) {
#include "near_NPiby2_tbl.h"
unsigned long nb_tests;
double x_start, x_end;

COMMENT("cos: current chosen algorithm; reduced argument in FP64 only")

show_special_fp64(rvvlm_cos, "Special Value handling of this function");
nb_tests = (NB_TEST_ARGS);
report_err_fp64(rvvlm_cos, cosl, dbl_near_NPiby2_tbl, nb_tests);
}

TEST(cos, small_args) {
Expand Down
11 changes: 9 additions & 2 deletions test/src/test_exp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
#include "rvvlm.h"
#include "test_infra.h"

TEST(exp, special) {
int nb_tv;
int64_t tv_in_out[2 * (NB_TV_FOR_EXP)] = TV_FOR_EXP;

nb_tv = NB_TV_FOR_EXP;

test_vectors_fp64(rvvlm_exp, tv_in_out, nb_tv);
}

TEST(exp, small_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("exp: current chosen algorithm; reduced argument in FP64 only")

show_special_fp64(rvvlm_exp, "Special Value handling of this function");

x_start = -0.34;
x_end = 0.34;
nb_tests = 100000;
Expand Down
11 changes: 9 additions & 2 deletions test/src/test_exp10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
#include "rvvlm.h"
#include "test_infra.h"

TEST(exp10, special) {
int nb_tv;
int64_t tv_in_out[2 * (NB_TV_FOR_EXP)] = TV_FOR_EXP;

nb_tv = NB_TV_FOR_EXP;

test_vectors_fp64(rvvlm_exp10, tv_in_out, nb_tv);
}

TEST(exp10, small_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("exp10: current chosen algorithm; reduced argument in FP64 only")

show_special_fp64(rvvlm_exp10, "Special Value handling of this function");

x_start = -0.34;
x_end = 0.34;
nb_tests = 30000;
Expand Down
11 changes: 9 additions & 2 deletions test/src/test_exp2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
#include "rvvlm.h"
#include "test_infra.h"

TEST(exp2, special) {
int nb_tv;
int64_t tv_in_out[2 * (NB_TV_FOR_EXP)] = TV_FOR_EXP;

nb_tv = NB_TV_FOR_EXP;

test_vectors_fp64(rvvlm_exp2, tv_in_out, nb_tv);
}

TEST(exp2, small_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("exp2: current chosen algorithm; reduced argument in FP64 only")

show_special_fp64(rvvlm_exp2, "Special Value handling of this function");

x_start = -0.34;
x_end = 0.34;
nb_tests = 80000;
Expand Down
11 changes: 9 additions & 2 deletions test/src/test_expm1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
#include "rvvlm.h"
#include "test_infra.h"

TEST(expm1, special) {
int nb_tv;
int64_t tv_in_out[2 * (NB_TV_FOR_EXPM1)] = TV_FOR_EXPM1;

nb_tv = NB_TV_FOR_EXPM1;

test_vectors_fp64(rvvlm_expm1, tv_in_out, nb_tv);
}

TEST(expm1, small_args) {
unsigned long nb_tests;
double x_start, x_end;

COMMENT("expm1: current chosen algorithm; reduced argument in FP64 only")

show_special_fp64(rvvlm_expm1, "Special Value handling of this function");

x_start = -0.01;
x_end = 0.01;
nb_tests = 30000;
Expand Down
Loading

0 comments on commit 8e0b4b6

Please sign in to comment.