This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/20530] New: bswap_16 should use __builtin_bswap16() when available


https://sourceware.org/bugzilla/show_bug.cgi?id=20530

            Bug ID: 20530
           Summary: bswap_16 should use __builtin_bswap16() when available
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: jzwinck at gmail dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Since GCC 4.3, glibc has used __builtin_bswap32() to implement bswap_32().  See
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=9904dc47c88d9592ec66e5990754369bfde84c02
(later amended to require GCC 4.3 instead of 4.2).

Since GCC 4.8, __builtin_bswap16() has existed, but it isn't used to implement
bswap_16().

This becomes a problem when trying to use bswap_16() in C++ constexpr
functions: GCC 5 and GCC 6 reject such code because bswap_16() uses inline
assembler.

I think the fix is to add this to bits/byteswap-16.h:

    # if __GNUC_PREREQ (4, 8)
    static __inline unsigned short int
    __bswap_16 (unsigned short int __bsx)
    {
      return __builtin_bswap16 (__bsx);
    }

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]