Skip to content

Use Clang's __is_trivially_equality_comparable intrinsic to optimize more cases in vector algorithms #5479

@AlexGuteniev

Description

@AlexGuteniev

__is_trivially_equality_comparable is a trait that is true if a type is memcmp comarable for == and != against itself. We can use that on Clang along with existing metaprogramming.

This will allow covering more types like struct containing only integers with defaulted comparison and enums without user-defined comparison. This includes user defined types, for which this cannot be achieved without "magic". Also this includes standard types, such as chrono::duration or pair<int, int> if their comparison is defaulted properly; this should be less burden that specializing traits for them all.

A separate escape hatch could be a good idea, due to quasi-supporting old Clang and "new" Intel, which may not have __is_trivially_equality_comparable, or may have more bugs in it.

These algorithms can be improved:

  • equal for all sizes
  • search, find_end, adjacent_find, find_first_of, search_n, unique, unique_copy for vector element sizes
  • mismatch for all sizes
  • find, find_last, remove, remove_copy, count for vector element sizes
  • replace for some vector element sizes (32-bit and 64-bit)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions