On Tue, Nov 12, 2024 at 01:32:36PM -0300, Ranier Vilela wrote: > See v1_allzeros_small.c attached.
In your pg_memory_is_all_zeros_v11: while (((uintptr_t) p & (sizeof(size_t) - 1)) != 0) { if (p == end) return true; if (*p++ != 0) return false; } if (len > sizeof(size_t) * 8) { for (; p < aligned_end - (sizeof(size_t) * 7); p += sizeof(size_t) * 8) { if ((((size_t *) p)[0] != 0) | (((size_t *) p)[1] != 0) | (((size_t *) p)[2] != 0) | (((size_t *) p)[3] != 0) | (((size_t *) p)[4] != 0) | (((size_t *) p)[5] != 0) | (((size_t *) p)[6] != 0) | (((size_t *) p)[7] != 0)) return false; } } If I'm reading that right, this could still read a couple of bytes past the wanted memory area. For example, imagine a case of 65 bytes with a location a bit unaligned (more than 2 bytes). You'd want to check the remaining size after the first loop, not the initial one. I'd be OK to have a quick loop for the less-than-64-byte case rather than more checks depending on sizeof(size_t) spread, like Bertrand is suggesting. I'd like to imagine that compilers would like that a bit better, though I am not completely sure, either. -- Michael
signature.asc
Description: PGP signature