はじめに..私はASMの経験が非常に限られており、SIMDの経験はさらに少ないです。
しかし、次のMMX / SSE最適化コードがあり、PPC/Cellプロセッサで使用するためにAltiVec命令に移植したいと思います。
これはおそらく大きな質問です。数行のコードですが、ここで何が起こっているのかを理解するのに問題はありませんでした。
元の機能:
static inline int convolve(const short *a, const short *b, int n)
{
int out = 0;
union {
__m64 m64;
int i32[2];
} tmp;
tmp.i32[0] = 0;
tmp.i32[1] = 0;
while (n >= 4) {
tmp.m64 = _mm_add_pi32(tmp.m64,
_mm_madd_pi16(*((__m64 *)a),
*((__m64 *)b)));
a += 4;
b += 4;
n -= 4;
}
out = tmp.i32[0] + tmp.i32[1];
_mm_empty();
while (n --)
out += (*(a++)) * (*(b++));
return out;
}
AltiVec命令を使用するためにこれを書き直す方法に関するヒントはありますか?
私の最初の試み(非常に間違った試み)は次のようになります。しかし、それは完全に(またはリモートでさえ)正しくありません。
static inline int convolve_altivec(const short *a, const short *b, int n)
{
int out = 0;
union {
vector unsigned int m128;
int i64[2];
} tmp;
vector unsigned int zero = {0, 0, 0, 0};
tmp.i64[0] = 0;
tmp.i64[1] = 0;
while (n >= 8) {
tmp.m128 = vec_add(tmp.m128,
vec_msum(*((vector unsigned short *)a),
*((vector unsigned short *)b), zero));
a += 8;
b += 8;
n -= 8;
}
out = tmp.i64[0] + tmp.i64[1];
#endif
while (n --)
out += (*(a++)) * (*(b++));
return out;
}