Bug 58872 - RFC: more builtins for bit manipulation
Summary: RFC: more builtins for bit manipulation
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-25 09:28 UTC by Yann Droneaud
Modified: 2022-11-30 23:29 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yann Droneaud 2013-10-25 09:28:58 UTC
Current bit manipulation builtins can be found in documentation:
http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#Other-Builtins

GCC could benefit of more bit manipulation builtins, for example:

- rotate bit right:

  __builtin_ror8(uint8_t v, int count)
  __builtin_ror16(uint16_t v, int count)
  __builtin_ror32(uint32_t v, int count)
  __builtin_ror64(uint64_t v, int count)

- rotate bit left:

  __builtin_rol8(uint8_t v, int count)
  __builtin_rol16(uint16_t v, int count)
  __builtin_rol32(uint32_t v, int count)
  __builtin_rol64(uint64_t v, int count)

- reverse bit string (bit swap):

  __builtin_brev8(uint8_t v, int index, int count)
  __builtin_brev16(uint16_t v, int index, int count)
  __builtin_brev32(uint32_t v, int index, int count)
  __builtin_brev64(uint64_t v, int index, int count)
Comment 1 Marc Glisse 2013-10-25 10:15:29 UTC
What do the arguments of brev mean?
Related to PR 50481.
Comment 2 Yann Droneaud 2013-10-25 12:46:15 UTC
(In reply to Marc Glisse from comment #1)
> What do the arguments of brev mean?
> Related to PR 50481.

The prototype for the reverse bit string builtin was designed to be useful to reverse bits in a subset of a integer value, starting at "index" with "count" bits.

The general use case is likely to reverse all bits in a variable, (uint64_t for example):

    uint64_t v;
    __builtin_brev64(v, 0, sizeof(v) * 8);

But I thought it might be interesting to have a "more" general purpose builtin.

Actually, the builtin arguments for reverse should probably match what's currently available on modern hardware.