(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
vec-init-8.c
       1  /* { dg-do run } */
       2  /* { dg-require-effective-target vsx_hw } */
       3  /* { dg-options "-O2 -mvsx" } */
       4  
       5  #include <stdlib.h>
       6  #include <stddef.h>
       7  #include <altivec.h>
       8  
       9  #define ELEMENTS -1.0f, 2.0f, 0.0f, -1234.0f
      10  #define SPLAT 2345.0f
      11  
      12  vector float sv = (vector float) { ELEMENTS };
      13  vector float splat = (vector float) { SPLAT, SPLAT, SPLAT, SPLAT };
      14  vector float sv_global, sp_global;
      15  static vector float sv_static, sp_static;
      16  static const float expected[] = { ELEMENTS };
      17  
      18  extern void check (vector float a)
      19    __attribute__((__noinline__));
      20  
      21  extern void check_splat (vector float a)
      22    __attribute__((__noinline__));
      23  
      24  extern vector float pack_reg (float a, float b, float c, float d)
      25    __attribute__((__noinline__));
      26  
      27  extern vector float pack_from_ptr (float *p_a, float *p_b,
      28  				   float *p_c, float *p_d)
      29    __attribute__((__noinline__));
      30  
      31  extern vector float pack_const (void)
      32    __attribute__((__noinline__));
      33  
      34  extern void pack_ptr (vector float *p, float a, float b, float c, float d)
      35    __attribute__((__noinline__));
      36  
      37  extern void pack_static (float a, float b, float c, float d)
      38    __attribute__((__noinline__));
      39  
      40  extern void pack_global (float a, float b, float c, float d)
      41    __attribute__((__noinline__));
      42  
      43  extern vector float splat_reg (float a)
      44    __attribute__((__noinline__));
      45  
      46  extern vector float splat_from_ptr (float *p)
      47    __attribute__((__noinline__));
      48  
      49  extern vector float splat_const (void)
      50    __attribute__((__noinline__));
      51  
      52  extern void splat_ptr (vector float *p, float a)
      53    __attribute__((__noinline__));
      54  
      55  extern void splat_static (float a)
      56    __attribute__((__noinline__));
      57  
      58  extern void splat_global (float a)
      59    __attribute__((__noinline__));
      60  
      61  void
      62  check (vector float a)
      63  {
      64    size_t i;
      65  
      66    for (i = 0; i < 4; i++)
      67      if (vec_extract (a, i) != expected[i])
      68        abort ();
      69  }
      70  
      71  void
      72  check_splat (vector float a)
      73  {
      74    size_t i;
      75  
      76    for (i = 0; i < 4; i++)
      77      if (vec_extract (a, i) != SPLAT)
      78        abort ();
      79  }
      80  
      81  vector float
      82  pack_reg (float a, float b, float c, float d)
      83  {
      84    return (vector float) { a, b, c, d };
      85  }
      86  
      87  vector float
      88  pack_from_ptr (float *p_a, float *p_b, float *p_c, float *p_d)
      89  {
      90    return (vector float) { *p_a, *p_b, *p_c, *p_d };
      91  }
      92  
      93  vector float
      94  pack_const (void)
      95  {
      96    return (vector float) { ELEMENTS };
      97  }
      98  
      99  void
     100  pack_ptr (vector float *p, float a, float b, float c, float d)
     101  {
     102    *p = (vector float) { a, b, c, d };
     103  }
     104  
     105  void
     106  pack_static (float a, float b, float c, float d)
     107  {
     108    sv_static = (vector float) { a, b, c, d };
     109  }
     110  
     111  void
     112  pack_global (float a, float b, float c, float d)
     113  {
     114    sv_global = (vector float) { a, b, c, d };
     115  }
     116  
     117  vector float
     118  splat_reg (float a)
     119  {
     120    return (vector float) { a, a, a, a };
     121  }
     122  
     123  vector float
     124  splat_from_ptr (float *p)
     125  {
     126    return (vector float) { *p, *p, *p, *p };
     127  }
     128  
     129  vector float
     130  splat_const (void)
     131  {
     132    return (vector float) { SPLAT, SPLAT, SPLAT, SPLAT };
     133  }
     134  
     135  void
     136  splat_ptr (vector float *p, float a)
     137  {
     138    *p = (vector float) { a, a, a, a };
     139  }
     140  
     141  void
     142  splat_static (float a)
     143  {
     144    sp_static = (vector float) { a, a, a, a };
     145  }
     146  
     147  void
     148  splat_global (float a)
     149  {
     150    sp_global = (vector float) { a, a, a, a };
     151  }
     152  
     153  int main (void)
     154  {
     155    vector float sv2, sv3;
     156    float mem = SPLAT;
     157    float mem2[4] = { ELEMENTS };
     158  
     159    check (sv);
     160  
     161    check (pack_reg (ELEMENTS));
     162  
     163    check (pack_from_ptr (&mem2[0], &mem2[1], &mem2[2], &mem2[3]));
     164  
     165    check (pack_const ());
     166  
     167    pack_ptr (&sv2, ELEMENTS);
     168    check (sv2);
     169  
     170    pack_static (ELEMENTS);
     171    check (sv_static);
     172  
     173    pack_global (ELEMENTS);
     174    check (sv_global);
     175  
     176    check_splat (splat);
     177  
     178    check_splat (splat_reg (SPLAT));
     179  
     180    check_splat (splat_from_ptr (&mem));
     181  
     182    check_splat (splat_const ());
     183  
     184    splat_ptr (&sv2, SPLAT);
     185    check_splat (sv2);
     186  
     187    splat_static (SPLAT);
     188    check_splat (sp_static);
     189  
     190    splat_global (SPLAT);
     191    check_splat (sp_global);
     192  
     193    return 0;
     194  }