-
-
Save ChrisKitching/73f66a422af926a6dbdcd045442c4440 to your computer and use it in GitHub Desktop.
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
__device__ uint32_t scopeViolation(bool* secretlyAlwaysTrue, | |
bool* secretlyAlwaysFalse, | |
uint32_t x) { | |
asm volatile("{"); | |
asm volatile(".reg .b32 tmp;"); | |
asm volatile("mov.b32 tmp, 76;"); // <- Write to unused variable. | |
asm volatile("}"); | |
uint32_t output; | |
if (*secretlyAlwaysFalse) { | |
asm volatile(".reg .b32 tmp;"); // <- Declarations count, even if unreachable. | |
asm volatile("mov.b32 tmp, 42;"); // <- Never runs | |
asm volatile("{"); | |
#pragma clang diagnostic push | |
#pragma clang diagnostic ignored "-Wptx-warnings" | |
asm volatile(".reg .b32 tmp;"); // <- Inaccessible local variable. | |
#pragma clang diagnostic pop | |
asm volatile("}"); | |
} | |
if (*secretlyAlwaysTrue) { | |
asm volatile("mov.b32 tmp, 4;"); // <- Actually runs. | |
} | |
asm volatile("add.u32 tmp, %0, tmp;" :: "r"(x)); | |
if (*secretlyAlwaysTrue) { | |
asm volatile("add.u32 tmp, %0, tmp;" :: "r"(x)); | |
} | |
asm volatile("mov.b32 %0, tmp;" : "=r"(output)); | |
// Overall effect is `return x * 2 + 4;`. | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment