Created
March 26, 2012 02:57
-
-
Save rygorous/2202577 to your computer and use it in GitHub Desktop.
ISPC surprising code-gen edge case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export void good(uniform int output[], uniform const int a[], uniform const int b[], uniform unsigned int count) | |
{ | |
count &= ~15; | |
foreach (i = 0 ... count) | |
{ | |
// This function works as you'd expect | |
int x = a[i]; | |
int y = b[i]; | |
output[i] = (x > 0) ? x : y; | |
} | |
} | |
export void bad(uniform int output[], uniform const int a[], uniform const int b[], uniform unsigned int count) | |
{ | |
count &= ~15; | |
foreach (i = 0 ... count) | |
{ | |
// This one doesn't: to preserve semantics of the program correctly, b[i] may only be | |
// accessed in lanes where x > 0. Which means that this code generates a lot of conditional | |
// control flow that users will likely be surprised by. :) | |
int x = a[i]; | |
output[i] = (x > 0) ? x : b[i]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment