SSE内在-_mm_and_ps奇数行为
SSE intrinsics - _mm_and_ps odd behaviour
以下代码:
__m128 a = _mm_setr_ps( 1, 2, 3, 4 );
__m128 b = _mm_set1_ps( 2 );
__m128 res = _mm_and_ps( a, b );
cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << endl;
cout << b[0] << " " << b[1] << " " << b[2] << " " << b[3] << endl;
cout << res[0] << " " << res[1] << " " << res[2] << " " << res[3] << endl;
cout<<endl;
cout << ( 1 & 2 ) << " " << ( 2 & 2 ) << " " << ( 3 & 2 ) << " " << ( 4 & 2 ) << endl;
导致:
1 2 3 4
2 2 2 2
0 2 2 2
0 2 2 0
SSE操作的结果不应该是0 2 2 0
,因为2 = 010, 4 = 100 => 2&4 = 0
。
根据文档:
__ m128 _mm_and_ps(__ m128 a,__m128 b)
计算a和b的四个SP fp值的位。
R0 R1 R2 R3
a0&amp;B0 A1&amp;B1 A2&amp;B2 A3&amp;B3
我发现的文档说:
计算a和b。
(我的重点)
2和4将具有相同的Mantissa(0,另外一个暗示的1位)和128和129的指数。位和这些是零mantissa,指数为128(== 2.0)。
编辑
如果您想做一点努力和非阴性整数,则可以添加一个偏移。如果您使用8388608的偏移(== 1&lt;&lt; 23),那么您可以按照您的期望在0..8388607上进行位置操作。
const float offset=8388608;
__m128 mm_offset = _mm_set1_ps();
__m128 a = _mm_setr_ps( 1, 2, 3, 4 );
a =_mm_add_ps(mm_offset,a);
__m128 b = _mm_set1_ps( 2+offset );
__m128 res = _mm_and_ps( a, b );
res = _mm_sub_ps(res,mm_offset);
相关文章:
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 为什么 Clang 不允许"and"作为函数名称?
- 位阵列上的快速AND运算
- 是否可以在 C++03 中定义'move-and-swap idiom'等效项
- BoostPython and CMake
- OpenSSL BIO and SSL_read
- Gurobi GRBModel and GRBmodel in C++
- std::visit and std::variant usage
- SHBrowseForFolder with BIF_BROWSEFORCOMPUTER and SHGetPathFr
- Directx12 and keystrokes
- different between int **arr =new int [ n]; and int a[i][j]?
- C++ getenv and setenv
- Inference pytorch C++ with alexnet and cv::imread image
- Visual Studio 2019 C++ and std::filesystem
- 保证逻辑 AND 表达式中的函数调用
- python ctypes and C++ pointers
- C++ const char with .begin() and .end()
- Threads with Classes and std::packaged_task
- libgphoto2 and Visual Studio 2019