(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
builtin-tgmath-3.c
       1  /* Test __builtin_tgmath: integer arguments with _FloatN / _FloatNx.  */
       2  /* { dg-do run } */
       3  /* { dg-options "" } */
       4  /* { dg-add-options float32 } */
       5  /* { dg-add-options float64 } */
       6  /* { dg-add-options float32x } */
       7  /* { dg-require-effective-target float32_runtime } */
       8  /* { dg-require-effective-target float64_runtime } */
       9  /* { dg-require-effective-target float32x_runtime } */
      10  
      11  extern void abort (void);
      12  extern void exit (int);
      13  
      14  #define CHECK_CALL(C, E, V)			\
      15    do						\
      16      {						\
      17        if ((C) != (E))				\
      18  	abort ();				\
      19        extern __typeof (C) V;			\
      20      }						\
      21    while (0)
      22  
      23  extern double var_d;
      24  extern _Float32 var_f32;
      25  extern _Float64 var_f64;
      26  extern _Float32x var_f32x;
      27  extern _Complex _Float32x var_cf32x;
      28  
      29  _Float32 t1f (float x) { return x + 1; }
      30  _Float32 t1d (double x) { return x + 2; }
      31  _Float32 t1l (long double x) { return x + 3; }
      32  _Float32 t1f64 (_Float64 x) { return x + 4; }
      33  
      34  #define t1v(x) __builtin_tgmath (t1f, t1d, t1l, t1f64, x)
      35  
      36  static void
      37  test_1 (void)
      38  {
      39    float f = 1;
      40    double d = 2;
      41    long double ld = 3;
      42    _Float64 f64 = 4;
      43    int i = 5;
      44    CHECK_CALL (t1v (f), 2, var_f32);
      45    CHECK_CALL (t1v (d), 4, var_f32);
      46    CHECK_CALL (t1v (ld), 6, var_f32);
      47    CHECK_CALL (t1v (f64), 8, var_f32);
      48    CHECK_CALL (t1v (i), 7, var_f32);
      49  }
      50  
      51  float t2f (float x, float y) { return 10 * x + y; }
      52  double t2d (double x, double y) { return 100 * x + y; }
      53  long double t2l (long double x, long double y) { return 1000 * x + y; }
      54  _Float32x t2f32x (_Float32x x, _Float32x y) { return 10000 * x + y; }
      55  _Float64 t2f64 (_Float64 x, _Float64 y) { return 100000 * x + y; }
      56  
      57  _Complex _Float32x
      58  ct2f32x (_Complex _Float32x x, _Complex _Float32x y)
      59  {
      60    return 1000000 * x + y;
      61  }
      62  
      63  #define t2v(x, y) __builtin_tgmath (t2f, t2d, t2l, t2f32x, t2f64, ct2f32x, x, y)
      64  
      65  static void
      66  test_2 (void)
      67  {
      68    double d = 3;
      69    _Float64 f64 = 6;
      70    _Float32x f32x = 7;
      71    int i = 5;
      72    _Complex _Float32x cf32x = 8;
      73    CHECK_CALL (t2v (f32x, i), 70005, var_f32x);
      74    CHECK_CALL (t2v (i, f32x), 50007, var_f32x);
      75    CHECK_CALL (t2v (f64, i), 600005, var_f64);
      76    CHECK_CALL (t2v (i, f64), 500006, var_f64);
      77    CHECK_CALL (t2v (d, i), 305, var_d);
      78    CHECK_CALL (t2v (i, d), 503, var_d);
      79    CHECK_CALL (t2v (cf32x, i), 8000005, var_cf32x);
      80    CHECK_CALL (t2v (i, cf32x), 5000008, var_cf32x);
      81  }
      82  
      83  int
      84  main (void)
      85  {
      86    test_1 ();
      87    test_2 ();
      88    exit (0);
      89  }