builtin_31_readcyclecounter.c (578B)
1 /* __builtin_readcyclecounter(): reads the target cycle/timestamp counter as an 2 * unsigned long long (x86 RDTSC, aarch64 CNTVCT_EL0, riscv64 RDCYCLE). A free- 3 * running counter is monotonic, so re-reading it eventually yields a larger 4 * value. Spin-read until it advances, bounded so a broken/constant read fails 5 * the oracle instead of looping forever. */ 6 typedef unsigned long long u64; 7 8 int test_main(void) { 9 u64 a = __builtin_readcyclecounter(); 10 u64 b = a; 11 for (int i = 0; i < 100000000 && b == a; i++) b = __builtin_readcyclecounter(); 12 return b > a ? 42 : 1; 13 }