Skip to content

[API Proposal]: BitOperations.ReverseBits #125879

@saucecontrol

Description

@saucecontrol

Background and motivation

This is defined and used a few places in the runtime and libs: https://github.com/search?q=repo%3Adotnet%2Fruntime%20ReverseBits&type=code

It would be generally useful to expose it publicly in BitOperations.

This operation can be hardware accelerated on Arm64 (rbit) and recent x86/64 (GFNI or AVX512_BMM).

API Proposal

namespace System.Numerics;

public static class BitOperations
{
    public static byte ReverseBits(byte value);
    public static ushort ReverseBits(ushort value);
    public static uint ReverseBits(uint value);
    public static ulong ReverseBits(ulong value);
    public static nuint ReverseBits(nuint value);
}

API Usage

uint xrev = BitOperations.ReverseBits(x);

Alternative Designs

Could consider signed and/or smaller type overloads

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions