33
33
//
34
34
// Functions with "test_" prefix will be called in run_single_test.
35
35
namespace NEON2RVV {
36
- // Forward declaration
36
+ static float ranf (float low, float high) {
37
+ float rand_float = (float )rand () / (float )RAND_MAX;
38
+ return rand_float * (high - low) + low;
39
+ }
40
+
41
+ #if defined(__riscv_v_elen)
42
+ #define REGISTER_SIZE __riscv_v_elen
43
+ #elif defined(__aarch64__)
44
+ #define REGISTER_SIZE 128
45
+ #endif
46
+
37
47
class NEON2RVV_TEST_IMPL : public NEON2RVV_TEST {
38
48
public:
39
- NEON2RVV_TEST_IMPL (void );
40
- result_t load_test_float_pointers (uint32_t i);
41
- result_t load_test_int_pointers (uint32_t i);
42
- result_t run_single_test (INSTRUCTION_TEST test, uint32_t i);
43
-
49
+ NEON2RVV_TEST_IMPL (void ) {
50
+ test_cases_float_pointer1 = (float *)platform_aligned_alloc (REGISTER_SIZE);
51
+ test_cases_float_pointer2 = (float *)platform_aligned_alloc (REGISTER_SIZE);
52
+ test_cases_int_pointer1 = (int32_t *)platform_aligned_alloc (REGISTER_SIZE);
53
+ test_cases_int_pointer2 = (int32_t *)platform_aligned_alloc (REGISTER_SIZE);
54
+ srand (0 );
55
+ for (uint32_t i = 0 ; i < MAX_TEST_VALUE; i++) {
56
+ test_cases_floats[i] = ranf (-100000 , 100000 );
57
+ test_cases_ints[i] = (int32_t )ranf (-100000 , 100000 );
58
+ }
59
+ }
44
60
float *test_cases_float_pointer1;
45
61
float *test_cases_float_pointer2;
46
62
int32_t *test_cases_int_pointer1;
@@ -54,18 +70,30 @@ class NEON2RVV_TEST_IMPL : public NEON2RVV_TEST {
54
70
platform_aligned_free (test_cases_int_pointer1);
55
71
platform_aligned_free (test_cases_int_pointer2);
56
72
}
73
+
74
+ void load_test_float_pointers (uint32_t iter) {
75
+ for (int i = 0 ; i < 4 ; i++) {
76
+ test_cases_float_pointer1[i] = test_cases_floats[iter + i];
77
+ test_cases_float_pointer2[i + 4 ] = test_cases_floats[iter + i + 4 ];
78
+ }
79
+ }
80
+ void load_test_int_pointers (uint32_t iter) {
81
+ for (int i = 0 ; i < 4 ; i++) {
82
+ test_cases_int_pointer1[i] = test_cases_ints[iter + i];
83
+ test_cases_int_pointer2[i + 4 ] = test_cases_ints[iter + i + 4 ];
84
+ }
85
+ }
86
+ result_t run_single_test (INSTRUCTION_TEST test, uint32_t iter);
87
+
57
88
virtual void release (void ) { delete this ; }
58
89
virtual result_t run_test (INSTRUCTION_TEST test) {
59
90
result_t ret = TEST_SUCCESS;
60
91
61
92
// Test a whole bunch of values
62
93
for (uint32_t i = 0 ; i < (MAX_TEST_VALUE - 8 ); i++) {
63
- ret = load_test_float_pointers (i); // Load some random float values
64
- if (ret == TEST_FAIL)
65
- break ; // load test float failed??
66
- ret = load_test_int_pointers (i); // load some random int values
67
- if (ret == TEST_FAIL)
68
- break ; // load test float failed??
94
+ load_test_float_pointers (i); // Load some random float values
95
+ load_test_int_pointers (i); // load some random int values
96
+
69
97
// If we are testing the reciprocal, then invert the input data
70
98
// (easier for debugging)
71
99
if (test == it_vrecps_f32 || test == it_vrecpsq_f32 || test == it_vrecpe_f32 || test == it_vrecpe_u32 ||
@@ -224,6 +252,11 @@ class NEON2RVV_TEST_IMPL : public NEON2RVV_TEST {
224
252
}
225
253
};
226
254
255
+ NEON2RVV_TEST *NEON2RVV_TEST::create (void ) {
256
+ NEON2RVV_TEST_IMPL *st = new NEON2RVV_TEST_IMPL;
257
+ return static_cast <NEON2RVV_TEST *>(st);
258
+ }
259
+
227
260
const char *instruction_string[] = {
228
261
#define _ (x ) #x,
229
262
INTRIN_LIST
@@ -295,13 +328,6 @@ static inline double bankers_rounding(double val) {
295
328
return ret;
296
329
}
297
330
298
- static float ranf (void ) {
299
- uint32_t ir = rand () & 0x7FFF ;
300
- return (float )ir * (1 .0f / 32768 .0f );
301
- }
302
-
303
- static float ranf (float low, float high) { return ranf () * (high - low) + low; }
304
-
305
331
result_t test_vadd_s8 (const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
306
332
const int8_t *_a = (int8_t *)impl.test_cases_int_pointer1 ;
307
333
const int8_t *_b = (int8_t *)impl.test_cases_int_pointer2 ;
@@ -4317,47 +4343,13 @@ result_t test_vsudotq_laneq_s32(const NEON2RVV_TEST_IMPL &impl, uint32_t iter) {
4317
4343
// Dummy function to match the case label in run_single_test.
4318
4344
result_t test_last (const NEON2RVV_TEST_IMPL &impl, uint32_t iter) { return TEST_SUCCESS; }
4319
4345
4320
- #if defined(__riscv_v_elen)
4321
- #define REGISTER_SIZE __riscv_v_elen
4322
- #elif defined(__aarch64__)
4323
- #define REGISTER_SIZE 128
4324
- #endif
4325
-
4326
- NEON2RVV_TEST_IMPL::NEON2RVV_TEST_IMPL (void ) {
4327
- test_cases_float_pointer1 = (float *)platform_aligned_alloc (REGISTER_SIZE);
4328
- test_cases_float_pointer2 = (float *)platform_aligned_alloc (REGISTER_SIZE);
4329
- test_cases_int_pointer1 = (int32_t *)platform_aligned_alloc (REGISTER_SIZE);
4330
- test_cases_int_pointer2 = (int32_t *)platform_aligned_alloc (REGISTER_SIZE);
4331
- srand (0 );
4332
- for (uint32_t i = 0 ; i < MAX_TEST_VALUE; i++) {
4333
- test_cases_floats[i] = ranf (-100000 , 100000 );
4334
- test_cases_ints[i] = (int32_t )ranf (-100000 , 100000 );
4335
- }
4336
- }
4337
-
4338
- result_t NEON2RVV_TEST_IMPL::load_test_float_pointers (uint32_t i) {
4339
- for (int i = 0 ; i < 4 ; i++) {
4340
- test_cases_float_pointer1[i] = test_cases_floats[i];
4341
- test_cases_float_pointer2[i + 4 ] = test_cases_floats[i + 4 ];
4342
- }
4343
- return TEST_SUCCESS;
4344
- }
4345
-
4346
- result_t NEON2RVV_TEST_IMPL::load_test_int_pointers (uint32_t i) {
4347
- for (int i = 0 ; i < 4 ; i++) {
4348
- test_cases_int_pointer1[i] = test_cases_ints[i];
4349
- test_cases_int_pointer2[i + 4 ] = test_cases_ints[i + 4 ];
4350
- }
4351
- return TEST_SUCCESS;
4352
- }
4353
-
4354
- result_t NEON2RVV_TEST_IMPL::run_single_test (INSTRUCTION_TEST test, uint32_t i) {
4346
+ result_t NEON2RVV_TEST_IMPL::run_single_test (INSTRUCTION_TEST test, uint32_t iter) {
4355
4347
result_t ret = TEST_SUCCESS;
4356
4348
4357
4349
switch (test) {
4358
- #define _ (x ) \
4359
- case it_##x: \
4360
- ret = test_##x (*this , i ); \
4350
+ #define _ (x ) \
4351
+ case it_##x: \
4352
+ ret = test_##x (*this , iter ); \
4361
4353
break ;
4362
4354
INTRIN_LIST
4363
4355
#undef _
@@ -4366,9 +4358,4 @@ result_t NEON2RVV_TEST_IMPL::run_single_test(INSTRUCTION_TEST test, uint32_t i)
4366
4358
return ret;
4367
4359
}
4368
4360
4369
- NEON2RVV_TEST *NEON2RVV_TEST::create (void ) {
4370
- NEON2RVV_TEST_IMPL *st = new NEON2RVV_TEST_IMPL;
4371
- return static_cast <NEON2RVV_TEST *>(st);
4372
- }
4373
-
4374
4361
} // namespace NEON2RVV
0 commit comments