| 1 | #include <iostream>
|
|---|
| 2 |
|
|---|
| 3 | typedef unsigned uint32;
|
|---|
| 4 | typedef long long unsigned uint64;
|
|---|
| 5 |
|
|---|
| 6 | static uint64 rdtsc(void) {
|
|---|
| 7 | uint32 low, high;
|
|---|
| 8 |
|
|---|
| 9 | __asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
|
|---|
| 10 | return low | (uint64(high) << 32);
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | int main(int, char *[]) {
|
|---|
| 14 | uint64 previous = 0, current, initial = rdtsc();
|
|---|
| 15 | for (unsigned i = 0; i < 100 * 1000 * 1000; ++i) {
|
|---|
| 16 | current = rdtsc();
|
|---|
| 17 | if (current < previous) {
|
|---|
| 18 | std::cout << "After " << i << " iterations:\n"
|
|---|
| 19 | "Current: " << current << " (" << std::hex << current << std::dec << ")\n"
|
|---|
| 20 | "Previous: " << previous << " (" << std::hex << previous << std::dec << ")\n";
|
|---|
| 21 | return 1;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | previous = current;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | std::cout << "OK\nOn the final iteration:\n"
|
|---|
| 28 | "Initial: " << initial << " (" << std::hex << initial << std::dec << ")\n"
|
|---|
| 29 | "Current: " << current << " (" << std::hex << current << std::dec << ")\n";
|
|---|
| 30 | return 0;
|
|---|
| 31 | }
|
|---|