Subject: Re: [PATCH v2 4/6] bswap.h: Always overwrite ntohl/ ntohll macros

From: "brian m. carlson" <[email-masked]>
Date: Thu, 12 Jun 2025 00:14:48 +0000

On 2025-06-11 at 22:14:40, Sebastian Andrzej Siewior wrote:
> The ntohl and htonl macros are redefined because the provided macros were
> not always optimal. Sometimes it was a function call, sometimes it was a
> macro which did the shifting. Using the 'bswap' opcode on x86 provides
> probably better performance than performing the shifting.

I believe that the peephole optimizer will almost always optimize them
to the bswap or equivalent opcode, much like it recognizes how to
generate rotate opcodes from two shifts and an or, so they should
actually be equivalent.

GCC and clang both emit simple bswap instructions with `-O2`, which is
the optimization level we use: https://godbolt.org/z/1r8P1Pqo7.
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA