multiexp: pack the digits table when STRAUS_C is 4

Spotted by stoffu
This commit is contained in:
moneromooo-monero 2018-08-13 11:18:54 +00:00
parent bf8e4b9870
commit 4061960a16
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3

View file

@ -320,7 +320,7 @@ rct::key bos_coster_heap_conv_robust(std::vector<MultiexpData> data)
return res; return res;
} }
static constexpr unsigned int STRAUS_C = 4; #define STRAUS_C 4
struct straus_cached_data struct straus_cached_data
{ {
@ -447,26 +447,23 @@ rct::key straus(const std::vector<MultiexpData> &data, const std::shared_ptr<str
#endif #endif
MULTIEXP_PERF(PERF_TIMER_START_UNIT(digits, 1000000)); MULTIEXP_PERF(PERF_TIMER_START_UNIT(digits, 1000000));
#if STRAUS_C==4
std::unique_ptr<uint8_t[]> digits{new uint8_t[64 * data.size()]};
#else
std::unique_ptr<uint8_t[]> digits{new uint8_t[256 * data.size()]}; std::unique_ptr<uint8_t[]> digits{new uint8_t[256 * data.size()]};
#endif
for (size_t j = 0; j < data.size(); ++j) for (size_t j = 0; j < data.size(); ++j)
{ {
unsigned char bytes33[33]; unsigned char bytes33[33];
memcpy(bytes33, data[j].scalar.bytes, 32); memcpy(bytes33, data[j].scalar.bytes, 32);
bytes33[32] = 0; bytes33[32] = 0;
const unsigned char *bytes = bytes33; const unsigned char *bytes = bytes33;
#if 1 #if STRAUS_C==4
static_assert(STRAUS_C == 4, "optimized version needs STRAUS_C == 4");
unsigned int i; unsigned int i;
for (i = 0; i < 256; i += 8, bytes++) for (i = 0; i < 64; i += 2, bytes++)
{ {
digits[j*256+i] = bytes[0] & 0xf; digits[j*64+i] = bytes[0] & 0xf;
digits[j*256+i+1] = (bytes[0] >> 1) & 0xf; digits[j*64+i+1] = bytes[0] >> 4;
digits[j*256+i+2] = (bytes[0] >> 2) & 0xf;
digits[j*256+i+3] = (bytes[0] >> 3) & 0xf;
digits[j*256+i+4] = ((bytes[0] >> 4) | (bytes[1]<<4)) & 0xf;
digits[j*256+i+5] = ((bytes[0] >> 5) | (bytes[1]<<3)) & 0xf;
digits[j*256+i+6] = ((bytes[0] >> 6) | (bytes[1]<<2)) & 0xf;
digits[j*256+i+7] = ((bytes[0] >> 7) | (bytes[1]<<1)) & 0xf;
} }
#elif 1 #elif 1
for (size_t i = 0; i < 256; ++i) for (size_t i = 0; i < 256; ++i)
@ -521,7 +518,11 @@ skipfirst:
if (skip[j]) if (skip[j])
continue; continue;
#endif #endif
#if STRAUS_C==4
const uint8_t digit = digits[j*64+i/4];
#else
const uint8_t digit = digits[j*256+i]; const uint8_t digit = digits[j*256+i];
#endif
if (digit) if (digit)
{ {
ge_add(&p1, &band_p3, &CACHE_OFFSET(local_cache, j, digit)); ge_add(&p1, &band_p3, &CACHE_OFFSET(local_cache, j, digit));