问题描述
我需要将 Xorshift 算法从标量移植到矢量代码(SSE/SIMD
版本使用 -march=nocona
构建)。
我正在使用算法的 uint32_t 版本(直接取自 wiki):
#include <stdint.h>
struct xorshift32_state {
uint32_t a;
};
/* The state word must be initialized to non-zero */
uint32_t xorshift32(struct xorshift32_state *state)
{
/* Algorithm "xor" from p. 4 of Marsaglia,"Xorshift RNGs" */
uint32_t x = state->a;
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
return state->a = x;
}
主要问题是:
- 它使用 uint32,所以(按照标准)它会自动环绕
- 由于 SSE3 的“限制”,我会继续使用 m128i(我相信它已签署,并提供我需要的所有操作)
- 有符号溢出是 C++ 标准中未定义的行为
您将如何使用 SIMD 管理此移植?处理 epu32 并减去 uint32 最大值的一半(然后添加)?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)