Blame math/test-math-vector.h

Packit 6c4009
/* Common definitions for libm tests for vector functions.
Packit 6c4009
   Copyright (C) 2014-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#define TEST_MATHVEC 1
Packit 6c4009
#define TEST_NARROW 0
Packit 6c4009
#define TEST_FINITE 0
Packit 6c4009
#define TEST_ERRNO 0
Packit 6c4009
#define TEST_EXCEPTIONS 0
Packit 6c4009
Packit 6c4009
#define CNCT(x, y) x ## y
Packit 6c4009
#define CONCAT(a, b) CNCT (a, b)
Packit 6c4009
Packit 6c4009
#define WRAPPER_NAME(function) CONCAT (function, VEC_SUFF)
Packit 6c4009
#define FUNC_TEST(function) WRAPPER_NAME (FUNC (function))
Packit 6c4009
Packit 6c4009
/* This macro is used in VECTOR_WRAPPER macros for vector tests.  */
Packit 6c4009
#define TEST_VEC_LOOP(vec, len) 				\
Packit 6c4009
  do								\
Packit 6c4009
    {								\
Packit 6c4009
      for (i = 1; i < len; i++)					\
Packit 6c4009
        {							\
Packit 6c4009
          if ((FLOAT) vec[0] != (FLOAT) vec[i])			\
Packit 6c4009
            {							\
Packit 6c4009
              vec[0] = (FLOAT) vec[0] + 0.1;			\
Packit 6c4009
	      break;						\
Packit 6c4009
            }							\
Packit 6c4009
        }							\
Packit 6c4009
    }								\
Packit 6c4009
  while (0)
Packit 6c4009
Packit 6c4009
#define INIT_VEC_LOOP(vec, val, len)				\
Packit 6c4009
  do								\
Packit 6c4009
    {								\
Packit 6c4009
      for (i = 0; i < len; i++)					\
Packit 6c4009
        {							\
Packit 6c4009
          vec[i] = val;						\
Packit 6c4009
        }							\
Packit 6c4009
    }								\
Packit 6c4009
  while (0)
Packit 6c4009
Packit 6c4009
#define WRAPPER_DECL_f(function) extern FLOAT function (FLOAT);
Packit 6c4009
#define WRAPPER_DECL_ff(function) extern FLOAT function (FLOAT, FLOAT);
Packit 6c4009
#define WRAPPER_DECL_fFF(function) extern void function (FLOAT, FLOAT *, FLOAT *);
Packit 6c4009
Packit 6c4009
/* Wrapper from scalar to vector function.  */
Packit 6c4009
#define VECTOR_WRAPPER(scalar_func, vector_func) \
Packit 6c4009
extern VEC_TYPE vector_func (VEC_TYPE);		\
Packit 6c4009
FLOAT scalar_func (FLOAT x)			\
Packit 6c4009
{						\
Packit 6c4009
  int i;					\
Packit 6c4009
  VEC_TYPE mx;					\
Packit 6c4009
  INIT_VEC_LOOP (mx, x, VEC_LEN);		\
Packit 6c4009
  VEC_TYPE mr = vector_func (mx);		\
Packit 6c4009
  TEST_VEC_LOOP (mr, VEC_LEN);			\
Packit 6c4009
  return ((FLOAT) mr[0]);			\
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Wrapper from scalar 2 argument function to vector one.  */
Packit 6c4009
#define VECTOR_WRAPPER_ff(scalar_func, vector_func) 	\
Packit 6c4009
extern VEC_TYPE vector_func (VEC_TYPE, VEC_TYPE);	\
Packit 6c4009
FLOAT scalar_func (FLOAT x, FLOAT y)		\
Packit 6c4009
{						\
Packit 6c4009
  int i;					\
Packit 6c4009
  VEC_TYPE mx, my;				\
Packit 6c4009
  INIT_VEC_LOOP (mx, x, VEC_LEN);		\
Packit 6c4009
  INIT_VEC_LOOP (my, y, VEC_LEN);		\
Packit 6c4009
  VEC_TYPE mr = vector_func (mx, my);		\
Packit 6c4009
  TEST_VEC_LOOP (mr, VEC_LEN);			\
Packit 6c4009
  return ((FLOAT) mr[0]);			\
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Wrapper from scalar 3 argument function to vector one.  */
Packit 6c4009
#define VECTOR_WRAPPER_fFF(scalar_func, vector_func) 	\
Packit 6c4009
extern void vector_func (VEC_TYPE, VEC_TYPE *, VEC_TYPE *);	\
Packit 6c4009
void scalar_func (FLOAT x, FLOAT * r, FLOAT * r1)		\
Packit 6c4009
{						\
Packit 6c4009
  int i;					\
Packit 6c4009
  VEC_TYPE mx, mr, mr1;				\
Packit 6c4009
  INIT_VEC_LOOP (mx, x, VEC_LEN);		\
Packit 6c4009
  vector_func (mx, &mr, &mr1);			\
Packit 6c4009
  TEST_VEC_LOOP (mr, VEC_LEN);			\
Packit 6c4009
  TEST_VEC_LOOP (mr1, VEC_LEN);			\
Packit 6c4009
  *r = (FLOAT) mr[0];				\
Packit 6c4009
  *r1 = (FLOAT) mr1[0];				\
Packit 6c4009
  return;					\
Packit 6c4009
}