Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created March 26, 2012 02:57
Show Gist options
  • Save rygorous/2202577 to your computer and use it in GitHub Desktop.
Save rygorous/2202577 to your computer and use it in GitHub Desktop.
ISPC surprising code-gen edge case
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