我想尝试使用C++中的SSE instrincs来获取一些浮点数的平方根.但是当我尝试存储结果时,我得到一个例外.我可以像这样使用std :: aligned_storage吗?
#include#include #include using namespace std; using float_storage = aligned_storage<4 * sizeof(float), 16>; int main() { int N; cin >> N; float_storage * values = new float_storage[ N / 4 ]; // 4 floats in pack for(int i = 0; i < N / 4; i++) { void *vptr = static_cast (&values[i]); float *fptr = static_cast (vptr); for(int i = 0; i < 4; i++) cin >> fptr[i]; } for(int i = 0; i < N / 4; i++) { void *vptr = static_cast (&values[i]); float *fptr = static_cast (vptr); __m128 x = _mm_loadu_ps(fptr); x = _mm_sqrt_ps(x); _mm_store_ps(fptr, x); // im getting an crash here } for(int i = 0; i < N / 4; i++) { void *vptr = static_cast (&values[i]); float *fptr = static_cast (vptr); for(int i = 0; i < 4; i++) cout << fptr[i] << endl; } delete[] values; }
Puppy.. 6
是的aligned_storage
.aligned_storage
本身只是一个元编程结构.
此外,如果我没记错的话,即使您使用具有更高对齐要求的类型,new
也仅被评定为.std::max_align_t
new
是的aligned_storage<size, align>::type
.aligned_storage
本身只是一个元编程结构.
此外,如果我没记错的话,即使您使用具有更高对齐要求的类型,new
也仅被评定为.std::max_align_t
new