public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/55899] New: GCC should provide built-ins in <stdint.h> data types flavor/version/variation
@ 2013-01-07 15:15 yann at droneaud dot fr
  2013-01-10 17:30 ` [Bug other/55899] " hp at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: yann at droneaud dot fr @ 2013-01-07 15:15 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55899

             Bug #: 55899
           Summary: GCC should provide built-ins in <stdint.h> data types
                    flavor/version/variation
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: other
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: yann@droneaud.fr


Built-in functions such as 
 __builtin_clz(unsigned int x)
 __builtin_ctz(unsigned int x)
 __builtin_ffs(unsigned int x)
 etc.
are lacking variant based on C99 <stdint.h> data type.

Currently there's
 __builtin_clzl(unsigned long x)
 __builtin_clzll(unsigned long long x)

I'd like to have:
 __builtin_clz32(uint32_t x)
 __builtin_clz64(uint64_t x)

This would help to hard code the number of bits when using such construct to
know the number of bit needed to hold a value:

(8 * sizeof(unsigned int)) - __builtin_clz(value)

when value is of type uint32_t:

 32 - __builtin_clz32(value)

Note: there's already __builtin_bswap32(int32_t x) and
__builtin_bswap64(int64_t x)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug other/55899] GCC should provide built-ins in <stdint.h> data types flavor/version/variation
  2013-01-07 15:15 [Bug other/55899] New: GCC should provide built-ins in <stdint.h> data types flavor/version/variation yann at droneaud dot fr
@ 2013-01-10 17:30 ` hp at gcc dot gnu.org
  2022-11-29 11:45 ` yann at droneaud dot fr
  2022-11-29 18:59 ` joseph at codesourcery dot com
  2 siblings, 0 replies; 4+ messages in thread
From: hp at gcc dot gnu.org @ 2013-01-10 17:30 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55899

Hans-Peter Nilsson <hp at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-01-10
                 CC|                            |hp at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #1 from Hans-Peter Nilsson <hp at gcc dot gnu.org> 2013-01-10 17:29:48 UTC ---
Sounds fair.  Note the inconsistency between clz/ctz builtins and bswap
builtins.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug other/55899] GCC should provide built-ins in <stdint.h> data types flavor/version/variation
  2013-01-07 15:15 [Bug other/55899] New: GCC should provide built-ins in <stdint.h> data types flavor/version/variation yann at droneaud dot fr
  2013-01-10 17:30 ` [Bug other/55899] " hp at gcc dot gnu.org
@ 2022-11-29 11:45 ` yann at droneaud dot fr
  2022-11-29 18:59 ` joseph at codesourcery dot com
  2 siblings, 0 replies; 4+ messages in thread
From: yann at droneaud dot fr @ 2022-11-29 11:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55899

Yann Droneaud <yann at droneaud dot fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yann at droneaud dot fr

--- Comment #2 from Yann Droneaud <yann at droneaud dot fr> ---
I stumbled upon this issue again when dealing with uint64_t as sometimes it's
defined as unsigned long, sometimes it's defined as unsigned long long
depending on the ABI. Having __builtin_ffs64(), __builtin_clz64(),
__builtin_ctz64(), etc. would ease me making my code portable to unpleasant ABI
such as Microsoft Windows ones without having to use GCC's
__builtin_types_compatible_p() (which is not supported when compiling C++), or
C11 _Generic() ...

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug other/55899] GCC should provide built-ins in <stdint.h> data types flavor/version/variation
  2013-01-07 15:15 [Bug other/55899] New: GCC should provide built-ins in <stdint.h> data types flavor/version/variation yann at droneaud dot fr
  2013-01-10 17:30 ` [Bug other/55899] " hp at gcc dot gnu.org
  2022-11-29 11:45 ` yann at droneaud dot fr
@ 2022-11-29 18:59 ` joseph at codesourcery dot com
  2 siblings, 0 replies; 4+ messages in thread
From: joseph at codesourcery dot com @ 2022-11-29 18:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55899

--- Comment #3 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
C2x <stdbit.h> provides type-generic versions of various such operations, 
in addition to type-specific versions (but the type-specific versions are 
for unsigned char through unsigned long long, so don't themselves address 
the issue from this PR, and my view is that type-generic functions are 
error-prone in cases, such as clz, where the result depends on the type 
and not just the integer value of the argument).

Since <stdbit.h> is a library facility (with functions thus expected to be 
available with external linkage to link against whether or not the header 
is included) I expect to implement it in due course in glibc, not GCC, 
though as usual built-in functions with the standard names would be 
appropriate in GCC.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-29 18:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-07 15:15 [Bug other/55899] New: GCC should provide built-ins in <stdint.h> data types flavor/version/variation yann at droneaud dot fr
2013-01-10 17:30 ` [Bug other/55899] " hp at gcc dot gnu.org
2022-11-29 11:45 ` yann at droneaud dot fr
2022-11-29 18:59 ` joseph at codesourcery dot com

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 read-only IMAP folder(s) and NNTP newsgroup(s).