(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
aarch64/
vdiv_f.c
       1  /* Test vdiv works correctly.  */
       2  /* { dg-do run } */
       3  /* { dg-options "-O3 --save-temps" } */
       4  
       5  #include <arm_neon.h>
       6  
       7  #define FLT_INFINITY (__builtin_inff ())
       8  #define DBL_INFINITY (__builtin_inf ())
       9  
      10  #define NAN (__builtin_nan (""))
      11  
      12  #define PI 3.141592653589793
      13  #define PI_4 0.7853981633974483
      14  #define SQRT2 1.4142135623730951
      15  #define SQRT1_2 0.7071067811865475
      16  
      17  #define TESTA0 PI
      18  #define TESTA1 -PI
      19  #define TESTA2 PI
      20  #define TESTA3 -PI
      21  #define TESTA4 1.0
      22  #define TESTA5 -1.0
      23  #define TESTA6 1.0
      24  #define TESTA7 -1.0
      25  /* 2^25+1, float has 24 significand bits
      26     according to Single-precision floating-point format.  */
      27  #define TESTA8_FLT 33554433
      28  /* 2^54+1, double has 53 significand bits
      29     according to Double-precision floating-point format.  */
      30  #define TESTA8_DBL 18014398509481985
      31  #define TESTA9 -TESTA8
      32  #define TESTA10 TESTA8
      33  #define TESTA11 -TESTA8
      34  #define TESTA12 NAN
      35  #define TESTA13 1.0
      36  #define TESTA14 INFINITY
      37  #define TESTA15 -INFINITY
      38  #define TESTA16 INFINITY
      39  #define TESTA17 9.0
      40  #define TESTA18 11.0
      41  #define TESTA19 13.0
      42  
      43  #define TESTB0 4.0
      44  #define TESTB1 4.0
      45  #define TESTB2 -4.0
      46  #define TESTB3 -4.0
      47  #define TESTB4 SQRT2
      48  #define TESTB5 SQRT2
      49  #define TESTB6 -SQRT2
      50  #define TESTB7 -SQRT2
      51  #define TESTB8 2.0
      52  #define TESTB9 2.0
      53  #define TESTB10 -2.0
      54  #define TESTB11 -2.0
      55  #define TESTB12 3.0
      56  #define TESTB13 NAN
      57  #define TESTB14 5.0
      58  #define TESTB15 7.0
      59  #define TESTB16 INFINITY
      60  #define TESTB17 INFINITY
      61  #define TESTB18 -INFINITY
      62  #define TESTB19 0
      63  
      64  #define ANSW0 PI_4
      65  #define ANSW1 -PI_4
      66  #define ANSW2 -PI_4
      67  #define ANSW3 PI_4
      68  #define ANSW4 SQRT1_2
      69  #define ANSW5 -SQRT1_2
      70  #define ANSW6 -SQRT1_2
      71  #define ANSW7 SQRT1_2
      72  #define ANSW8_FLT 16777216
      73  #define ANSW8_DBL 9007199254740992
      74  #define ANSW9 -ANSW8
      75  #define ANSW10 -ANSW8
      76  #define ANSW11 ANSW8
      77  #define ANSW12 NAN
      78  #define ANSW13 NAN
      79  #define ANSW14 INFINITY
      80  #define ANSW15 -INFINITY
      81  #define ANSW16 NAN
      82  #define ANSW17 0
      83  #define ANSW18 0
      84  #define ANSW19 INFINITY
      85  
      86  #define CONCAT(a, b) a##b
      87  #define CONCAT1(a, b) CONCAT (a, b)
      88  #define REG_INFEX64 _
      89  #define REG_INFEX128 q_
      90  #define REG_INFEX(reg_len) REG_INFEX##reg_len
      91  #define POSTFIX(reg_len, data_len) \
      92    CONCAT1 (REG_INFEX (reg_len), f##data_len)
      93  
      94  #define DATA_TYPE_32 float
      95  #define DATA_TYPE_64 double
      96  #define DATA_TYPE(data_len) DATA_TYPE_##data_len
      97  
      98  #define EPSILON_32 __FLT_EPSILON__
      99  #define EPSILON_64 __DBL_EPSILON__
     100  #define EPSILON(data_len) EPSILON_##data_len
     101  
     102  #define LOAD_INST(reg_len, data_len) \
     103    CONCAT1 (vld1, POSTFIX (reg_len, data_len))
     104  #define DIV_INST(reg_len, data_len) \
     105    CONCAT1 (vdiv, POSTFIX (reg_len, data_len))
     106  
     107  #define ABS(a) __builtin_fabs (a)
     108  #define ISNAN(a) __builtin_isnan (a)
     109  #define FP_equals(a, b, epsilon)			\
     110    (							\
     111     ((a) == (b))						\
     112      || (ISNAN (a) && ISNAN (b))				\
     113      || (ABS (a - b) < epsilon)				\
     114    )
     115  
     116  #define INHIB_OPTIMIZATION asm volatile ("" : : : "memory")
     117  
     118  #define RUN_TEST(a, b, c, testseta, testsetb, answset, count,		\
     119  		 reg_len, data_len, n)					\
     120  {									\
     121    int i;								\
     122    INHIB_OPTIMIZATION;							\
     123    (a) = LOAD_INST (reg_len, data_len) (testseta[count]);		\
     124    (b) = LOAD_INST (reg_len, data_len) (testsetb[count]);		\
     125    (c) = LOAD_INST (reg_len, data_len) (answset[count]);			\
     126    INHIB_OPTIMIZATION;							\
     127    (a) = DIV_INST (reg_len, data_len) (a, b);				\
     128    for (i = 0; i < n; i++)						\
     129    {									\
     130      INHIB_OPTIMIZATION;							\
     131      if (!FP_equals ((a) [i], (c) [i], EPSILON (data_len)))		\
     132        return 1;								\
     133    }									\
     134  }
     135  
     136  extern void abort (void);
     137  
     138  #define TESTA8 TESTA8_FLT
     139  #define ANSW8 ANSW8_FLT
     140  #define INFINITY FLT_INFINITY
     141  
     142  int
     143  test_vdiv_f32 ()
     144  {
     145    int count;
     146    float32x2_t a;
     147    float32x2_t b;
     148    float32x2_t c;
     149  
     150    float32_t testseta[10][2] = {
     151      { TESTA0, TESTA1 }, { TESTA2, TESTA3 },
     152      { TESTA4, TESTA5 }, { TESTA6, TESTA7 },
     153      { TESTA8, TESTA9 }, { TESTA10, TESTA11 },
     154      { TESTA12, TESTA13 }, { TESTA14, TESTA15 },
     155      { TESTA16, TESTA17 }, { TESTA18, TESTA19 }
     156    };
     157  
     158    float32_t testsetb[10][2] = {
     159      { TESTB0, TESTB1 }, { TESTB2, TESTB3 },
     160      { TESTB4, TESTB5 }, { TESTB6, TESTB7 },
     161      { TESTB8, TESTB9 }, { TESTB10, TESTB11 },
     162      { TESTB12, TESTB13 }, { TESTB14, TESTB15 },
     163      { TESTB16, TESTB17 }, { TESTB18, TESTB19 }
     164    };
     165  
     166    float32_t answset[10][2] = {
     167      { ANSW0, ANSW1 }, { ANSW2, ANSW3 },
     168      { ANSW4, ANSW5 }, { ANSW6, ANSW7 },
     169      { ANSW8, ANSW9 }, { ANSW10, ANSW11 },
     170      { ANSW12, ANSW13 }, { ANSW14, ANSW15 },
     171      { ANSW16, ANSW17 }, { ANSW18, ANSW19 }
     172    };
     173  
     174    for (count = 0; count < 10; count++)
     175      {
     176        RUN_TEST (a, b, c, testseta, testsetb, answset, count, 64, 32, 2);
     177      }
     178  
     179    return 0;
     180  }
     181  
     182  /* { dg-final { scan-assembler-times "fdiv\\tv\[0-9\]+\.2s, v\[0-9\]+\.2s, v\[0-9\]+\.2s" 1 } } */
     183  
     184  #undef TESTA8
     185  #undef ANSW8
     186  #undef INFINITY
     187  
     188  #define TESTA8 TESTA8_DBL
     189  #define ANSW8 ANSW8_DBL
     190  #define INFINITY DBL_INFINITY
     191  
     192  int
     193  test_vdiv_f64 ()
     194  {
     195    int count;
     196    float64x1_t a;
     197    float64x1_t b;
     198    float64x1_t c;
     199  
     200    float64_t testseta[20][1] = {
     201      { TESTA0 }, { TESTA1 }, { TESTA2 }, { TESTA3 },
     202      { TESTA4 }, { TESTA5 }, { TESTA6 }, { TESTA7 },
     203      { TESTA8 }, { TESTA9 }, { TESTA10 }, { TESTA11 },
     204      { TESTA12 }, { TESTA13 }, { TESTA14 }, { TESTA15 },
     205      { TESTA16 }, { TESTA17 }, { TESTA18 }, { TESTA19 }
     206    };
     207  
     208    float64_t testsetb[20][1] = {
     209      { TESTB0 }, { TESTB1 }, { TESTB2 }, { TESTB3 },
     210      { TESTB4 }, { TESTB5 }, { TESTB6 }, { TESTB7 },
     211      { TESTB8 }, { TESTB9 }, { TESTB10 }, { TESTB11 },
     212      { TESTB12 }, { TESTB13 }, { TESTB14 }, { TESTB15 },
     213      { TESTB16 }, { TESTB17 }, { TESTB18 }, { TESTB19 }
     214    };
     215  
     216    float64_t answset[20][1] = {
     217      { ANSW0 }, { ANSW1 }, { ANSW2 }, { ANSW3 },
     218      { ANSW4 }, { ANSW5 }, { ANSW6 }, { ANSW7 },
     219      { ANSW8 }, { ANSW9 }, { ANSW10 }, { ANSW11 },
     220      { ANSW12 }, { ANSW13 }, { ANSW14 }, { ANSW15 },
     221      { ANSW16 }, { ANSW17 }, { ANSW18 }, { ANSW19 }
     222    };
     223  
     224    for (count = 0; count < 20; count++)
     225      {
     226        RUN_TEST (a, b, c, testseta, testsetb, answset, count, 64, 64, 1);
     227      }
     228    return 0;
     229  }
     230  
     231  /* { dg-final { scan-assembler-times "fdiv\\td\[0-9\]+, d\[0-9\]+, d\[0-9\]+" 1 } } */
     232  
     233  #undef TESTA8
     234  #undef ANSW8
     235  #undef INFINITY
     236  
     237  #define TESTA8 TESTA8_FLT
     238  #define ANSW8 ANSW8_FLT
     239  #define INFINITY FLT_INFINITY
     240  
     241  int
     242  test_vdivq_f32 ()
     243  {
     244    int count;
     245    float32x4_t a;
     246    float32x4_t b;
     247    float32x4_t c;
     248  
     249    float32_t testseta[5][4] = {
     250      { TESTA0, TESTA1, TESTA2, TESTA3 },
     251      { TESTA4, TESTA5, TESTA6, TESTA7 },
     252      { TESTA8, TESTA9, TESTA10, TESTA11 },
     253      { TESTA12, TESTA13, TESTA14, TESTA15 },
     254      { TESTA16, TESTA17, TESTA18, TESTA19 }
     255    };
     256  
     257    float32_t testsetb[5][4] = {
     258      { TESTB0, TESTB1, TESTB2, TESTB3 },
     259      { TESTB4, TESTB5, TESTB6, TESTB7 },
     260      { TESTB8, TESTB9, TESTB10, TESTB11 },
     261      { TESTB12, TESTB13, TESTB14, TESTB15 },
     262      { TESTB16, TESTB17, TESTB18, TESTB19 }
     263    };
     264  
     265    float32_t answset[5][4] = {
     266      { ANSW0, ANSW1, ANSW2, ANSW3 },
     267      { ANSW4, ANSW5, ANSW6, ANSW7 },
     268      { ANSW8, ANSW9, ANSW10, ANSW11 },
     269      { ANSW12, ANSW13, ANSW14, ANSW15 },
     270      { ANSW16, ANSW17, ANSW18, ANSW19 }
     271    };
     272  
     273    for (count = 0; count < 5; count++)
     274      {
     275        RUN_TEST (a, b, c, testseta, testsetb, answset, count, 128, 32, 4);
     276      }
     277    return 0;
     278  }
     279  
     280  /* { dg-final { scan-assembler-times "fdiv\\tv\[0-9\]+\.4s, v\[0-9\]+\.4s, v\[0-9\]+\.4s" 1 } } */
     281  
     282  #undef TESTA8
     283  #undef ANSW8
     284  #undef INFINITY
     285  
     286  #define TESTA8 TESTA8_DBL
     287  #define ANSW8 ANSW8_DBL
     288  #define INFINITY DBL_INFINITY
     289  
     290  int
     291  test_vdivq_f64 ()
     292  {
     293    int count;
     294    float64x2_t a;
     295    float64x2_t b;
     296    float64x2_t c;
     297  
     298    float64_t testseta[10][2] = {
     299      { TESTA0, TESTA1 }, { TESTA2, TESTA3 },
     300      { TESTA4, TESTA5 }, { TESTA6, TESTA7 },
     301      { TESTA8, TESTA9 }, { TESTA10, TESTA11 },
     302      { TESTA12, TESTA13 }, { TESTA14, TESTA15 },
     303      { TESTA16, TESTA17 }, { TESTA18, TESTA19 }
     304    };
     305  
     306    float64_t testsetb[10][2] = {
     307      { TESTB0, TESTB1 }, { TESTB2, TESTB3 },
     308      { TESTB4, TESTB5 }, { TESTB6, TESTB7 },
     309      { TESTB8, TESTB9 }, { TESTB10, TESTB11 },
     310      { TESTB12, TESTB13 }, { TESTB14, TESTB15 },
     311      { TESTB16, TESTB17 }, { TESTB18, TESTB19 }
     312    };
     313  
     314    float64_t answset[10][2] = {
     315      { ANSW0, ANSW1 }, { ANSW2, ANSW3 },
     316      { ANSW4, ANSW5 }, { ANSW6, ANSW7 },
     317      { ANSW8, ANSW9 }, { ANSW10, ANSW11 },
     318      { ANSW12, ANSW13 }, { ANSW14, ANSW15 },
     319      { ANSW16, ANSW17 }, { ANSW18, ANSW19 }
     320    };
     321  
     322    for (count = 0; count < 10; count++)
     323      {
     324        RUN_TEST (a, b, c, testseta, testsetb, answset, count, 128, 64, 2);
     325      }
     326  
     327    return 0;
     328  }
     329  
     330  /* { dg-final { scan-assembler-times "fdiv\\tv\[0-9\]+\.2d, v\[0-9\]+\.2d, v\[0-9\]+\.2d" 1 } } */
     331  
     332  int
     333  main (int argc, char **argv)
     334  {
     335    if (test_vdiv_f32 ())
     336      abort ();
     337  
     338    if (test_vdiv_f64 ())
     339      abort ();
     340  
     341    if (test_vdivq_f32 ())
     342      abort ();
     343  
     344    if (test_vdivq_f64 ())
     345      abort ();
     346  
     347    return 0;
     348  }
     349