Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // compile with -O3 flag
- size_t strlen_no_condbr(char *s)
- {
- size_t l=0;
- void* ptr;
- while (1)
- {
- // ugly but gcc produce conditionnal branches if i don't do that
- goto *(void*) ( ((!!s[l])-1ll) & (long long)&&d | ((!!s[l])*-1ll) & (long long)&&i );
- i:
- l ++;
- }
- d:;
- return l;
- }
- size_t strlen_no_condbr2(char* s)
- {
- size_t l = 0;
- volatile int x = 0;
- l --;
- while (1)
- {
- l++;
- switch ((unsigned char)s[l])
- {
- case 0:
- break;
- case 1:
- // random value so the compiler can't find a relation between s[l] and x
- x = 205;
- continue;
- case 2:
- x = 102;
- continue;
- [...]
- case 254:
- x = 10;
- continue;
- case 255:
- x = 72;
- continue;
- default :
- continue;
- }
- break;
- }
- return l;
- }
Add Comment
Please, Sign In to add comment