minor refactor

check scenario with input size == exact nb of blocks
though not a multiple of 256 (streaming internal buffer size)
This commit is contained in:
Yann Collet 2020-06-18 12:37:03 -07:00
parent dcb83c8cc3
commit 2e88626a2c
2 changed files with 14 additions and 10 deletions

20
xxh3.h
View File

@ -1995,23 +1995,25 @@ XXH3_64bits_reset_withSeed(XXH3_state_t* statePtr, XXH64_hash_t seed)
XXH_FORCE_INLINE void
XXH3_consumeStripes(xxh_u64* XXH_RESTRICT acc,
size_t* XXH_RESTRICT nbStripesSoFarPtr, size_t nbStripesPerBlock,
const xxh_u8* XXH_RESTRICT input, size_t totalStripes,
const xxh_u8* XXH_RESTRICT input, size_t nbStripes,
const xxh_u8* XXH_RESTRICT secret, size_t secretLimit,
XXH3_accWidth_e accWidth,
XXH3_f_accumulate_512 f_acc512,
XXH3_f_scrambleAcc f_scramble)
{
XXH_ASSERT(nbStripes <= nbStripesPerBlock); /* can handle max 1 scramble per invocation */
XXH_ASSERT(*nbStripesSoFarPtr < nbStripesPerBlock);
if (nbStripesPerBlock - *nbStripesSoFarPtr <= totalStripes) {
if (nbStripesPerBlock - *nbStripesSoFarPtr <= nbStripes) {
/* need a scrambling operation */
size_t const nbStripes = nbStripesPerBlock - *nbStripesSoFarPtr;
XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, nbStripes, accWidth, f_acc512);
size_t const nbStripesToEndofBlock = nbStripesPerBlock - *nbStripesSoFarPtr;
size_t const nbStripesAfterBlock = nbStripes - nbStripesToEndofBlock;
XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, nbStripesToEndofBlock, accWidth, f_acc512);
f_scramble(acc, secret + secretLimit);
XXH3_accumulate(acc, input + nbStripes * XXH_STRIPE_LEN, secret, totalStripes - nbStripes, accWidth, f_acc512);
*nbStripesSoFarPtr = totalStripes - nbStripes;
XXH3_accumulate(acc, input + nbStripesToEndofBlock * XXH_STRIPE_LEN, secret, nbStripesAfterBlock, accWidth, f_acc512);
*nbStripesSoFarPtr = nbStripesAfterBlock;
} else {
XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, totalStripes, accWidth, f_acc512);
*nbStripesSoFarPtr += totalStripes;
XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, nbStripes, accWidth, f_acc512);
*nbStripesSoFarPtr += nbStripes;
}
}
@ -2063,7 +2065,7 @@ XXH3_update(XXH3_state_t* state,
state->bufferedSize = 0;
}
/* Consume input by full buffer quantities */
/* Consume input by a multiple of internal buffer size */
if (input+XXH3_INTERNALBUFFER_SIZE <= bEnd) {
const xxh_u8* const limit = bEnd - XXH3_INTERNALBUFFER_SIZE;
do {

View File

@ -1212,7 +1212,7 @@ static void BMK_sanityCheck(void)
/* XXH3 with Custom Secret */
{ const void* const secret = sanityBuffer + 7;
const size_t secretSize = XXH3_SECRET_SIZE_MIN + 11;
assert(sizeof(sanityBuffer) >= XXH3_SECRET_SIZE_MIN + 7 + 11);
assert(sizeof(sanityBuffer) >= 7 + secretSize);
BMK_testXXH3_withSecret(NULL, 0, secret, secretSize, 0x6775FD10343C92C3ULL); /* empty string */
BMK_testXXH3_withSecret(sanityBuffer, 1, secret, secretSize, 0xC3382C326E24E3CDULL); /* 1 - 3 */
BMK_testXXH3_withSecret(sanityBuffer, 6, secret, secretSize, 0x82C90AB0519369ADULL); /* 4 - 8 */
@ -1226,6 +1226,8 @@ static void BMK_sanityCheck(void)
BMK_testXXH3_withSecret(sanityBuffer, 512, secret, secretSize, 0x7896E65DCFA09071ULL); /* one block, finishing at stripe boundary */
BMK_testXXH3_withSecret(sanityBuffer,2048, secret, secretSize, 0xD6545DB87ECFD98CULL); /* >= 2 blocks, at least one scrambling */
BMK_testXXH3_withSecret(sanityBuffer,2367, secret, secretSize, 0x857320340D953686ULL); /* >= 2 blocks, at least one scrambling, last stripe unaligned */
BMK_testXXH3_withSecret(sanityBuffer,64*10*3, secret, secretSize, 0xD4989A002E9850ABULL); /* exactly 3 full blocks, not a multiple of 256 */
}
/* XXH128 */