{ "root_post_id": "2060730425929080874", "posts": [ { "post_id": "2060730425929080874", "author": "NOTimothyLottes", "handle": "NOTimothyLottes", "text": "Renovating CPU clock code. I'm assuming x86-64 TSC is always >= 1 GHz so that conversion of clock counter diff to nanoseconds is simply a MUL instruction fetching the RDX high 64-bit result (of the 128-bit computed). But figuring out how to do the inline asm was a pain.", "timestamp": "2026-05-30 14:29:54", "media_urls": [ "https://pbs.twimg.com/media/HJku0L4WkAAZk5a?format=png&name=orig" ], "reply_to_id": null, "quote_of_id": null, "metrics": { "reply_count": 3, "repost_count": 0, "like_count": 40, "view_count": 4744 } }, { "post_id": "2060742129190568413", "author": "NOTimothyLottes", "handle": "NOTimothyLottes", "text": "Looks like NtQuerySystemInformation() with SystemHypervisorSharedPageInformation (aka 0xc5) gives 64-bit scalar for TSC that converts time to units of 10 MHz. So the smart way is to work in units of TSC, then do a subtraction of TSC terms, then MULHI to get {ms, us, or ns} time", "timestamp": "2026-05-30 15:16:24", "media_urls": [], "reply_to_id": "2060730425929080874", "quote_of_id": null, "metrics": { "reply_count": 1, "repost_count": 0, "like_count": 6, "view_count": 1060 } }, { "post_id": "2060752921092833490", "author": "NOTimothyLottes", "handle": "NOTimothyLottes", "text": "https://gist.github.com/pmttavara/6f06fc5c7679c07375483b06bb77430c - A great reference for getting TSC scaling multipliers on Linux and Windows", "timestamp": "2026-05-30 15:59:17", "media_urls": [], "reply_to_id": "2060742129190568413", "quote_of_id": null, "metrics": { "reply_count": 0, "repost_count": 0, "like_count": 11, "view_count": 924 } }, { "post_id": "2060885487858880689", "author": "Robert Clausecker", "handle": "FUZxxl", "text": "@NOTimothyLottes If you do the multiply in uint128_t and then right-shift by 64 places, the compiler should do the right thing.", "timestamp": "2026-05-31 00:46:04", "media_urls": [], "reply_to_id": "2060730425929080874", "quote_of_id": null, "metrics": { "reply_count": 1, "repost_count": 0, "like_count": 2, "view_count": 253 } }, { "post_id": "2060898306851516562", "author": "NOTimothyLottes", "handle": "NOTimothyLottes", "text": "@FUZxxl “Should” is exactly why I prefer the actual instruction instrinsics or just inline asm (which is what I use on C CPU land)", "timestamp": "2026-05-31 01:37:00", "media_urls": [], "reply_to_id": "2060885487858880689", "quote_of_id": null, "metrics": { "reply_count": 1, "repost_count": 0, "like_count": 0, "view_count": 125 } }, { "post_id": "2061000558698197386", "author": "Robert Clausecker", "handle": "FUZxxl", "text": "@NOTimothyLottes Have fun with a solution that the compiler optimises worse and that is not portable.", "timestamp": "2026-05-31 08:23:19", "media_urls": [], "reply_to_id": "2060898306851516562", "quote_of_id": null, "metrics": { "reply_count": 0, "repost_count": 0, "like_count": 0, "view_count": 27 } } ], "source_url": "https://x.com/NOTimothyLottes/status/2060730425929080874" }