Christophe Lyon | 073831a | 2011-01-24 17:37:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | Copyright (c) 2009, 2010, 2011 STMicroelectronics |
| 4 | Written by Christophe Lyon |
| 5 | |
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | of this software and associated documentation files (the "Software"), to deal |
| 8 | in the Software without restriction, including without limitation the rights |
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | copies of the Software, and to permit persons to whom the Software is |
| 11 | furnished to do so, subject to the following conditions: |
| 12 | |
| 13 | The above copyright notice and this permission notice shall be included in |
| 14 | all copies or substantial portions of the Software. |
| 15 | |
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | THE SOFTWARE. |
| 23 | |
| 24 | */ |
| 25 | |
Christophe Lyon | 1775be0 | 2014-07-10 13:46:54 +0200 | [diff] [blame] | 26 | #if defined(__arm__) || defined(__aarch64__) |
Christophe Lyon | 073831a | 2011-01-24 17:37:40 +0100 | [diff] [blame] | 27 | #include <arm_neon.h> |
| 28 | #else |
Christophe Lyon | 0dab5f7 | 2011-07-19 17:14:09 +0200 | [diff] [blame] | 29 | #include "stm-arm-neon.h" |
Christophe Lyon | 073831a | 2011-01-24 17:37:40 +0100 | [diff] [blame] | 30 | #endif |
| 31 | |
| 32 | #include "stm-arm-neon-ref.h" |
Christophe Lyon | ae97a86 | 2011-09-23 11:24:43 +0200 | [diff] [blame] | 33 | #include <math.h> |
Christophe Lyon | 073831a | 2011-01-24 17:37:40 +0100 | [diff] [blame] | 34 | |
| 35 | #define TEST_MSG "VRSQRTS/VRSQRTSQ" |
| 36 | void exec_vrsqrts(void) |
| 37 | { |
| 38 | int i; |
| 39 | |
| 40 | /* Basic test: y=vrsqrts(x), then store the result. */ |
| 41 | #define TEST_VRSQRTS(Q, T1, T2, W, N) \ |
| 42 | VECT_VAR(vector_res, T1, W, N) = \ |
| 43 | vrsqrts##Q##_##T2##W(VECT_VAR(vector, T1, W, N), \ |
| 44 | VECT_VAR(vector2, T1, W, N)); \ |
| 45 | vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N), \ |
| 46 | VECT_VAR(vector_res, T1, W, N)) |
| 47 | |
| 48 | /* With ARM RVCT, we need to declare variables before any executable |
| 49 | statement */ |
| 50 | |
| 51 | /* No need for integer variants */ |
| 52 | DECL_VARIABLE(vector, float, 32, 2); |
| 53 | DECL_VARIABLE(vector, float, 32, 4); |
| 54 | |
| 55 | DECL_VARIABLE(vector2, float, 32, 2); |
| 56 | DECL_VARIABLE(vector2, float, 32, 4); |
| 57 | |
| 58 | DECL_VARIABLE(vector_res, float, 32, 2); |
| 59 | DECL_VARIABLE(vector_res, float, 32, 4); |
| 60 | |
| 61 | clean_results (); |
| 62 | |
| 63 | /* Choose init value arbitrarily */ |
Christophe Lyon | bd9ecf4 | 2011-07-19 16:30:50 +0200 | [diff] [blame] | 64 | TEST_VDUP(vector, , float, f, 32, 2, 12.9f); |
| 65 | TEST_VDUP(vector, q, float, f, 32, 4, 9.1f); |
Christophe Lyon | 073831a | 2011-01-24 17:37:40 +0100 | [diff] [blame] | 66 | |
Christophe Lyon | bd9ecf4 | 2011-07-19 16:30:50 +0200 | [diff] [blame] | 67 | TEST_VDUP(vector2, , float, f, 32, 2, 9.9f); |
| 68 | TEST_VDUP(vector2, q, float, f, 32, 4, 1.9f); |
Christophe Lyon | 073831a | 2011-01-24 17:37:40 +0100 | [diff] [blame] | 69 | |
| 70 | /* Apply the operator */ |
| 71 | TEST_VRSQRTS(, float, f, 32, 2); |
| 72 | TEST_VRSQRTS(q, float, f, 32, 4); |
| 73 | |
| 74 | fprintf (ref_file, "\n%s output:\n", TEST_MSG); |
Christophe Lyon | bf21826 | 2014-07-10 15:53:15 +0200 | [diff] [blame^] | 75 | fprintf (gcc_tests_file, "\n%s output:\n", TEST_MSG); |
Christophe Lyon | 073831a | 2011-01-24 17:37:40 +0100 | [diff] [blame] | 76 | DUMP_FP(TEST_MSG, float, 32, 2, PRIx32); |
| 77 | DUMP_FP(TEST_MSG, float, 32, 4, PRIx32); |
Christophe Lyon | ae97a86 | 2011-09-23 11:24:43 +0200 | [diff] [blame] | 78 | |
| 79 | |
| 80 | /* Test FP variants with special input values (NaN) */ |
| 81 | TEST_VDUP(vector, , float, f, 32, 2, NAN); |
| 82 | TEST_VDUP(vector2, q, float, f, 32, 4, NAN); |
| 83 | |
| 84 | /* Apply the operator */ |
| 85 | TEST_VRSQRTS(, float, f, 32, 2); |
| 86 | TEST_VRSQRTS(q, float, f, 32, 4); |
| 87 | |
| 88 | fprintf (ref_file, "\n%s output:\n", TEST_MSG " FP special (NAN) and normal values"); |
| 89 | DUMP_FP(TEST_MSG, float, 32, 2, PRIx32); |
| 90 | DUMP_FP(TEST_MSG, float, 32, 4, PRIx32); |
| 91 | |
| 92 | |
| 93 | /* Test FP variants with special input values (infinity, 0) */ |
| 94 | TEST_VDUP(vector, , float, f, 32, 2, HUGE_VALF); |
| 95 | TEST_VDUP(vector, q, float, f, 32, 4, 0.0f); |
| 96 | TEST_VDUP(vector2, q, float, f, 32, 4, 3.2f); /* Restore a normal value */ |
| 97 | |
| 98 | /* Apply the operator */ |
| 99 | TEST_VRSQRTS(, float, f, 32, 2); |
| 100 | TEST_VRSQRTS(q, float, f, 32, 4); |
| 101 | |
| 102 | fprintf (ref_file, "\n%s output:\n", TEST_MSG " FP special (infinity, 0) and normal values"); |
| 103 | DUMP_FP(TEST_MSG, float, 32, 2, PRIx32); |
| 104 | DUMP_FP(TEST_MSG, float, 32, 4, PRIx32); |
| 105 | |
| 106 | |
| 107 | /* Test FP variants with only special input values (infinity, 0) */ |
| 108 | TEST_VDUP(vector, , float, f, 32, 2, HUGE_VALF); |
| 109 | TEST_VDUP(vector, q, float, f, 32, 4, 0.0f); |
Christophe Lyon | c8aa0f6 | 2011-09-26 18:00:27 +0200 | [diff] [blame] | 110 | TEST_VDUP(vector2, , float, f, 32, 2, -0.0f); |
Christophe Lyon | ae97a86 | 2011-09-23 11:24:43 +0200 | [diff] [blame] | 111 | TEST_VDUP(vector2, q, float, f, 32, 4, HUGE_VALF); |
| 112 | |
| 113 | /* Apply the operator */ |
| 114 | TEST_VRSQRTS(, float, f, 32, 2); |
| 115 | TEST_VRSQRTS(q, float, f, 32, 4); |
| 116 | |
| 117 | fprintf (ref_file, "\n%s output:\n", TEST_MSG " FP special (infinity, 0)"); |
| 118 | DUMP_FP(TEST_MSG, float, 32, 2, PRIx32); |
| 119 | DUMP_FP(TEST_MSG, float, 32, 4, PRIx32); |
Christophe Lyon | 073831a | 2011-01-24 17:37:40 +0100 | [diff] [blame] | 120 | } |