-
-
Save anonymous/bf9c81adea16e9cb8e027c17ac58da99 to your computer and use it in GitHub Desktop.
This file contains 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 <limits> | |
#include <iostream> | |
#include <immintrin.h> | |
#include <openssl/sha.h> | |
#pragma GCC target "avx2" | |
int main() | |
{ | |
constexpr std::uint32_t min_value = 0x00800000; | |
constexpr std::uint32_t stop_value = 0x7F800000; | |
auto value = _mm256_castsi256_ps(_mm256_setr_epi32( | |
min_value, min_value + 1, min_value + 2, min_value + 3, | |
min_value + 4, min_value + 5, min_value + 7, min_value + 8)); | |
const auto increment = _mm256_set1_epi32(8); | |
const auto final_value = _mm256_set1_epi32(stop_value); | |
const auto test_mask = _mm256_set1_epi8(-1); | |
SHA512_CTX sha_ctx; | |
SHA384_Init(&sha_ctx); | |
do { | |
alignas(32) float buffer[32]; | |
auto it = buffer; | |
_mm256_store_ps(it, _mm256_rsqrt_ps(value)); | |
it += 8; | |
value = _mm256_castsi256_ps( | |
_mm256_add_epi32(_mm256_castps_si256(value), increment)); | |
_mm256_store_ps(it, _mm256_rsqrt_ps(value)); | |
it += 8; | |
value = _mm256_castsi256_ps( | |
_mm256_add_epi32(_mm256_castps_si256(value), increment)); | |
_mm256_store_ps(it, _mm256_rsqrt_ps(value)); | |
it += 8; | |
value = _mm256_castsi256_ps( | |
_mm256_add_epi32(_mm256_castps_si256(value), increment)); | |
_mm256_store_ps(it, _mm256_rsqrt_ps(value)); | |
it += 8; | |
value = _mm256_castsi256_ps( | |
_mm256_add_epi32(_mm256_castps_si256(value), increment)); | |
SHA384_Update(&sha_ctx, buffer, sizeof(buffer)); | |
} while(_mm256_testz_si256( | |
_mm256_cmpeq_epi32(_mm256_castps_si256(value), final_value), | |
test_mask)); | |
unsigned char output[SHA384_DIGEST_LENGTH]; | |
SHA384_Final(output, &sha_ctx); | |
std::cout.setf(std::ios_base::hex, std::ios_base::basefield); | |
std::cout.fill('0'); | |
for(const auto& ch: output) { | |
std::cout.width(2); | |
std::cout << static_cast<unsigned>(ch); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment