test-math-vector.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Common definitions for libm tests for vector functions.
  2. Copyright (C) 2014-2016 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_FINITE 0
  17. #define TEST_ERRNO 0
  18. #define CNCT(x, y) x ## y
  19. #define CONCAT(a, b) CNCT (a, b)
  20. #define WRAPPER_NAME(function) CONCAT (function, VEC_SUFF)
  21. /* This macro is used in VECTOR_WRAPPER macros for vector tests. */
  22. #define TEST_VEC_LOOP(vec, len) \
  23. do \
  24. { \
  25. for (i = 1; i < len; i++) \
  26. { \
  27. if ((FLOAT) vec[0] != (FLOAT) vec[i]) \
  28. { \
  29. vec[0] = (FLOAT) vec[0] + 0.1; \
  30. break; \
  31. } \
  32. } \
  33. } \
  34. while (0)
  35. #define INIT_VEC_LOOP(vec, val, len) \
  36. do \
  37. { \
  38. for (i = 0; i < len; i++) \
  39. { \
  40. vec[i] = val; \
  41. } \
  42. } \
  43. while (0)
  44. #define WRAPPER_DECL(function) extern FLOAT function (FLOAT);
  45. #define WRAPPER_DECL_ff(function) extern FLOAT function (FLOAT, FLOAT);
  46. #define WRAPPER_DECL_fFF(function) extern void function (FLOAT, FLOAT *, FLOAT *);
  47. /* Wrapper from scalar to vector function. */
  48. #define VECTOR_WRAPPER(scalar_func, vector_func) \
  49. extern VEC_TYPE vector_func (VEC_TYPE); \
  50. FLOAT scalar_func (FLOAT x) \
  51. { \
  52. int i; \
  53. VEC_TYPE mx; \
  54. INIT_VEC_LOOP (mx, x, VEC_LEN); \
  55. VEC_TYPE mr = vector_func (mx); \
  56. TEST_VEC_LOOP (mr, VEC_LEN); \
  57. return ((FLOAT) mr[0]); \
  58. }
  59. /* Wrapper from scalar 2 argument function to vector one. */
  60. #define VECTOR_WRAPPER_ff(scalar_func, vector_func) \
  61. extern VEC_TYPE vector_func (VEC_TYPE, VEC_TYPE); \
  62. FLOAT scalar_func (FLOAT x, FLOAT y) \
  63. { \
  64. int i; \
  65. VEC_TYPE mx, my; \
  66. INIT_VEC_LOOP (mx, x, VEC_LEN); \
  67. INIT_VEC_LOOP (my, y, VEC_LEN); \
  68. VEC_TYPE mr = vector_func (mx, my); \
  69. TEST_VEC_LOOP (mr, VEC_LEN); \
  70. return ((FLOAT) mr[0]); \
  71. }
  72. /* Wrapper from scalar 3 argument function to vector one. */
  73. #define VECTOR_WRAPPER_fFF(scalar_func, vector_func) \
  74. extern void vector_func (VEC_TYPE, VEC_TYPE *, VEC_TYPE *); \
  75. void scalar_func (FLOAT x, FLOAT * r, FLOAT * r1) \
  76. { \
  77. int i; \
  78. VEC_TYPE mx, mr, mr1; \
  79. INIT_VEC_LOOP (mx, x, VEC_LEN); \
  80. vector_func (mx, &mr, &mr1); \
  81. TEST_VEC_LOOP (mr, VEC_LEN); \
  82. TEST_VEC_LOOP (mr1, VEC_LEN); \
  83. *r = (FLOAT) mr[0]; \
  84. *r1 = (FLOAT) mr1[0]; \
  85. return; \
  86. }