stackoverflow に質問を投稿するのはこれが初めてなので、質問やコードの書式設定で行った可能性のあるエラーを見逃さないようにしてください。しかし、私がもっと注意するように、同じことを私に指摘してください。
私は、2 つの 128 ビット (4 つの float 変数を含む) の数値を加算するための単純な組み込みルーチンをいくつか作成しようとしていました。ネット上でいくつかのコードを見つけ、それを自分のシステムで実行しようとしていました。コードは次のとおりです。
//this is a sample Intrinsics program to add two vectors.
#include <iostream>
#include <iomanip>
#include <xmmintrin.h>
#include <stdio.h>
using namespace std;
struct vector4 {
float x, y, z, w; };
//functions to operate on them.
vector4 set_vector(float x, float y, float z, float w = 0) {
vector4 temp;
temp.x = x;
temp.y = y;
temp.z = z;
temp.w = w;
return temp;
}
void print_vector(const vector4& v) {
cout << " This is the contents of vector: " << endl;
cout << " > vector.x = " << v.x << endl;
cout << " vector.y = " << v.y << endl;
cout << " vector.z = " << v.z << endl;
cout << " vector.w = " << v.w << endl;
}
vector4 sse_vector4_add(const vector4&a, const vector4& b) {
vector4 result;
asm volatile (
"movl $a, %eax" //move operands into registers.
"\n\tmovl $b, %ebx"
"\n\tmovups (%eax), xmm0" //move register contents into SSE registers.
"\n\tmovups (%ebx), xmm1"
"\n\taddps xmm0, xmm1" //add the elements. addps operates on single-precision vectors.
"\n\t movups xmm0, result" //move result into vector4 type data.
);
return result;
}
int main() {
vector4 a, b, result;
a = set_vector(1.1, 2.1, 3.2, 4.5);
b = set_vector(2.2, 4.2, 5.6);
result = sse_vector4_add(a, b);
print_vector(a);
print_vector(b);
print_vector(result);
return 0;
}
私が使用する g++ パラメータは次のとおりです。
g++ -Wall -pedantic -g -march=i386 -msse intrinsics_SSE_example.C -o h
私が得るエラーは次のとおりです。
intrinsics_SSE_example.C: Assembler messages:
intrinsics_SSE_example.C:45: Error: too many memory references for movups
intrinsics_SSE_example.C:46: Error: too many memory references for movups
intrinsics_SSE_example.C:47: Error: too many memory references for addps
intrinsics_SSE_example.C:48: Error: too many memory references for movups
これらのエラーをデバッグしたり、ググったりするのに多くの時間を費やしました。私は組み込み関数の完全な初心者なので、いくつかの重要なことを見落としている可能性があります。
どんな助けでも大歓迎です、
ありがとう、
Sriram。