Skip to content

Conversation

@BillyONeal
Copy link
Member

In GH-425 I was forced to add a dead initialization for the _Count variable in _Sort_unchecked in order to comply with constexpr rules. Also, _Sort_unchecked had somewhat complex assignment-in-conditional-expressions going on. This change moves the code around such that the _Count variable is assigned once.

Also:

  • Consistently test _ISORT_MAX with <=, and make that an _INLINE_VAR constexpr variable.
  • Remove _Count guards of 1 in front of _Insertion_sort_unchecked for consistency. I did performance testing and there was no measurable difference in keeping this check, and it's more code to reason about.
  • Avoid needless casts of _ISORT_MAX given that it is now a constexpr constant.

Checklist

Be sure you've read README.md and understand the scope of this repo.

If you're unsure about a box, leave it unchecked. A maintainer will help you.

  • Identifiers in product code changes are properly _Ugly as per
    https://eel.is/c++draft/lex.name#3.1 or there are no product code changes.
  • The STL builds successfully and all tests have passed (must be manually
    verified by an STL maintainer before automated testing is enabled on GitHub,
    leave this unchecked for initial submission).
  • These changes introduce no known ABI breaks (adding members, renaming
    members, adding virtual functions, changing whether a type is an aggregate
    or trivially copyable, etc.).
  • These changes were written from scratch using only this repository,
    the C++ Working Draft (including any cited standards), other WG21 papers
    (excluding reference implementations outside of proposed standard wording),
    and LWG issues as reference material. If they were derived from a project
    that's already listed in NOTICE.txt, that's fine, but please mention it.
    If they were derived from any other project (including Boost and libc++,
    which are not yet listed in NOTICE.txt), you must mention it here,
    so we can determine whether the license is compatible and what else needs
    to be done.

…were forced to initialize in the constexpr algorithms review by eliminating the variable entirely.

* Consistently test _ISORT_MAX with <=, and make that an _INLINE_VAR constexpr variable.
* Remove _Count guards of 1 in front of _Insertion_sort_unchecked for consistency. I did performance testing and there was no measurable difference in keeping this check, and it's more code to reason about.
* Avoid needless casts of _ISORT_MAX given that it is now a constexpr constant.
@BillyONeal BillyONeal requested a review from a team as a code owner January 24, 2020 02:14
return;
}

if (_Ideal <= 0) { // heap sort if too many divisions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I observe that _Ideal should never be negative. It's initially _ULast - _UFirst (non-negative) and then decreases via _Ideal = (_Ideal >> 1) + (_Ideal >> 2). Perhaps an _STL_INTERNAL_CHECK for negative, and an exact == 0 test otherwise? However, there's probably no codegen difference in practice, so I don't really care.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codegen is identical except for je vs. jle
image

@BillyONeal BillyONeal merged commit 4c91c91 into microsoft:master Jan 25, 2020
@BillyONeal BillyONeal deleted the improve_sort_eliminate_count branch January 25, 2020 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants