lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* Common definitions for libm tests for vector functions. |
| 2 | Copyright (C) 2014-2015 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #define TEST_MATHVEC 1 |
| 20 | |
| 21 | #define CNCT(x, y) x ## y |
| 22 | #define CONCAT(a, b) CNCT (a, b) |
| 23 | |
| 24 | #define WRAPPER_NAME(function) CONCAT (function, VEC_SUFF) |
| 25 | |
| 26 | /* This macro is used in VECTOR_WRAPPER macros for vector tests. */ |
| 27 | #define TEST_VEC_LOOP(vec, len) \ |
| 28 | do \ |
| 29 | { \ |
| 30 | for (i = 1; i < len; i++) \ |
| 31 | { \ |
| 32 | if ((FLOAT) vec[0] != (FLOAT) vec[i]) \ |
| 33 | { \ |
| 34 | vec[0] = (FLOAT) vec[0] + 0.1; \ |
| 35 | break; \ |
| 36 | } \ |
| 37 | } \ |
| 38 | } \ |
| 39 | while (0) |
| 40 | |
| 41 | #define INIT_VEC_LOOP(vec, val, len) \ |
| 42 | do \ |
| 43 | { \ |
| 44 | for (i = 0; i < len; i++) \ |
| 45 | { \ |
| 46 | vec[i] = val; \ |
| 47 | } \ |
| 48 | } \ |
| 49 | while (0) |
| 50 | |
| 51 | #define WRAPPER_DECL(function) extern FLOAT function (FLOAT); |
| 52 | #define WRAPPER_DECL_ff(function) extern FLOAT function (FLOAT, FLOAT); |
| 53 | #define WRAPPER_DECL_fFF(function) extern void function (FLOAT, FLOAT *, FLOAT *); |
| 54 | |
| 55 | /* Wrapper from scalar to vector function. */ |
| 56 | #define VECTOR_WRAPPER(scalar_func, vector_func) \ |
| 57 | extern VEC_TYPE vector_func (VEC_TYPE); \ |
| 58 | FLOAT scalar_func (FLOAT x) \ |
| 59 | { \ |
| 60 | int i; \ |
| 61 | VEC_TYPE mx; \ |
| 62 | INIT_VEC_LOOP (mx, x, VEC_LEN); \ |
| 63 | VEC_TYPE mr = vector_func (mx); \ |
| 64 | TEST_VEC_LOOP (mr, VEC_LEN); \ |
| 65 | return ((FLOAT) mr[0]); \ |
| 66 | } |
| 67 | |
| 68 | /* Wrapper from scalar 2 argument function to vector one. */ |
| 69 | #define VECTOR_WRAPPER_ff(scalar_func, vector_func) \ |
| 70 | extern VEC_TYPE vector_func (VEC_TYPE, VEC_TYPE); \ |
| 71 | FLOAT scalar_func (FLOAT x, FLOAT y) \ |
| 72 | { \ |
| 73 | int i; \ |
| 74 | VEC_TYPE mx, my; \ |
| 75 | INIT_VEC_LOOP (mx, x, VEC_LEN); \ |
| 76 | INIT_VEC_LOOP (my, y, VEC_LEN); \ |
| 77 | VEC_TYPE mr = vector_func (mx, my); \ |
| 78 | TEST_VEC_LOOP (mr, VEC_LEN); \ |
| 79 | return ((FLOAT) mr[0]); \ |
| 80 | } |
| 81 | |
| 82 | /* Wrapper from scalar 3 argument function to vector one. */ |
| 83 | #define VECTOR_WRAPPER_fFF(scalar_func, vector_func) \ |
| 84 | extern void vector_func (VEC_TYPE, VEC_TYPE *, VEC_TYPE *); \ |
| 85 | void scalar_func (FLOAT x, FLOAT * r, FLOAT * r1) \ |
| 86 | { \ |
| 87 | int i; \ |
| 88 | VEC_TYPE mx, mr, mr1; \ |
| 89 | INIT_VEC_LOOP (mx, x, VEC_LEN); \ |
| 90 | vector_func (mx, &mr, &mr1); \ |
| 91 | TEST_VEC_LOOP (mr, VEC_LEN); \ |
| 92 | TEST_VEC_LOOP (mr1, VEC_LEN); \ |
| 93 | *r = (FLOAT) mr[0]; \ |
| 94 | *r1 = (FLOAT) mr1[0]; \ |
| 95 | return; \ |
| 96 | } |