Skip to content

Commit

Permalink
Remove builtins.h, move clz() to where it is used
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Nov 9, 2021
1 parent 36be977 commit d0d5d4a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 46 deletions.
1 change: 0 additions & 1 deletion lib/ethash/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ set_target_properties(ethash PROPERTIES C_EXTENSIONS OFF CXX_EXTENSIONS OFF)
target_link_libraries(ethash PRIVATE ethash::keccak)
target_include_directories(ethash PUBLIC $<BUILD_INTERFACE:${include_dir}>$<INSTALL_INTERFACE:include>)
target_sources(ethash PRIVATE
builtins.h
endianness.hpp
${include_dir}/ethash/ethash.h
${include_dir}/ethash/ethash.hpp
Expand Down
43 changes: 0 additions & 43 deletions lib/ethash/builtins.h

This file was deleted.

19 changes: 17 additions & 2 deletions test/experimental/difficulty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
// Licensed under the Apache License, Version 2.0.

#include "difficulty.h"
#include "../../lib/ethash/builtins.h"
#include "../../lib/ethash/endianness.hpp"

#if defined(_MSC_VER) && !defined(__clang__)
#include <intrin.h>
#endif

#pragma clang diagnostic ignored "-Wunknown-sanitizers"

inline int clz(uint32_t x) noexcept
{
#if defined(_MSC_VER) && !defined(__clang__)
unsigned long most_significant_bit;
_BitScanReverse(&most_significant_bit, x);
return 31 - (int)most_significant_bit;
#else
return x != 0 ? __builtin_clz(x) : 32;
#endif
}


extern "C" {
NO_SANITIZE("unsigned-integer-overflow")
NO_SANITIZE("unsigned-shift-base")
Expand Down Expand Up @@ -40,7 +55,7 @@ ethash_hash256 ethash_difficulty_to_boundary(const ethash_hash256* difficulty) n

// Normalize d.
uint32_t dn[num_words];
const int shift = __builtin_clz(d[n - 1]);
const int shift = clz(d[n - 1]);
for (int i = n - 1; i > 0; i--)
dn[i] = shift ? (d[i] << shift) | (d[i - 1] >> (32 - shift)) : d[i];
dn[0] = d[0] << shift;
Expand Down

0 comments on commit d0d5d4a

Please sign in to comment.