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

Update RadixSort.cpp #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

ferralverrall
Copy link

Move if check out of inner while loop

Move if check out of inner while loop
@castano
Copy link
Contributor

castano commented Aug 19, 2018

Interesting, have you checked whether the compiler actually produces better code? bucketCount is a constant, so the compiler may be doing the same transform for you already.

In our jai implementation I'm using a different approach, evaluating the branch(es) explicitly at compile time:

while (p != pe) {
    h[0][<<p] += 1; p += 1;
    
    #if bucket_count > 1 {
        h[1][<<p] += 1; p += 1;

        #if bucket_count > 2 {
            h[2][<<p] += 1; p += 1;
            h[3][<<p] += 1; p += 1;

            #if bucket_count == 8 {
                h[4][<<p] += 1; p += 1;
                h[5][<<p] += 1; p += 1;
                h[6][<<p] += 1; p += 1;
                h[7][<<p] += 1; p += 1;
            }
        }
    }
}

I imagine that in C++17 you should be able to use 'if constexpr' instead. In any case, if your version produces better code, I'd be happy to commit it.

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