Last active
June 1, 2018 12:54
-
-
Save lion328/5b298539e930dba927df414658cb8cc6 to your computer and use it in GitHub Desktop.
Branchless Grading
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
#include <stdio.h> | |
#include <stdint.h> | |
int main() | |
{ | |
uint8_t buf[4] = {0}; | |
fgets(buf, sizeof(buf), stdin); | |
int32_t i = (buf[2] << 8) | (buf[0]); | |
int32_t g = (i - 0xA35) >> 31 & 0x33; | |
g |= (~-g & (i - 0xA38)) >> 31 & buf[0]; | |
g |= ~-g >> 31 & 0x38; | |
g = 0x79 - g; | |
putchar(g); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment