Re: define pg_structiszero(addr, s, r)
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>, Ranier Vilela <ranier.vf@gmail.com>, Peter Smith <smithpb2250@gmail.com>, Peter Eisentraut <peter@eisentraut.org>, Heikki Linnakangas <hlinnaka@iki.fi>, pgsql-hackers@lists.postgresql.org
Date: 2024-11-08T17:33:52Z
Lists: pgsql-hackers
Attachments
- v10-0001-Optimize-pg_memory_is_all_zeros.patch (text/x-diff)
Hi, On Fri, Nov 08, 2024 at 11:18:09PM +1300, David Rowley wrote: > On Fri, 8 Nov 2024 at 18:34, Michael Paquier <michael@paquier.xyz> wrote: > > I've done a round of comment and term cleanup for the whole patch, > > while on it. > > I don't think "intrinsics" is the correct word to use here: > > + * - 8 * sizeof(size_t) comparisons using bitwise OR, to encourage compilers > + * to use SIMD intrinsics if available, up to the last aligned location > > and > > + * All comparisons are combined with a single OR operation, making it a > + * good candidate for SIMD intrinsics, if available. > > an intrinsic function is a function built into the compiler that > provides some lower-level functionality. e.g. __builtin_popcount(). Agree, replaced by "instructions" in v10 attached. > I'm slightly worried due to the current rate we're receiving cleanup > suggestions that someone might come along and think they'd be doing us > a favour by submitting a patch to "fixup the inefficient bitwise-ORs > and use boolean-OR". That's a good point, better to be cautious here. > Maybe a comment like the following might prevent > that from happening. > > + * For performance reasons, we manually unroll this loop and purposefully > + * use bitwise-ORs to combine each comparison. This prevents boolean > + * short-circuiting and lets the compiler know that it's safe to access all 8 > + * elements regardless of the result of the other comparisons. This seems > + * to be enough to coax a few compilers into using SIMD instructions. Sounds good to me, used the above in v10. v10 also splits the patch into 2 parts as suggested by Michael up-thread. > > > Btw, gcc seems a bit smarter than clang when it comes to optimizing > > the code depending on the size of the structures. gcc gives up on > > SIMD if it's sure that the structure on which we are going to use the > > allzero check won't need it at all, and clang keeps it even if it does > > not need it. That was interesting to see, while going through the > > review.. > > Can you share your test case for this? +1 Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
Commits
-
Use pg_memory_is_all_zeros() in PageIsVerifiedExtended()
- 03a42c9652f8 18.0 landed
-
Optimize pg_memory_is_all_zeros() in memutils.h
- 5be1dabd2ae0 18.0 landed
-
Remove use of pg_memory_is_all_zeros() in bufpage.c
- e819bbb7c82a 18.0 landed
-
Add pg_memory_is_all_zeros() in memutils.h
- 07e9e28b56db 18.0 landed