Replace with consteval
It doesn't makes any sense to use this implementation at runtime.
This commit is contained in:
parent
327d93a6a4
commit
d068e68e75
2 changed files with 40 additions and 40 deletions
|
@ -24,18 +24,18 @@
|
|||
|
||||
namespace dhandy::bt {
|
||||
struct HashType {
|
||||
constexpr HashType ( uint64_t parA, uint64_t parB, uint64_t parC ) :
|
||||
consteval HashType ( uint64_t parA, uint64_t parB, uint64_t parC ) :
|
||||
a(parA), b(parB), c(parC)
|
||||
{
|
||||
}
|
||||
constexpr HashType ( uint64_t parAP, uint64_t parA, uint64_t parBP, uint64_t parB, uint64_t parCP, uint64_t parC ) :
|
||||
consteval HashType ( uint64_t parAP, uint64_t parA, uint64_t parBP, uint64_t parB, uint64_t parCP, uint64_t parC ) :
|
||||
a(0 == parAP ? parA : (0 == parBP ? parB : (0 == parCP ? parC : throw 0))),
|
||||
b(1 == parAP ? parA : (1 == parBP ? parB : (1 == parCP ? parC : throw 0))),
|
||||
c(2 == parAP ? parA : (2 == parBP ? parB : (2 == parCP ? parC : throw 0)))
|
||||
{
|
||||
}
|
||||
constexpr HashType ( const HashType& ) = default;
|
||||
constexpr uint64_t operator[] ( uint64_t parIndex ) const {
|
||||
consteval HashType ( const HashType& ) = default;
|
||||
consteval uint64_t operator[] ( uint64_t parIndex ) const {
|
||||
return (parIndex == 0 ? a :
|
||||
(parIndex == 1 ? b :
|
||||
(parIndex == 2 ? c : throw 0)
|
||||
|
@ -52,7 +52,7 @@ namespace dhandy::bt {
|
|||
inline const constexpr char TigerPaddingV2 = 0x80;
|
||||
|
||||
[[gnu::const]]
|
||||
constexpr HashType tiger ( const char* parStr, uint64_t parLen, char parPad );
|
||||
consteval HashType tiger ( const char* parStr, uint64_t parLen, char parPad );
|
||||
} //namespace dhandy::bt
|
||||
|
||||
#include "tiger_bt.inl"
|
||||
|
|
|
@ -280,7 +280,7 @@ namespace dhandy::bt {
|
|||
0xCB0C0708705A36A3ULL, 0xE74D14754F986044ULL, 0xCD56D9430EA8280EULL, 0xC12591D7535F5065ULL,
|
||||
0xC83223F1720AEF96ULL, 0xC3A0396F7363A51FULL };
|
||||
|
||||
constexpr uint64_t buff_to_uint64_with_filling (const char* parStr, const uint64_t parAvailLen) {
|
||||
consteval uint64_t buff_to_uint64_with_filling (const char* parStr, const uint64_t parAvailLen) {
|
||||
return (
|
||||
parAvailLen == 0 ?
|
||||
0
|
||||
|
@ -291,7 +291,7 @@ namespace dhandy::bt {
|
|||
);
|
||||
}
|
||||
|
||||
constexpr uint64_t buff_to_uint64_fill_ifn (const char* parStr, uint64_t parIndex, uint64_t parBuffLen, char parPad) {
|
||||
consteval uint64_t buff_to_uint64_fill_ifn (const char* parStr, uint64_t parIndex, uint64_t parBuffLen, char parPad) {
|
||||
return (sizeof(uint64_t) * parIndex >= parBuffLen ?
|
||||
(sizeof(uint64_t) * parIndex == parBuffLen ?
|
||||
static_cast<uint64_t>(static_cast<uint8_t>(parPad))
|
||||
|
@ -309,7 +309,7 @@ namespace dhandy::bt {
|
|||
}
|
||||
|
||||
struct TigerBlock {
|
||||
constexpr explicit TigerBlock ( const char* parStr ) :
|
||||
consteval explicit TigerBlock ( const char* parStr ) :
|
||||
data{
|
||||
buff_to_uint64_with_filling(parStr + sizeof(uint64_t) * 0, sizeof(uint64_t)),
|
||||
buff_to_uint64_with_filling(parStr + sizeof(uint64_t) * 1, sizeof(uint64_t)),
|
||||
|
@ -322,12 +322,12 @@ namespace dhandy::bt {
|
|||
}
|
||||
{
|
||||
}
|
||||
constexpr TigerBlock ( const TigerBlock& ) = default;
|
||||
constexpr TigerBlock ( uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e, uint64_t f, uint64_t g, uint64_t h) :
|
||||
consteval TigerBlock ( const TigerBlock& ) = default;
|
||||
consteval TigerBlock ( uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e, uint64_t f, uint64_t g, uint64_t h) :
|
||||
data{a, b, c, d, e, f, g, h}
|
||||
{
|
||||
}
|
||||
constexpr TigerBlock ( const char* parStr, uint64_t parLen, char parPad ) :
|
||||
consteval TigerBlock ( const char* parStr, uint64_t parLen, char parPad ) :
|
||||
data{
|
||||
buff_to_uint64_fill_ifn(parStr, 0, parLen, parPad),
|
||||
buff_to_uint64_fill_ifn(parStr, 1, parLen, parPad),
|
||||
|
@ -340,7 +340,7 @@ namespace dhandy::bt {
|
|||
}
|
||||
{
|
||||
}
|
||||
constexpr TigerBlock ( const char* parStr, uint64_t parLen, char parPad, uint64_t parData7 ) :
|
||||
consteval TigerBlock ( const char* parStr, uint64_t parLen, char parPad, uint64_t parData7 ) :
|
||||
data{
|
||||
buff_to_uint64_fill_ifn(parStr, 0, parLen, parPad),
|
||||
buff_to_uint64_fill_ifn(parStr, 1, parLen, parPad),
|
||||
|
@ -354,16 +354,16 @@ namespace dhandy::bt {
|
|||
{
|
||||
}
|
||||
|
||||
constexpr uint64_t operator[] (std::size_t parIndex) const { return (parIndex < lengthof(data) ? data[parIndex] : throw 0); }
|
||||
consteval uint64_t operator[] (std::size_t parIndex) const { return (parIndex < lengthof(data) ? data[parIndex] : throw 0); }
|
||||
|
||||
const uint64_t data[8];
|
||||
};
|
||||
|
||||
constexpr uint64_t gb (uint64_t r, uint64_t a) {
|
||||
consteval uint64_t gb (uint64_t r, uint64_t a) {
|
||||
return (r >> (a * CHAR_BIT)) bitand 0xff;
|
||||
}
|
||||
|
||||
constexpr HashType round (uint64_t mul, uint64_t a, uint64_t b, uint64_t c, uint64_t x, const TigerBlock& block, const HashType& hash) {
|
||||
consteval HashType round (uint64_t mul, uint64_t a, uint64_t b, uint64_t c, uint64_t x, const TigerBlock& block, const HashType& hash) {
|
||||
return HashType(
|
||||
a,
|
||||
hash[a] - (
|
||||
|
@ -382,7 +382,7 @@ namespace dhandy::bt {
|
|||
);
|
||||
}
|
||||
|
||||
constexpr HashType pass (uint64_t a, uint64_t b, uint64_t c, uint64_t mul, const TigerBlock& block, const HashType& hash, uint64_t x=0) {
|
||||
consteval HashType pass (uint64_t a, uint64_t b, uint64_t c, uint64_t mul, const TigerBlock& block, const HashType& hash, uint64_t x=0) {
|
||||
return (
|
||||
8 == x ?
|
||||
//if 0 == x
|
||||
|
@ -400,25 +400,25 @@ namespace dhandy::bt {
|
|||
);
|
||||
}
|
||||
|
||||
template <uint64_t I, uint64_t S> constexpr uint64_t key_sched_op (const TigerBlock& i);
|
||||
template<> constexpr uint64_t key_sched_op<0,1> (const TigerBlock& i) { return i[0] - (i[7] ^ 0xA5A5A5A5A5A5A5A5ULL); }
|
||||
template<> constexpr uint64_t key_sched_op<1,1> (const TigerBlock& i) { return i[1] ^ key_sched_op<0,1>(i); }
|
||||
template<> constexpr uint64_t key_sched_op<2,1> (const TigerBlock& i) { return i[2] + key_sched_op<1,1>(i); }
|
||||
template<> constexpr uint64_t key_sched_op<3,1> (const TigerBlock& i) { return i[3] - (key_sched_op<2,1>(i) ^ ((~key_sched_op<1,1>(i)) << 19)); }
|
||||
template<> constexpr uint64_t key_sched_op<4,1> (const TigerBlock& i) { return i[4] ^ key_sched_op<3,1>(i); }
|
||||
template<> constexpr uint64_t key_sched_op<5,1> (const TigerBlock& i) { return i[5] + key_sched_op<4,1>(i); }
|
||||
template<> constexpr uint64_t key_sched_op<6,1> (const TigerBlock& i) { return i[6] - (key_sched_op<5,1>(i) ^ ((~key_sched_op<4,1>(i)) >> 23)); }
|
||||
template<> constexpr uint64_t key_sched_op<7,1> (const TigerBlock& i) { return i[7] ^ key_sched_op<6,1>(i); }
|
||||
template<> constexpr uint64_t key_sched_op<0,2> (const TigerBlock& i) { return key_sched_op<0,1>(i) + key_sched_op<7,1>(i); }
|
||||
template<> constexpr uint64_t key_sched_op<1,2> (const TigerBlock& i) { return key_sched_op<1,1>(i) - (key_sched_op<0,2>(i) ^ ((~key_sched_op<7,1>(i)) << 19)); }
|
||||
template<> constexpr uint64_t key_sched_op<2,2> (const TigerBlock& i) { return key_sched_op<2,1>(i) ^ key_sched_op<1,2>(i); }
|
||||
template<> constexpr uint64_t key_sched_op<3,2> (const TigerBlock& i) { return key_sched_op<3,1>(i) + key_sched_op<2,2>(i); }
|
||||
template<> constexpr uint64_t key_sched_op<4,2> (const TigerBlock& i) { return key_sched_op<4,1>(i) - (key_sched_op<3,2>(i) ^ ((~key_sched_op<2,2>(i)) >> 23)); }
|
||||
template<> constexpr uint64_t key_sched_op<5,2> (const TigerBlock& i) { return key_sched_op<5,1>(i) ^ key_sched_op<4,2>(i); }
|
||||
template<> constexpr uint64_t key_sched_op<6,2> (const TigerBlock& i) { return key_sched_op<6,1>(i) + key_sched_op<5,2>(i); }
|
||||
template<> constexpr uint64_t key_sched_op<7,2> (const TigerBlock& i) { return key_sched_op<7,1>(i) - (key_sched_op<6,2>(i) ^ 0x0123456789ABCDEFULL); }
|
||||
template <uint64_t I, uint64_t S> consteval uint64_t key_sched_op (const TigerBlock& i);
|
||||
template<> consteval uint64_t key_sched_op<0,1> (const TigerBlock& i) { return i[0] - (i[7] ^ 0xA5A5A5A5A5A5A5A5ULL); }
|
||||
template<> consteval uint64_t key_sched_op<1,1> (const TigerBlock& i) { return i[1] ^ key_sched_op<0,1>(i); }
|
||||
template<> consteval uint64_t key_sched_op<2,1> (const TigerBlock& i) { return i[2] + key_sched_op<1,1>(i); }
|
||||
template<> consteval uint64_t key_sched_op<3,1> (const TigerBlock& i) { return i[3] - (key_sched_op<2,1>(i) ^ ((~key_sched_op<1,1>(i)) << 19)); }
|
||||
template<> consteval uint64_t key_sched_op<4,1> (const TigerBlock& i) { return i[4] ^ key_sched_op<3,1>(i); }
|
||||
template<> consteval uint64_t key_sched_op<5,1> (const TigerBlock& i) { return i[5] + key_sched_op<4,1>(i); }
|
||||
template<> consteval uint64_t key_sched_op<6,1> (const TigerBlock& i) { return i[6] - (key_sched_op<5,1>(i) ^ ((~key_sched_op<4,1>(i)) >> 23)); }
|
||||
template<> consteval uint64_t key_sched_op<7,1> (const TigerBlock& i) { return i[7] ^ key_sched_op<6,1>(i); }
|
||||
template<> consteval uint64_t key_sched_op<0,2> (const TigerBlock& i) { return key_sched_op<0,1>(i) + key_sched_op<7,1>(i); }
|
||||
template<> consteval uint64_t key_sched_op<1,2> (const TigerBlock& i) { return key_sched_op<1,1>(i) - (key_sched_op<0,2>(i) ^ ((~key_sched_op<7,1>(i)) << 19)); }
|
||||
template<> consteval uint64_t key_sched_op<2,2> (const TigerBlock& i) { return key_sched_op<2,1>(i) ^ key_sched_op<1,2>(i); }
|
||||
template<> consteval uint64_t key_sched_op<3,2> (const TigerBlock& i) { return key_sched_op<3,1>(i) + key_sched_op<2,2>(i); }
|
||||
template<> consteval uint64_t key_sched_op<4,2> (const TigerBlock& i) { return key_sched_op<4,1>(i) - (key_sched_op<3,2>(i) ^ ((~key_sched_op<2,2>(i)) >> 23)); }
|
||||
template<> consteval uint64_t key_sched_op<5,2> (const TigerBlock& i) { return key_sched_op<5,1>(i) ^ key_sched_op<4,2>(i); }
|
||||
template<> consteval uint64_t key_sched_op<6,2> (const TigerBlock& i) { return key_sched_op<6,1>(i) + key_sched_op<5,2>(i); }
|
||||
template<> consteval uint64_t key_sched_op<7,2> (const TigerBlock& i) { return key_sched_op<7,1>(i) - (key_sched_op<6,2>(i) ^ 0x0123456789ABCDEFULL); }
|
||||
|
||||
constexpr TigerBlock key_sched (const TigerBlock& parBlock) {
|
||||
consteval TigerBlock key_sched (const TigerBlock& parBlock) {
|
||||
return TigerBlock(
|
||||
key_sched_op<0,2>(parBlock),
|
||||
key_sched_op<1,2>(parBlock),
|
||||
|
@ -431,7 +431,7 @@ namespace dhandy::bt {
|
|||
);
|
||||
}
|
||||
|
||||
constexpr HashType finalize_tiger_step (HashType parOriginal, HashType parPartial) {
|
||||
consteval HashType finalize_tiger_step (HashType parOriginal, HashType parPartial) {
|
||||
return HashType(
|
||||
parPartial.a ^ parOriginal.a,
|
||||
parPartial.b - parOriginal.b,
|
||||
|
@ -439,7 +439,7 @@ namespace dhandy::bt {
|
|||
);
|
||||
}
|
||||
|
||||
constexpr HashType tiger_block (const TigerBlock& parBlock, HashType parHash) {
|
||||
consteval HashType tiger_block (const TigerBlock& parBlock, HashType parHash) {
|
||||
return finalize_tiger_step(
|
||||
parHash,
|
||||
pass(1, 2, 0, 9, key_sched(key_sched(parBlock)),
|
||||
|
@ -450,11 +450,11 @@ namespace dhandy::bt {
|
|||
);
|
||||
}
|
||||
|
||||
constexpr HashType tiger_block (const char* parStr, HashType parHash) {
|
||||
consteval HashType tiger_block (const char* parStr, HashType parHash) {
|
||||
return tiger_block(TigerBlock(parStr), parHash);
|
||||
}
|
||||
|
||||
constexpr HashType tiger_chunk (const char* parStr, uint64_t parLen, HashType parHash) {
|
||||
consteval HashType tiger_chunk (const char* parStr, uint64_t parLen, HashType parHash) {
|
||||
return (parLen == 0 ?
|
||||
//if parLen == 0
|
||||
parHash
|
||||
|
@ -464,7 +464,7 @@ namespace dhandy::bt {
|
|||
);
|
||||
}
|
||||
|
||||
constexpr HashType tiger_last_chunk (const char* parStr, uint64_t parLen, uint64_t parRealLen, HashType parHash, char parPad) {
|
||||
consteval HashType tiger_last_chunk (const char* parStr, uint64_t parLen, uint64_t parRealLen, HashType parHash, char parPad) {
|
||||
return (
|
||||
parLen + 1 + ((8 - parLen - 1) bitand 7) == 64 ?
|
||||
tiger_block(
|
||||
|
@ -477,7 +477,7 @@ namespace dhandy::bt {
|
|||
}
|
||||
} //namespace implem
|
||||
|
||||
constexpr HashType tiger (const char* parStr, uint64_t parLen, char parPad) {
|
||||
consteval HashType tiger (const char* parStr, uint64_t parLen, char parPad) {
|
||||
return implem::tiger_last_chunk(
|
||||
parStr + (parLen bitand ~static_cast<uint64_t>(0x3f)),
|
||||
parLen - (parLen bitand ~static_cast<uint64_t>(0x3f)),
|
||||
|
|
Loading…
Reference in a new issue