-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
I am currently looking at the performance page.
which contains this function.
bool need_allocation(const char *buf, size_t len) {
return ((reinterpret_cast<uintptr_t>(buf + len - 1) % page_size())
+ simdjson::SIMDJSON_PADDING > static_cast<uintptr_t>(page_size()));
}
I am writing some unit tests.
system_page_sizeis 4096 (4k)bufstarts at0x0len= 4033SIMDJSON_PADDING= 64 bytes
The last address of such an array is 0 + 4033 - 1 = 4032.
Add the padding, we get 4096. 4096, if interpreted as a pointer to an address, is in the next page. So the function should return true.
Instead, it returns false.
In other words, the operator should be >= and not >.
One possible solution occurs to me. While SIMDJSON_PADDING is defined to be 64 bytes, the actual amount of padding required is only 63 bytes.
Why? Because the SIMD machine reads blocks of 64 bytes at a time, and if our array of data to be processed ends on the final byte before a new block of 64 starts, we do not need any additional padding. If the array ended on the first address of a new block of 64 bytes, then an additional 63 bytes would be required.
Can anyone confirm what is the expected behavior?