c++ - 您如何将此“无符号整数”标量代码移植到“有符号整数”向量?
问题描述
我需要将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 最大值的一半(然后添加)?
解决方案
推荐阅读
- javascript - 依赖于其范围之外的变量的函数会导致 Javascript 中的内存泄漏?
- python - 让我的乌龟在遇到另一只乌龟时变大
- c - 以下 strncpy 调用的解释
- javascript - toLocaleString - 如果不是 .00,则仅显示小数
- java - 按表示项目位置的可空字段排序
- function - Azure Functional App 2.0 Sql 不支持错误
- redis - redis排序集中基于时间间隔的桶
- java - 为什么我可以实例化抽象类和接口的对象?构造函数中的 super 是什么?
- image-processing - 是否有一种视频格式,其彩色视频的大小是其灰度版本的三倍?
- java - 给定列名列表,如何选择数据集的多列?