(root)/
gcc-13.2.0/
libstdc++-v3/
testsuite/
experimental/
simd/
tests/
bits/
make_vec.h
       1  // Copyright (C) 2020-2023 Free Software Foundation, Inc.
       2  //
       3  // This file is part of the GNU ISO C++ Library.  This library is free
       4  // software; you can redistribute it and/or modify it under the
       5  // terms of the GNU General Public License as published by the
       6  // Free Software Foundation; either version 3, or (at your option)
       7  // any later version.
       8  //
       9  // This library is distributed in the hope that it will be useful,
      10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12  // GNU General Public License for more details.
      13  //
      14  // You should have received a copy of the GNU General Public License along
      15  // with this library; see the file COPYING3.  If not see
      16  // <http://www.gnu.org/licenses/>.
      17  
      18  #ifndef SIMD_TESTS_BITS_MAKE_VEC_H_
      19  #define SIMD_TESTS_BITS_MAKE_VEC_H_
      20  #include <experimental/simd>
      21  
      22  template <class M>
      23    inline M
      24    make_mask(const std::initializer_list<bool> &init)
      25    {
      26      std::size_t i = 0;
      27      M r = {};
      28      for (;;)
      29        {
      30  	for (bool x : init)
      31  	  {
      32  	    r[i] = x;
      33  	    if (++i == M::size())
      34  	      {
      35  		return r;
      36  	      }
      37  	  }
      38        }
      39    }
      40  
      41  template <class M>
      42    M
      43    make_alternating_mask()
      44    {
      45      return make_mask<M>({false, true});
      46    }
      47  
      48  template <class V>
      49    inline V
      50    make_vec(const std::initializer_list<typename V::value_type> &init,
      51  	   typename V::value_type inc = 0)
      52    {
      53      std::size_t i = 0;
      54      V r = {};
      55      typename V::value_type base = 0;
      56      for (;;)
      57        {
      58  	for (auto x : init)
      59  	  {
      60  	    r[i] = base + x;
      61  	    if (++i == V::size())
      62  	      {
      63  		return r;
      64  	      }
      65  	  }
      66  	base += inc;
      67        }
      68    }
      69  #endif  // SIMD_TESTS_BITS_MAKE_VEC_H_