[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Improve bswap portability

From: Schanzenbach, Martin
Subject: Re: [PATCH] Improve bswap portability
Date: Sun, 19 Sep 2021 18:11:46 +0000

> On 19. Sep 2021, at 19:41, Malte Voos <> wrote:
> Hi!
> Thanks for the explanation. This may be a stupid question, but why not
> just use the bswap_* definitions from the libc?

I do not know why it is/was done in this way, possibly because there are 
platforms that use gcc but not glibc.
Maybe historically for win32 support.

> In glibc's case, bswap_*
> becomes __bswap_* (which is still not a compiler builtin, but a glibc
> internal name), which in turn becomes __builtin_bswap* if the GCC is
> recent enough. [1] In bionic's case, bswap_* always becomes
> __builtin_bswap* [2] [3]. Only musl doesn't use the builtins [4]. In my
> view, we have three options here:
> * Use the bswap_* definitions provided by the libc and accept that some
>  might not use compiler builtins
> * Use __builtin_bswap*, which is supported by both non-ancient GCC [5]
>  and Clang [6]
> * Keep rolling our own bswap compatibility layer to support obscure
>  compilers. In this case, I'd suggest that we check if __builtin_bswap*
>  is available, and if not, use the manual implementations we already
>  have.
> I don't think sticking with __bswap* is a good idea, since it is
> basically an implementation detail of glibc and musl, not a compiler
> builtin.

I changed it to this for now:
May break *BSDs and obscure byteswap.h.
It uses and libc/OS bytesswap.h now if present, otherwise the fallback 


> -malvo
> [1] 
> [2] 
> [3] 
> [4]
> [5]
> [6] 

Attachment: signature.asc
Description: Message signed with OpenPGP

reply via email to

[Prev in Thread] Current Thread [Next in Thread]