intrinsics.c (720B)
1 #define FORCE_INLINE inline __attribute__((always_inline)) 2 3 static FORCE_INLINE u32 4 clz_u32(u32 a) 5 { 6 u32 result = 32; 7 if (a) result = __builtin_clz(a); 8 return result; 9 } 10 11 static FORCE_INLINE u32 12 ctz_u32(u32 a) 13 { 14 u32 result = 32; 15 if (a) result = __builtin_ctz(a); 16 return result; 17 } 18 19 #ifdef __ARM_ARCH_ISA_A64 20 /* TODO? debuggers just loop here forever and need a manual PC increment (jump +1 in gdb) */ 21 #define debugbreak() asm volatile ("brk 0xf000") 22 23 static FORCE_INLINE u64 24 rdtsc(void) 25 { 26 register u64 cntvct asm("x0"); 27 asm volatile ("mrs x0, cntvct_el0" : "=x"(cntvct)); 28 return cntvct; 29 } 30 #elif __x86_64__ 31 #include <immintrin.h> 32 33 #define debugbreak() asm volatile ("int3; nop") 34 35 #define rdtsc() __rdtsc() 36 37 #endif