我读到了Facebook最近发布的新版ZStandard compression yesterday,其中部分内容解释说它更快部分归功于无分支循环。
任何人都可以解释它是如何运作的吗?
/* classic version */
while (nbBitsUsed >= 8) { /* each while test is a branch */
accumulator <<= 8;
accumulator += *byte++;
nbBitsUsed -= 8;
}
/* branch-less version */
nbBytesUsed = nbBitsUsed >> 3;
nbBitsUsed &= 7;
ptr += nbBytesUsed;
accumulator = read64(ptr);