* byteswap.h
@ 2017-04-07 17:53 fab10
2017-04-07 17:55 ` byteswap.h Jon Chesterfield
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: fab10 @ 2017-04-07 17:53 UTC (permalink / raw)
To: musl
I had a look at byteswap.h and it seems to me that the code is not very
efficient. Every function in this header could be translated in a single
assembly instruction with the gcc intrinsics:
__builtin_bswap16
__builtin_bswap32
__builtin_bswap64
Is there a reason to not use these gcc intrinsics?
Bye
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: byteswap.h
2017-04-07 17:53 byteswap.h fab10
@ 2017-04-07 17:55 ` Jon Chesterfield
2017-04-07 18:01 ` byteswap.h Rich Felker
2017-04-07 18:07 ` byteswap.h Joakim Sindholt
2 siblings, 0 replies; 5+ messages in thread
From: Jon Chesterfield @ 2017-04-07 17:55 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 529 bytes --]
Have you tested whether the intrinsics improve codegen on a recent
compiler? There's a good chance they make the code non-portable while
generating the same asm.
Jon
On 7 Apr 2017 18:53, "fab10" <0xfab10@gmail.com> wrote:
I had a look at byteswap.h and it seems to me that the code is not very
efficient. Every function in this header could be translated in a single
assembly instruction with the gcc intrinsics:
__builtin_bswap16
__builtin_bswap32
__builtin_bswap64
Is there a reason to not use these gcc intrinsics?
Bye
[-- Attachment #2: Type: text/html, Size: 923 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: byteswap.h
2017-04-07 17:53 byteswap.h fab10
2017-04-07 17:55 ` byteswap.h Jon Chesterfield
@ 2017-04-07 18:01 ` Rich Felker
2017-04-07 18:07 ` byteswap.h Joakim Sindholt
2 siblings, 0 replies; 5+ messages in thread
From: Rich Felker @ 2017-04-07 18:01 UTC (permalink / raw)
To: musl
On Fri, Apr 07, 2017 at 07:53:09PM +0200, fab10 wrote:
> I had a look at byteswap.h and it seems to me that the code is not
> very efficient. Every function in this header could be translated in
> a single assembly instruction with the gcc intrinsics:
>
> __builtin_bswap16
> __builtin_bswap32
> __builtin_bswap64
>
> Is there a reason to not use these gcc intrinsics?
Because the compile should be (and as far as I know, is) generating
the optimal single instructions from the portable C, without the need
for hackish non-portable intrinsics.
Rich
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: byteswap.h
2017-04-07 17:53 byteswap.h fab10
2017-04-07 17:55 ` byteswap.h Jon Chesterfield
2017-04-07 18:01 ` byteswap.h Rich Felker
@ 2017-04-07 18:07 ` Joakim Sindholt
2017-04-08 14:57 ` byteswap.h Szabolcs Nagy
2 siblings, 1 reply; 5+ messages in thread
From: Joakim Sindholt @ 2017-04-07 18:07 UTC (permalink / raw)
To: musl
On Fri, Apr 07, 2017 at 07:53:09PM +0200, fab10 wrote:
> I had a look at byteswap.h and it seems to me that the code is not very
> efficient. Every function in this header could be translated in a single
> assembly instruction with the gcc intrinsics:
>
> __builtin_bswap16
> __builtin_bswap32
> __builtin_bswap64
>
> Is there a reason to not use these gcc intrinsics?
>
> Bye
>
While musl does employ GNU C features in quite a few places it's just
plain unnecessary here.
https://godbolt.org/g/eLZWwI
When optimized those functions yield a single bswap instruction anyway,
because GCC is smart enough to deduce this.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: byteswap.h
2017-04-07 18:07 ` byteswap.h Joakim Sindholt
@ 2017-04-08 14:57 ` Szabolcs Nagy
0 siblings, 0 replies; 5+ messages in thread
From: Szabolcs Nagy @ 2017-04-08 14:57 UTC (permalink / raw)
To: musl
* Joakim Sindholt <opensource@zhasha.com> [2017-04-07 20:07:42 +0200]:
> On Fri, Apr 07, 2017 at 07:53:09PM +0200, fab10 wrote:
> > I had a look at byteswap.h and it seems to me that the code is not very
> > efficient. Every function in this header could be translated in a single
> > assembly instruction with the gcc intrinsics:
> >
> > __builtin_bswap16
> > __builtin_bswap32
> > __builtin_bswap64
> >
> > Is there a reason to not use these gcc intrinsics?
> >
> > Bye
> >
>
> While musl does employ GNU C features in quite a few places it's just
> plain unnecessary here.
>
rarely in public headers though which have to
be portable to all c source parser tools.
builtins would need to be conditional on __GNUC__
and we still need the portable code as a fallback
which is harder to maintain and test
> https://godbolt.org/g/eLZWwI
>
> When optimized those functions yield a single bswap instruction anyway,
> because GCC is smart enough to deduce this.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-04-08 14:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-07 17:53 byteswap.h fab10
2017-04-07 17:55 ` byteswap.h Jon Chesterfield
2017-04-07 18:01 ` byteswap.h Rich Felker
2017-04-07 18:07 ` byteswap.h Joakim Sindholt
2017-04-08 14:57 ` byteswap.h Szabolcs Nagy
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).