gnzlbg / stdcxx-bitops

C++ Proposal: A constexpr bitwise operations library for C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

N3864 - A constexpr bitwise operations library for C++

This proposal has been submitted to the ISO C++ committee.

For the latest working draft go here:

Reference header:

Std-Proposals discussion:

Often we need to do bitwise manipulations such as finding the next power of 2, counting trailing zeros, and so on.

I'd like to propose a new <bitops> header which will contain a set of constexpr bit manipulation functions.

Why standardize this?

  1. These are low level basic primitives that can be used in a wide variety of applications and domains.
  2. Many cpus provide special instructions for these operations which are not available to the programmer without implementation specific support.
  3. The most efficient implementation varies greatly between platforms (built in instructions? loops? arithmetic? table lookup?), thus it belongs in the standard so that library implementers can sort out the differences on each platform
  4. Many compilers already provide intrinsics for a lot of these operations, so a lot of the work is already done. We just need a standard wrapper.
  5. operator>> for signed integral types behavior is implementation defined. There are no standard primitives to explicitly state logical shift and arithmetic shift. Also there is no circular shift or rotate.
  6. This is a very simple library addition that has no dependencies.

TODO:

  • Come up with at least one application for each proposed function.
  • Double check the reference implementation for bugs.
  • Write unit tests for the reference implementation using google test framework.
  • Propose more bitwise functions / remove or clarify existing.
  • Debate or propose new names for any of the functions.
  • (Low Priority) list native instructions for more machine types.

About

C++ Proposal: A constexpr bitwise operations library for C++

License:MIT License


Languages

Language:HTML 64.0%Language:C++ 34.6%Language:Makefile 1.4%