Handmade Hero»Forums»Code
Kim
Kim Jørgensen
64 posts
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
55 posts
Day 113: GCC & Cycle Count
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.
Mārtiņš Možeiko
2562 posts / 2 projects
Day 113: GCC & Cycle Count
Edited by Mārtiņš Možeiko on
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.
55 posts
Day 113: GCC & Cycle Count
Thank you. I managed to get it working, it was due to an issue with the bridging header between objc and swift.