Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant division templates #89

Merged
merged 7 commits into from
Nov 30, 2021

Conversation

adbancroft
Copy link
Collaborator

A set of predefined templates to speed up division by 16-bit constants.

Template equivalent of #76.

@ridiculousfish
Copy link
Owner

ridiculousfish commented Nov 19, 2021

These hpp files are giving the compiler quite a workout, with 32k separate specializations! Those are going to be some fun error messages when it lists all the templates that don't apply!

I think this could be cleaner as a constexpr function instead. With C++14 you could use switch, with C++11 it can still be done with chained ternary operators:

constexpr libdivide_s16_t get_divider(constexpr int16_t v) {
  return v == -16384   ? libdivide_s16_t{0, 142}
         : v == -16383 ? libdivide_s16_t{32765, 205}
         : v == -16382 ? libdivide_s16_t{32763, 205}
         // remaining 65k go here
         : libdivide_s16_t{0, 0}; // unreachable
}

etc. It's up to you whether you implement that, just an idea in case you haven't thought of it.

So single source of truth for 16-bit libdivide constants
@adbancroft
Copy link
Collaborator Author

Unfortunately the constexpr function didn't pan out: it increases compile times to an unacceptable level. I don't know exactly how much, as it took so long that I killed the compiler process after 10 mins (for a build that normally takes seconds).

I've left the relevant code in the generator just in case we could make use of it in the future.

@adbancroft adbancroft merged commit fec818d into ridiculousfish:master Nov 30, 2021
@adbancroft adbancroft deleted the cpp_constants branch February 7, 2022 13:21
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.

2 participants