尝试使用std::aligned_storage与SSE和new
Trying to use std::aligned_storage with SSE and new
我想尝试在c++中使用SSE指令获得一些浮点数的平方根。但是当我试图存储结果时,我得到了一个异常。我可以像那样使用std::aligned_storage吗?
#include <iostream>
#include <type_traits>
#include <xmmintrin.h>
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<void*>(&values[i]);
float *fptr = static_cast<float*>(vptr);
for(int i = 0; i < 4; i++)
cin >> fptr[i];
}
for(int i = 0; i < N / 4; i++)
{
void *vptr = static_cast<void*>(&values[i]);
float *fptr = static_cast<float*>(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<void*>(&values[i]);
float *fptr = static_cast<float*>(vptr);
for(int i = 0; i < 4; i++)
cout << fptr[i] << endl;
}
delete[] values;
}
是aligned_storage<size, align>::type
。aligned_storage
本身只是一个元编程结构体。
另外,如果我没记错的话,new
只被评为std::max_align_t
,即使您new
设置了具有更高对齐要求的类型。
相关文章:
- C++ SSE 内部函数:将结果存储在变量中
- Azure Storage CPP & VCPKG
- C++应用程序缺少 winrt::Windows::Storage::Streams::D ataWriter
- thread_local "storage class specified"
- Constexpr and SSE intrinsics
- 如何使用SSE将__m128i注册乘以浮点因子?
- 使用SSE内部函数复制少量数据时出现问题
- 可以在 macOS 上启用的最低支持的 SSE 标志是什么?
- C++ 结构数组 - "This declaration has no storage class or type specifier"
- SSE 标志应该如何与现代 CMake 一起添加?
- 快速 SSE 射线 - 4 三角形交叉点
- 使用 SSE 以最快的速度缩小 8 位灰度图像
- 如何用SSE优化矩阵3乘3乘法与点?
- 使用双精度运算的快速 SSE 低精度指数
- 手动矢量化/SSE 用于 C++ 中的复杂问题
- 单精度矩阵运算的特征性能 AVX 与 SSE 没有区别?
- 编写 std::copysign 的可移植 SSE/AVX 版本
- SSE 内联汇编和可能的 g++ 优化错误
- SSE 整数 2^n 的 2 次方,对于没有 AVX2 的 32 位整数
- 带有SSE的有条件陈述