我有两个__m128i
s,a
并且b
,我想要洗牌,以便在64位a
的低位64位dst
和64位的高位b
落在64位的高位64位dst
.即
dst[ 0:63] = a[64:127]
dst[64:127] = b[0:63]
Run Code Online (Sandbox Code Playgroud)
相当于:
__m128i dst = _mm_unpacklo_epi64(_mm_srli_si128i(a, 8), b);
Run Code Online (Sandbox Code Playgroud)
要么
__m128i dst = _mm_castpd_si128(mm_shuffle_pd(_mm_castsi128_pd(a),_mm_castsi128_pd(b),1));
Run Code Online (Sandbox Code Playgroud)
有没有比第一种方法更好的方法呢?第二个只是一条指令,但切换到浮点SIMD执行比第一条指令的额外指令更昂贵.
当我将a unique_ptr<>
移入引发的函数中时,move -from指针不为空。这是正常现象吗?
这是两个显示该行为的测试程序。我可以在类的析构函数中观察到唯一的指针:
#include <memory>
#include <iostream>
void f(std::unique_ptr<int> &&) { throw "fail"; }
struct except_move_tester
{
std::unique_ptr<int> x;
except_move_tester()
: x(std::make_unique<int>(0))
{}
~except_move_tester() { std::cout << "x at destructor: " << x.get() << std::endl; }
void g()
{
std::cout << "x at g: " << x.get() << std::endl;
f(std::move(x));
}
};
int main()
{
try {
except_move_tester t;
t.g();
} catch (...) {}
}
Run Code Online (Sandbox Code Playgroud)
运行时给出的输出:
x at g: 0x7f818b402ac0
x at destructor: 0x7f818b402ac0
Run Code Online (Sandbox Code Playgroud)
如果我按如下方式修改上面的清单(只是在函数调用的位置添加了一个临时名称),那么我通常会期望得到异常安全行为:
#include <memory>
#include …
Run Code Online (Sandbox Code Playgroud)