Day 113: GCC & Cycle Count

GCC comes with a __rdtsc() intrinsic defined in x86intrin.h, it would be nice if there was support for BEGIN_TIMED_BLOCK on that platform too :)

While we are at it, shouldn't the call to __rdtsc be defined in handmade_intrinsics.h?

/Kim
Where does llvm or clang define __rdtsc()? I've been searching for hours and still have no clue how to access the TSC from Swift on OS X. According to Apple mach_absolute_time() should return absolute time (cycles?) but, alas, it returns nanoseconds.
clang also has __rdtsc() available from x86intrin.h header.

Actual clang intrinsic is __builtin_readcyclecounter (and llvm.readcyclecounter for llvm), but clang provides __rdtsc for compatibility reasons.

For Swift I think you can simply create C function that would call __rdtsc() and return result value. Then call this function from Swift.

Edited by Mārtiņš Možeiko on
Thank you. I managed to get it working, it was due to an issue with the bridging header between objc and swift.