Skip to content

[tracking issue] const fn: count_zeros, count_ones, leading_zeros, trailing_zeros #51267

Description

@glandium

One thing that I would like to do is to compile-time assert that the log2 of an alignment is less a given size. A simple way to do log2 of a power of 2 is to use trailing_zeros. But trailing_zeros is not const, so it's not possible to do a compile-time check.

The equivalent __builtins in clang are const (example: https://godbolt.org/g/RxWczn) so llvm should be able to handle that.

However, adding const to the functions in core::num requires adding const to the corresponding intrinsics, and that is not supported (extern items cannot be 'const')

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions