| 1 |
#include <arm_neon.h> |
| 2 |
#include "arm-neon-ref.h" |
| 3 |
#include "compute-ref-data.h" |
| 4 |
|
| 5 |
/* Expected results with negative input. */ |
| 6 |
VECT_VAR_DECL(expected_neg,uint,8,8) [] = { 0x0, 0x0, 0x0, 0x0, |
| 7 |
0x0, 0x0, 0x0, 0x0 }; |
| 8 |
VECT_VAR_DECL(expected_neg,uint,16,4) [] = { 0x0, 0x0, 0x0, 0x0 }; |
| 9 |
VECT_VAR_DECL(expected_neg,uint,32,2) [] = { 0x0, 0x0 }; |
| 10 |
|
| 11 |
/* Expected results with max input value shifted by 1. */ |
| 12 |
VECT_VAR_DECL(expected_max_sh1,uint,8,8) [] = { 0xff, 0xff, 0xff, 0xff, |
| 13 |
0xff, 0xff, 0xff, 0xff }; |
| 14 |
VECT_VAR_DECL(expected_max_sh1,uint,16,4) [] = { 0xffff, 0xffff, |
| 15 |
0xffff, 0xffff }; |
| 16 |
VECT_VAR_DECL(expected_max_sh1,uint,32,2) [] = { 0xffffffff, 0xffffffff }; |
| 17 |
VECT_VAR_DECL(expected_max_sh1,uint,64,1) [] = { 0x3333333333333333 }; |
| 18 |
|
| 19 |
/* Expected results with max input value shifted by max amount. */ |
| 20 |
VECT_VAR_DECL(expected_max_shmax,uint,8,8) [] = { 0x80, 0x80, 0x80, 0x80, |
| 21 |
0x80, 0x80, 0x80, 0x80 }; |
| 22 |
VECT_VAR_DECL(expected_max_shmax,uint,16,4) [] = { 0x8000, 0x8000, |
| 23 |
0x8000, 0x8000 }; |
| 24 |
VECT_VAR_DECL(expected_max_shmax,uint,32,2) [] = { 0x80000000, 0x80000000 }; |
| 25 |
|
| 26 |
/* Expected results with min input value shifted by max amount. */ |
| 27 |
VECT_VAR_DECL(expected_min_shmax,uint,8,8) [] = { 0x0, 0x0, 0x0, 0x0, |
| 28 |
0x0, 0x0, 0x0, 0x0 }; |
| 29 |
VECT_VAR_DECL(expected_min_shmax,uint,16,4) [] = { 0x0, 0x0, 0x0, 0x0 }; |
| 30 |
VECT_VAR_DECL(expected_min_shmax,uint,32,2) [] = { 0x0, 0x0 }; |
| 31 |
|
| 32 |
/* Expected results with inputs in usual range. */ |
| 33 |
VECT_VAR_DECL(expected,uint,8,8) [] = { 0x49, 0x49, 0x49, 0x49, |
| 34 |
0x49, 0x49, 0x49, 0x49 }; |
| 35 |
VECT_VAR_DECL(expected,uint,16,4) [] = { 0x0, 0x0, 0x0, 0x0 }; |
| 36 |
VECT_VAR_DECL(expected,uint,32,2) [] = { 0xdeadbf, 0xdeadbf }; |
| 37 |
|
| 38 |
#define INSN vqrshrun_n |
| 39 |
#define TEST_MSG "VQRSHRUN_N" |
| 40 |
|
| 41 |
#define FNNAME1(NAME) void exec_ ## NAME (void) |
| 42 |
#define FNNAME(NAME) FNNAME1(NAME) |
| 43 |
|
| 44 |
FNNAME (INSN) |
| 45 |
{ |
| 46 |
/* Basic test: y=vqrshrun_n(x,v), then store the result. */ |
| 47 |
#define TEST_VQRSHRUN_N2(INSN, T1, T2, W, W2, N, V, CMT) \ |
| 48 |
Set_Neon_Cumulative_Sat(0, VECT_VAR(vector_res, uint, W2, N)); \ |
| 49 |
VECT_VAR(vector_res, uint, W2, N) = \ |
| 50 |
INSN##_##T2##W(VECT_VAR(vector, T1, W, N), \ |
| 51 |
V); \ |
| 52 |
vst1_u##W2(VECT_VAR(result, uint, W2, N), \ |
| 53 |
VECT_VAR(vector_res, uint, W2, N)) |
| 54 |
|
| 55 |
/* Two auxliary macros are necessary to expand INSN */ |
| 56 |
#define TEST_VQRSHRUN_N1(INSN, T1, T2, W, W2, N, V, CMT) \ |
| 57 |
TEST_VQRSHRUN_N2(INSN, T1, T2, W, W2, N, V, CMT) |
| 58 |
|
| 59 |
#define TEST_VQRSHRUN_N(T1, T2, W, W2, N, V, CMT) \ |
| 60 |
TEST_VQRSHRUN_N1(INSN, T1, T2, W, W2, N, V, CMT) |
| 61 |
|
| 62 |
|
| 63 |
/* vector is twice as large as vector_res. */ |
| 64 |
DECL_VARIABLE(vector, int, 16, 8); |
| 65 |
DECL_VARIABLE(vector, int, 32, 4); |
| 66 |
DECL_VARIABLE(vector, int, 64, 2); |
| 67 |
|
| 68 |
DECL_VARIABLE(vector_res, uint, 8, 8); |
| 69 |
DECL_VARIABLE(vector_res, uint, 16, 4); |
| 70 |
DECL_VARIABLE(vector_res, uint, 32, 2); |
| 71 |
|
| 72 |
clean_results (); |
| 73 |
|
| 74 |
/* Fill input vector with negative values, to check saturation on |
| 75 |
limits. */ |
| 76 |
VDUP(vector, q, int, s, 16, 8, -2); |
| 77 |
VDUP(vector, q, int, s, 32, 4, -3); |
| 78 |
VDUP(vector, q, int, s, 64, 2, -4); |
| 79 |
|
| 80 |
/* Choose shift amount arbitrarily. */ |
| 81 |
#define CMT " (negative input)" |
| 82 |
TEST_VQRSHRUN_N(int, s, 16, 8, 8, 3, CMT); |
| 83 |
TEST_VQRSHRUN_N(int, s, 32, 16, 4, 4, CMT); |
| 84 |
TEST_VQRSHRUN_N(int, s, 64, 32, 2, 2, CMT); |
| 85 |
|
| 86 |
CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_neg, CMT); |
| 87 |
CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_neg, CMT); |
| 88 |
CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_neg, CMT); |
| 89 |
|
| 90 |
|
| 91 |
/* Fill input vector with max value, to check saturation on |
| 92 |
limits. */ |
| 93 |
VDUP(vector, q, int, s, 16, 8, 0x7FFF); |
| 94 |
VDUP(vector, q, int, s, 32, 4, 0x7FFFFFFF); |
| 95 |
VDUP(vector, q, int, s, 64, 2, 0x7FFFFFFFFFFFFFFFLL); |
| 96 |
|
| 97 |
/* shift by 1. */ |
| 98 |
#undef CMT |
| 99 |
#define CMT " (check cumulative saturation: shift by 1)" |
| 100 |
TEST_VQRSHRUN_N(int, s, 16, 8, 8, 1, CMT); |
| 101 |
TEST_VQRSHRUN_N(int, s, 32, 16, 4, 1, CMT); |
| 102 |
TEST_VQRSHRUN_N(int, s, 64, 32, 2, 1, CMT); |
| 103 |
|
| 104 |
CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_max_sh1, CMT); |
| 105 |
CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_max_sh1, CMT); |
| 106 |
CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_max_sh1, CMT); |
| 107 |
|
| 108 |
|
| 109 |
/* shift by max. */ |
| 110 |
#undef CMT |
| 111 |
#define CMT " (check cumulative saturation: shift by max, positive input)" |
| 112 |
TEST_VQRSHRUN_N(int, s, 16, 8, 8, 8, CMT); |
| 113 |
TEST_VQRSHRUN_N(int, s, 32, 16, 4, 16, CMT); |
| 114 |
TEST_VQRSHRUN_N(int, s, 64, 32, 2, 32, CMT); |
| 115 |
|
| 116 |
CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_max_shmax, CMT); |
| 117 |
CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_max_shmax, CMT); |
| 118 |
CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_max_shmax, CMT); |
| 119 |
|
| 120 |
|
| 121 |
/* Fill input vector with min value, to check saturation on limits. */ |
| 122 |
VDUP(vector, q, int, s, 16, 8, 0x8000); |
| 123 |
VDUP(vector, q, int, s, 32, 4, 0x80000000); |
| 124 |
VDUP(vector, q, int, s, 64, 2, 0x8000000000000000LL); |
| 125 |
|
| 126 |
/* shift by max */ |
| 127 |
#undef CMT |
| 128 |
#define CMT " (check cumulative saturation: shift by max, negative input)" |
| 129 |
TEST_VQRSHRUN_N(int, s, 16, 8, 8, 8, CMT); |
| 130 |
TEST_VQRSHRUN_N(int, s, 32, 16, 4, 16, CMT); |
| 131 |
TEST_VQRSHRUN_N(int, s, 64, 32, 2, 32, CMT); |
| 132 |
|
| 133 |
CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_min_shmax, CMT); |
| 134 |
CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_min_shmax, CMT); |
| 135 |
CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_min_shmax, CMT); |
| 136 |
|
| 137 |
|
| 138 |
/* Fill input vector with positive values, to check normal case. */ |
| 139 |
VDUP(vector, q, int, s, 16, 8, 0x1234); |
| 140 |
VDUP(vector, q, int, s, 32, 4, 0x87654321); |
| 141 |
VDUP(vector, q, int, s, 64, 2, 0xDEADBEEF); |
| 142 |
|
| 143 |
/* shift arbitrary amount. */ |
| 144 |
#undef CMT |
| 145 |
#define CMT "" |
| 146 |
TEST_VQRSHRUN_N(int, s, 16, 8, 8, 6, CMT); |
| 147 |
TEST_VQRSHRUN_N(int, s, 32, 16, 4, 7, CMT); |
| 148 |
TEST_VQRSHRUN_N(int, s, 64, 32, 2, 8, CMT); |
| 149 |
|
| 150 |
CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected, CMT); |
| 151 |
CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected, CMT); |
| 152 |
CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected, CMT); |
| 153 |
} |
| 154 |
|
| 155 |
int main (void) |
| 156 |
{ |
| 157 |
exec_vqrshrun_n (); |
| 158 |
return 0; |
| 159 |
} |