3

私は現在、GCC ベクトル拡張機能を試しています。sqrt(vec)とはいえ、期待通りの仕事に就くにはどうすればいいのだろう。

次のように:

typedef double v4d __attribute__ ((vector_size (16)));
v4d myfunc(v4d in)
{
    return some_sqrt(in);
}

少なくとも最近の x86 システムでは、関連する組み込み sqrtpd への呼び出しを発行します。ベクトル型で動作するsqrt用のGCCビルトインはありますか、それともこれを達成するために組み込みレベルにドロップダウンする必要がありますか?

4

3 に答える 3

0

バグのようです: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54408コンポーネントごとに行う以外の回避策はわかりません。いずれにしても、ベクトル拡張は、プラットフォーム固有の組み込み関数を置き換えることを意図したものではありません。

この趣旨のいくつかのファンキーなコード:

#include <cmath>

#include <utility>

template <::std::size_t...> struct indices { };

template <::std::size_t M, ::std::size_t... Is>
struct make_indices : make_indices<M - 1, M - 1, Is...> {};

template <::std::size_t... Is>
struct make_indices<0, Is...> : indices<Is...> {};

typedef float vec_type __attribute__ ((vector_size(4 * sizeof(float))));

template <::std::size_t ...Is>
vec_type sqrt_(vec_type const& v, indices<Is...> const)
{
  vec_type r;

  ::std::initializer_list<int>{(r[Is] = ::std::sqrt(v[Is]), 0)...};

  return r;
}

vec_type sqrt(vec_type const& v)
{
  return sqrt_(v, make_indices<4>());
}

int main()
{
  vec_type v;

  return sqrt(v)[0];
}

ベクター拡張とは別の自動ベクター化で運試しをすることもできます。

于 2013-10-22T16:28:36.250 に答える