我有一根绳子
const signed char From[] = {
0b00000000, 0b00000001, 0b00000010, 0b00000011,
0b00000100, 0b00000101, 0b00000110, 0b00000111,
0b00001000, 0b00001001, 0b00001010, 0b00001011,
0b00001100, 0b00001101, 0b00001110, 0b00001111,
};
我需要将此字符串中的字符放入 __m128i 向量中,然后将此向量中的字节存储到
std::uint32_t Schedule[4]
数组中
这样做:
const __m128i Chars = _mm_set_epi8 (
From[0],
From[1],
From[2],
From[3],
From[4],
From[5],
From[6],
From[7],
From[8],
From[9],
From[10],
From[11],
From[12],
From[13],
From[14],
From[15]
);
现在将此向量存储到 Schedule 中:
_mm_store_si128((__m128i*)&Schedule[Kter], SettedLines4);
我们在时间表中的字节顺序不正确(而且我认为这不是不正确的字节顺序。我认为位是混合的)
template<typename Type>
[[ nodiscard ]] std::string to_binary(Type Data) noexcept
{
std::string Result = "";
std::uint64_t CurrentBit = 8 * sizeof Data;
while(CurrentBit--)
Result += ((Data >> CurrentBit) & 1) == 0 ? "0" : "1";
return Result;
}
std::cout << to_binary(Schedule[0]) << std::endl;
std::cout << to_binary(Schedule[1]) << std::endl;
std::cout << to_binary(Schedule[2]) << std::endl;
std::cout << to_binary(Schedule[3]) << std::endl;
完整代码:
# include <x86intrin.h>
# include <iostream>
# include <cstdint>
template<typename Type>
[[ nodiscard ]] std::string to_binary(Type Data) noexcept
{
std::string Result = "";
std::uint64_t CurrentBit = 8 * sizeof Data;
while(CurrentBit--)
Result += ((Data >> CurrentBit) & 1) == 0 ? "0" : "1";
return Result;
}
int main(void)
{
std::uint32_t Schedule[4];
const signed char From[] = {
0b00000000, 0b00000001, 0b00000010, 0b00000011,
0b00000100, 0b00000101, 0b00000110, 0b00000111,
0b00001000, 0b00001001, 0b00001010, 0b00001011,
0b00001100, 0b00001101, 0b00001110, 0b00001111,
};
const __m128i v = _mm_set_epi8 (
From[0],
From[1],
From[2],
From[3],
From[4],
From[5],
From[6],
From[7],
From[8],
From[9],
From[10],
From[11],
From[12],
From[13],
From[14],
From[15]
);
_mm_store_si128((__m128i*)&Schedule[0], v);
std::cout << to_binary(Schedule[0]) << std::endl;
std::cout << to_binary(Schedule[1]) << std::endl;
std::cout << to_binary(Schedule[2]) << std::endl;
std::cout << to_binary(Schedule[0]) << std::endl;
}
我该如何修复它?我需要获得与预期相同的字节顺序
您的问题是
_mm_set_epi8
从最重要的参数开始。您需要 _mm_setr_epi8
或反转参数顺序