(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
torture/
builtin-symmetric-1.c
       1  /* Copyright (C) 2006  Free Software Foundation.
       2  
       3     Verify that built-in math function folding of symmetric even and
       4     odd functions is correctly performed by the compiler.
       5  
       6     Origin: Kaveh R. Ghazi,  November 09, 2006.  */
       7  
       8  /* { dg-do link } */
       9  /* { dg-options "-ffast-math" } */
      10  /* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
      11  
      12  /* All references to link_error should go away at compile-time.  */
      13  extern void link_error(int);
      14  
      15  /* Test that FUNC(-ARG) == FUNC(ARG).  */
      16  #define TESTIT_EVEN(FUNC) do { \
      17    if (__builtin_##FUNC##f(-xf) != __builtin_##FUNC##f(xf)) \
      18      link_error(__LINE__); \
      19    if (__builtin_##FUNC(-x) != __builtin_##FUNC(x)) \
      20      link_error(__LINE__); \
      21    if (__builtin_##FUNC##l(-xl) != __builtin_##FUNC##l(xl)) \
      22      link_error(__LINE__); \
      23    } while (0)
      24  
      25  /* Test that FUNC(-ARG) == FUNC(ARG), where ARG has a complex type.  */
      26  #define TESTIT_EVEN_C(FUNC) do { \
      27    if (__builtin_##FUNC##f(-cxf) != __builtin_##FUNC##f(cxf)) \
      28      link_error(__LINE__); \
      29    if (__builtin_##FUNC(-cx) != __builtin_##FUNC(cx)) \
      30      link_error(__LINE__); \
      31    if (__builtin_##FUNC##l(-cxl) != __builtin_##FUNC##l(cxl)) \
      32      link_error(__LINE__); \
      33    } while (0)
      34  
      35  /* Test that FUNC(-VAR) == FUNC(VAR), where VAR has an int type.  */
      36  #define TESTIT_EVEN_I(FUNC,VAR) do { \
      37    if (__builtin_##FUNC(-VAR) != __builtin_##FUNC(VAR)) \
      38      link_error(__LINE__); \
      39    } while (0)
      40  
      41  /* Test that -FUNC(ARG) == FUNC(-ARG).  */
      42  #define TESTIT_ODD(FUNC) do { \
      43    if (-__builtin_##FUNC##f(-xf) != __builtin_##FUNC##f(xf)) \
      44      link_error(__LINE__); \
      45    if (-__builtin_##FUNC(-x) != __builtin_##FUNC(x)) \
      46      link_error(__LINE__); \
      47    if (-__builtin_##FUNC##l(-xl) != __builtin_##FUNC##l(xl)) \
      48      link_error(__LINE__); \
      49    } while (0)
      50  
      51  /* Test that -FUNC(ARG) == FUNC(-ARG), where ARG has a complex type.  */
      52  #define TESTIT_ODD_C(FUNC) do { \
      53    if (-__builtin_##FUNC##f(-cxf) != __builtin_##FUNC##f(cxf)) \
      54      link_error(__LINE__); \
      55    if (-__builtin_##FUNC(-cx) != __builtin_##FUNC(cx)) \
      56      link_error(__LINE__); \
      57    if (-__builtin_##FUNC##l(-cxl) != __builtin_##FUNC##l(cxl)) \
      58      link_error(__LINE__); \
      59    } while (0)
      60  
      61  void foo (float xf, double x, long double xl,
      62  	  __complex__ float cxf, __complex__ double cx, __complex__ long double cxl,
      63  	  int i, long l, long long ll, __INTMAX_TYPE__ im)
      64  {
      65    TESTIT_EVEN(cos);
      66    TESTIT_EVEN(cosh);
      67    TESTIT_EVEN(fabs);
      68  
      69    TESTIT_EVEN_C(ccos);
      70    TESTIT_EVEN_C(ccosh);
      71    TESTIT_EVEN_C(cabs);
      72  
      73    TESTIT_EVEN_I(abs, i);
      74    TESTIT_EVEN_I(imaxabs, im);
      75    TESTIT_EVEN_I(labs, l);
      76    TESTIT_EVEN_I(llabs, ll);
      77  
      78    TESTIT_ODD(asin);
      79    TESTIT_ODD(asinh);
      80    TESTIT_ODD(atan);
      81    TESTIT_ODD(atanh);
      82    TESTIT_ODD(cbrt);
      83    TESTIT_ODD(erf);
      84    TESTIT_ODD(llrint);
      85    TESTIT_ODD(llround);
      86    TESTIT_ODD(lrint);
      87    TESTIT_ODD(lround);
      88    TESTIT_ODD(nearbyint);
      89    TESTIT_ODD(rint);
      90    TESTIT_ODD(round);
      91    TESTIT_ODD(sin);
      92    TESTIT_ODD(sinh);
      93    TESTIT_ODD(tan);
      94    TESTIT_ODD(tanh);
      95    TESTIT_ODD(trunc);
      96  
      97    TESTIT_ODD_C(casin);
      98    TESTIT_ODD_C(casinh);
      99    TESTIT_ODD_C(catan);
     100    TESTIT_ODD_C(catanh);
     101    TESTIT_ODD_C(cproj);
     102    TESTIT_ODD_C(csin);
     103    TESTIT_ODD_C(csinh);
     104    TESTIT_ODD_C(ctan);
     105    TESTIT_ODD_C(ctanh);
     106  }
     107  
     108  int main()
     109  {
     110    foo (1,1,1,1,1,1,1,1,1,1);
     111    return 0;
     112  }