Created
November 8, 2015 09:03
-
-
Save HugoGuiroux/4f32fc59320c78dcea7e to your computer and use it in GitHub Desktop.
Code generating an optimization bug with clang
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 <iostream> | |
| #include <cstring> | |
| #define LOOP_COUNT 1000000000 | |
| unsigned long long rdtscl(void) | |
| { | |
| unsigned int lo, hi; | |
| __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); | |
| return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); | |
| } | |
| int main() | |
| { | |
| unsigned long long before = rdtscl(); | |
| size_t ret; | |
| for (int i = 0; i < LOOP_COUNT; i++) | |
| ret = strlen("abcd"); | |
| unsigned long long after = rdtscl(); | |
| std::cout << "Strlen " << (after - before) << " ret=" << ret << std::endl; | |
| before = rdtscl(); | |
| for (int i = 0; i < LOOP_COUNT; i++) | |
| ret = sizeof("abcd"); | |
| after = rdtscl(); | |
| std::cout << "Sizeof " << (after - before) << " ret=" << ret << std::endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment