test-math-vector.h 3.2 KB

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