Last active
May 28, 2019 23:09
-
-
Save Wunkolo/58c694b0d7f653cd99ffdcbc3d968b25 to your computer and use it in GitHub Desktop.
Fun with pclmulqdq(carryless multiply)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <cstdio> | |
#include <bitset> | |
#include <immintrin.h> | |
int main() | |
{ | |
const std::uint64_t Bits | |
= 0b00011000100000000001000000000010000000001000000100000001000000001; | |
std::puts(("Bits:\t"+std::bitset<64>(Bits).to_string()).c_str()); | |
const __m128i Result = _mm_clmulepi64_si128( | |
_mm_set_epi64x(0, Bits), | |
_mm_set1_epi8(0xFF), | |
0 | |
); | |
const std::uint64_t Lo = _mm_cvtsi128_si64(Result); | |
const std::uint64_t Hi = _mm_extract_epi64(Result,1); | |
std::puts(("Lo:\t"+std::bitset<64>(Lo).to_string()).c_str()); | |
std::puts(("Hi:\t"+std::bitset<64>(Hi).to_string()).c_str()); | |
// Bit mask odds(mask odd set bits) | |
std::puts(("BMO:\t"+std::bitset<64>(~(Hi) & Bits).to_string()).c_str()); | |
// Bit mask evens(mask even set bits) | |
std::puts(("BME:\t"+std::bitset<64>(~(Lo) & Bits).to_string()).c_str()); | |
// Bit scan odd parity ranges(exclusive) | |
std::puts(("BSOP:\t"+std::bitset<64>((~Bits) & Lo).to_string()).c_str()); | |
// Bit scan even parity ranges(exclusive) | |
std::puts(("BSEP:\t"+std::bitset<64>((~Bits) & Hi).to_string()).c_str()); | |
} | |
// Bits: 0011000100000000001000000000010000000001000000100000001000000001 | |
// Lo: 1110111100000000000111111111110000000000111111100000000111111111 | |
// Hi: 0001000011111111111000000000001111111111000000011111111000000000 | |
// BMO: 0010000100000000000000000000010000000000000000100000000000000001 | |
// BME: 0001000000000000001000000000000000000001000000000000001000000000 | |
// BSOP: 1100111000000000000111111111100000000000111111000000000111111110 | |
// BSEP: 0000000011111111110000000000001111111110000000011111110000000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment