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

Check that compiler generates reasonable code when upper bound of for loop involves a function call #19

Open
dictoon opened this issue Jan 4, 2017 · 1 comment

Comments

@dictoon
Copy link

dictoon commented Jan 4, 2017

E.g. in ewah.h line 908 it's worth making sure compilers compute the upper bound once, and not at each iteration.

A safer alternative, immune to optimization woes, with minimal changes:

for (size_t k = 0, e = rlw.getNumberOfLiteralWords(); k < e; ++k)
@lemire
Copy link
Owner

lemire commented Jan 4, 2017

If these sort of function calls do not get inlined and optimized using current C++ compilers, then the whole code base is in trouble because it is filled with getRunningBit(), getNumberOfLiteralWords() and so forth all over, including within hot loops. So there is a strong assumption that C++ compilers are at least that good.

The issue you raise is totally valid and this assumption should be checked.

In Java, I do not make this assumption. Often the JDK cannot optimize these calls away. But C++ is a different beast and I assume that C++ is a lot better at providing us abstraction for free.

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

No branches or pull requests

2 participants