这段代码改错#include "xmmintrin.h" #include <iostream> using namespace std; void main() { __declspec(align(16)) float Input1[4] = {1.0,2.0,3.0,4.0}; __declspec(align(16)) float Input2[4] = {5.0,6.0,7.0,8.0}; __declspec(align(16)) float Result[4]; __m128 a = _mm_load_ps(Input1); __m128 b = _mm_load_ps(Input2); __m128 c = _mm_add_ps(a,b); _mm_store_ps(Result,c); cout<<a.m128_f32[0]<<" "<<a.m128_f32[1]<<" " <<a.m128_f32[2]<<" "<<a.m128_f32[3]<<endl; cout<<b.m128_f32[0]<<" "<<b.m128_f32[1]<<" " <<b.m128_f32[2]<<" "<<b.m128_f32[3]<<endl; cout<<c.m128_f32[0]<<" "<<c.m128_f32[1]<<" " <<c.m128_f32[2]<<" "<<c.m128_f32[3]<<endl; for(int i=0;i<4;i++) { cout<<Result[i]<<" "; } cout<<endl; getchar(); }
时间: 2024-02-20 08:58:00 浏览: 109
这段代码需要做以下改动:
1. `void main()` 应改为 `int main()`,并在函数末尾返回一个整型值,例如 `return 0;`。
2. 头文件 `xmmintrin.h` 应放在头文件 `iostream` 之前。
3. 应在代码开头加入 `#include <cstdlib>`,以便使用 `getchar()` 函数。
修改后的代码如下所示:
```c++
#include <xmmintrin.h>
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
__declspec(align(16)) float Input1[4] = {1.0,2.0,3.0,4.0};
__declspec(align(16)) float Input2[4] = {5.0,6.0,7.0,8.0};
__declspec(align(16)) float Result[4];
__m128 a = _mm_load_ps(Input1);
__m128 b = _mm_load_ps(Input2);
__m128 c = _mm_add_ps(a,b);
_mm_store_ps(Result,c);
cout<<a.m128_f32[0]<<" "<<a.m128_f32[1]<<" " <<a.m128_f32[2]<<" "<<a.m128_f32[3]<<endl;
cout<<b.m128_f32[0]<<" "<<b.m128_f32[1]<<" " <<b.m128_f32[2]<<" "<<b.m128_f32[3]<<endl;
cout<<c.m128_f32[0]<<" "<<c.m128_f32[1]<<" " <<c.m128_f32[2]<<" "<<c.m128_f32[3]<<endl;
for(int i=0;i<4;i++) {
cout<<Result[i]<<" ";
}
cout<<endl;
getchar();
return 0;
}
```
阅读全文