{"id":361,"date":"2012-07-17T23:06:08","date_gmt":"2012-07-17T14:06:08","guid":{"rendered":"http:\/\/soundengine.jp\/wordpress\/tips\/?p=361"},"modified":"2014-02-06T23:42:36","modified_gmt":"2014-02-06T14:42:36","slug":"rdtscread-time-stamp-counter%e3%81%ae%e3%82%af%e3%83%a9%e3%82%b9%e5%8c%96","status":"publish","type":"post","link":"https:\/\/soundengine.jp\/wordpress\/tips\/try\/361\/","title":{"rendered":"rdtsc(Read Time Stamp Counter)\u306e\u30af\u30e9\u30b9\u5316"},"content":{"rendered":"<h2 id=\"content_1_0\">rdtsc  <a class=\"anchor_super\" id=\"c8e10314\" href=\"http:\/\/soundengine.jp\/backend\/?services%2Ftips%2F2007-06-07%2F2#c8e10314\" title=\"c8e10314\"> <\/a><\/h2>\n<p>rdtsc\u3068\u306f<strong>Read Time Stamp Counter<\/strong>\u3067\u3042\u308b\u3002\u3053\u308c\u306f\u4f55\u304b\u3068\u3044\u3046\u3068\u3001<a href=\"http:\/\/www.02.246.ne.jp\/%7Etorutk\/cxx\/clock\/cpucounter.html\" rel=\"nofollow\">CPU\u30af\u30ed\u30c3\u30af\u306b\u57fa\u3065\u304f\u76f8\u5bfe\u6642\u523b\u306e\u8a08\u6e2c<\/a>\u306e\u30da\u30fc\u30b8\u3092\u5f15\u7528\u3055\u305b\u3066\u3082\u3089\u3046\u3068<\/p>\n<blockquote>\n<p class=\"quotation\">Intel x86\u7cfb\u306eCPU\uff08AMD\u306eAthlon\u7b49\u3082\u542b\u3080\uff09\u3067\u306f\u3001CPU\u30af\u30ed\u30c3\u30af\u3054\u3068\u306b\u52a0\u7b97\u3055\u308c\u308b64bit\u306e\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u30ab\u30a6\u30f3\u30bf\uff08IA32_TIME_STAMP_COUNTER_MSR\uff1a\u901a\u79f0TSC_MSR)\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<\/blockquote>\n<p>\u3068\u306a\u3063\u3066\u304a\u308a\u3001\u3053\u308c\u3092<strong>\u8aad\u307f\u8fbc\u3080<\/strong>\u30a2\u30bb\u30f3\u30d6\u30e9\u547d\u4ee4\u304crdtsc\u3068\u306e\u3053\u3068\u306e\u3088\u3046\u3060\u3002<!--more-->\u5b9f\u969bVC++\u306a\u3069\u95a2\u6570\u3068\u3057\u3066\u4f7f\u3046\u5834\u5408\u3067\u306f\u3001<\/p>\n<pre>__int64 getRdTsc()\r\n{  \r\n\t_asm\r\n\t{\r\n\t\trdtsc\r\n\t}\r\n};<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u30ab\u30a6\u30f3\u30bf\u3092\u53d6\u308b\u3053\u3068\u304c\u3067\u304d\u308b(<a href=\"http:\/\/soundengine.jp\/wordpress\/tips\/?p=67\">QueryPerformanceCounter<\/a>\u3067\u306e\u6e2c\u5b9a\u306f\u6642\u9593\u306e\u6e2c\u5b9a\u3067\u3042\u3063\u305f\u304c\u3001\u3053\u3061\u3089\u306f\u3082\u308d\u306b<strong>\u6d88\u8cbb\u30af\u30ed\u30c3\u30af\u6570\u3092\u6e2c\u5b9a<\/strong>\u3067\u304d\u308b\u3068\u3044\u3046\u610f\u5473\u3067\u8208\u5473\u6df1\u3044)\u3002<\/p>\n<p>\u3061\u306a\u307f\u306bx64\u306e\u5834\u5408\u3001\u4e0a\u8a18\u30a2\u30bb\u30f3\u30d6\u30e9\u306f\u30a8\u30e9\u30fc\u306b\u306a\u308b\u306e\u3067__rdtsc()\u3068\u3044\u3046\u306e\u3092\u4f7f\u3046\u3002\u307e\u305f\u3001intrin.h\u3068\u3044\u3046\u30d8\u30c3\u30c0\u30fc\u3092\u30a4\u30f3\u30af\u30eb\u30fc\u30c9\u3059\u308b\u3053\u3068\u306732bit\u3067\u308264bit\u3067\u3082__rdtsc()\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n<div class=\"jumpmenu\">\n<\/div>\n<h2 id=\"content_1_1\">\u30af\u30e9\u30b9\u5316  <a class=\"anchor_super\" id=\"v8a3cfcd\" href=\"http:\/\/soundengine.jp\/backend\/?services%2Ftips%2F2007-06-07%2F2#v8a3cfcd\" title=\"v8a3cfcd\"> <\/a><\/h2>\n<p>\u7c21\u5358\u306b\u30af\u30e9\u30b9\u5316\u3057\u3066\u307f\u305f\u3002<\/p>\n<pre>class RdTsc\r\n{\r\nprivate:\r\n\r\n\t__int64 oldRdTsc_;\r\n\t__int64 newRdTsc_;\r\n\r\n\tinline static __int64 getRdTsc()\r\n\t{  \r\n#ifdef _M_IX86\r\n\t\t_asm\r\n\t\t{\r\n\t\t\trdtsc\r\n\t\t}\r\n#endif\r\n#ifdef _M_X64\r\n\t\treturn __rdtsc();\r\n#endif\r\n\t};\r\n\r\npublic:\r\n\r\n\tRdTsc() :\r\n\t\toldRdTsc_( 0 ),\r\n\t\tnewRdTsc_( 0 )\r\n\t{\r\n\t};\r\n\r\n\tinline void update()\r\n\t{\r\n\t\toldRdTsc_ = newRdTsc_;\r\n\t\tnewRdTsc_ = getRdTsc();\r\n\t};\r\n\r\n\tvoid trace()\r\n\t{\r\n\t\tATLTRACE2( _T( \"%I64d\\n\" ), newRdTsc_ - oldRdTsc_ );\r\n\t};\r\n\r\n\tvoid print()\r\n\t{\r\n\t\t_tprintf( _T( \"%I64d\\n\" ), newRdTsc_ - oldRdTsc_ );\r\n\t};\r\n};<\/pre>\n<p>\u30b3\u30fc\u30c9\u304c\u30b7\u30f3\u30bf\u30c3\u30af\u30b9\u7684\u306b\u3042\u3063\u3066\u308b\u304b\u3069\u3046\u304b\u306f\u3055\u3066\u304a\u304d\u3001\u4f7f\u3046\u76f4\u524d\u4f7f\u3046\u76f4\u5f8c\u306bupdate\u3068\u3044\u3046\u611f\u3058\u3060\u3002\u4e00\u5fdcinline\u3068\u3044\u3046\u6307\u5b9a\u306f\u3057\u3066\u3044\u308b\u3082\u306e\u306e\u3001\u30af\u30e9\u30b9\u5316\u306b\u3088\u3063\u3066\u82e5\u5e72<strong>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u60aa\u304f<\/strong>\u306a\u3063\u3066\u3044\u308b\u6c17\u3082\u3059\u308b(\u7121\u99c4\u306a\u6d88\u8cbb\u30af\u30ed\u30c3\u30af\u6570\u304c\u5897\u3048\u3066\u3044\u308b\uff1f)\u3002\u305f\u3060\u3001\u30af\u30e9\u30b9\u5316\u3057\u305f\u307b\u3046\u304c\u4f7f\u3046\u3068\u304d\u306f\u697d\u304b\u306a\u3068\u3044\u3046\u6c17\u3082\u3059\u308b\u306e\u3067\u3001\u305d\u306e\u70b9\u3092\u6b21\u306b\u5b9f\u9a13\u3067\u8abf\u67fb\u3059\u308b\u3002<\/p>\n<div class=\"jumpmenu\">\n<\/div>\n<h3 id=\"content_1_2\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9  <a class=\"anchor_super\" id=\"p430e7df\" href=\"http:\/\/soundengine.jp\/backend\/?services%2Ftips%2F2007-06-07%2F2#p430e7df\" title=\"p430e7df\"> <\/a><\/h3>\n<p>\u30af\u30e9\u30b9\u5316\u306b\u3088\u308b<strong>\u4f59\u8a08\u306a\u30af\u30ed\u30c3\u30af\u6570\u306e\u5897\u52a0<\/strong>\u3092\u898b\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u3001\u30af\u30e9\u30b9\u5316\u3092\u3057\u306a\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u6bd4\u8f03\u3057\u3066\u307f\u305f\u3002\u5b9f\u9a13\u3059\u308b\u30b3\u30fc\u30c9\u306f<strong>\u4f55\u3082\u3057\u306a\u3044\u30b3\u30fc\u30c9\u30921000\u56de\u307e\u308f\u3057\u3066\u305d\u306e\u5e73\u5747<\/strong>\u3092\u53d6\u308b\u3068\u3044\u3063\u305f\u3082\u306e\u3067\u3042\u308b(\u4e00\u9023rdtsc\u30eb\u30fc\u30c1\u30f3\u305d\u308c\u81ea\u4f53\u304c\u6d88\u8cbb\u3059\u308b\u30af\u30ed\u30c3\u30af\u6570\u306e\u6e2c\u5b9a)\u3002\u305d\u306e\u7d50\u679c\u3001<\/p>\n<div class=\"ie5\">\n<table class=\"style_table\" border=\"0\" cellspacing=\"1\">\n<tbody>\n<tr>\n<td class=\"style_td\">\u30a4\u30f3\u30e9\u30a4\u30f3<\/td>\n<td class=\"style_td\">66<\/td>\n<\/tr>\n<tr>\n<td class=\"style_td\">\u30af\u30e9\u30b9<\/td>\n<td class=\"style_td\">66<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u3068\u306e\u3053\u3068\u3067\u3042\u3063\u305f\u3002\u3064\u307e\u308a\u30af\u30e9\u30b9\u5316\u306b\u3088\u308b\u640d\u5931\u306f\u30011000\u56de\u306e\u8a66\u884c\u3067\u306f<strong>\u7279\u306b\u767a\u751f\u3057\u306a\u3044<\/strong>\u3068\u3044\u3046\u7d50\u679c\u306b\u306a\u3063\u305f\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001rdtsc\u306e\u7d50\u679c\u306f\u4e21\u8005\u3068\u3082\u306b\u6700\u521d\u306e\u6570\u56de99\u3068\u3044\u3046\u5024\u3092\u767a\u751f\u3057\u305f\u5f8c72\u304b63\u306e\u5024\u3057\u304b\u5410\u304d\u51fa\u3055\u306a\u3044(9\u306e\u500d\u6570\u306b\u306a\u308b\u306e\u304c\u666e\u901a\u306a\u306e\u3060\u308d\u3046\u304b\u3001\u3001\u3001)\u3068\u3044\u3046\u50be\u5411\u3067\u3042\u3063\u305f\u3002<\/p>\n<p>\u306a\u304a\u3001\u4eca\u56de\u306f\u30ea\u30ea\u30fc\u30b9\u6700\u9069\u5316\u30b3\u30f3\u30d1\u30a4\u30eb\u7248\u3067\u306e\u6bd4\u8f03\u3067\u3042\u308b\u304c\u3001\u30c7\u30d0\u30c3\u30b0\u7248(\u975e\u6700\u9069\u5316)\u6642\u306b\u306f\u30a4\u30f3\u30e9\u30a4\u30f3\u306f\u5909\u308f\u3089\u305a<strong>66<\/strong>\u3060\u3063\u305f\u306e\u306b\u5bfe\u3057\u3001\u30af\u30e9\u30b9\u3067\u306f<strong>238<\/strong>\u3067\u3042\u3063\u305f\u3002\u6700\u9069\u5316\u3059\u308b\u304b\u3069\u3046\u304b\u3067\u3053\u306e\u5909\u306e\u30af\u30ed\u30c3\u30af\u6570\u306f\u5909\u308f\u3063\u3066\u304f\u308b\u3088\u3046\u3060\u3002(\u9006\u306b\u8a00\u3048\u3070\u3001<strong>\u5358\u306a\u308b\u30af\u30e9\u30b9\u5316<\/strong>\u3067\u306e<strong>\u30af\u30ed\u30c3\u30af\u640d\u5931<\/strong>\u306f<strong>\u30ea\u30ea\u30fc\u30b9\u6700\u9069\u5316\u7248<\/strong>\u306b\u304a\u3044\u3066\u306f\u3001\u307b\u3068\u3093\u3069<strong>\u767a\u751f\u3057\u306a\u3044<\/strong>\u3068\u3044\u3046\u3053\u3068\u3002\u306a\u304a\u3001\u4eca\u56de\u306fVisual Studio 2005\u306eVC++8.0\u3067\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u3066\u3044\u308b)<\/p>\n<p>GUI\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u5834\u5408\u306f\u3001\u30a6\u30a4\u30f3\u30c9\u30a6\u306e\u30bf\u30a4\u30c8\u30eb\u90e8\u5206\u306b\u3067\u3082\u51fa\u305b\u3070\u3088\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre>\tvoid update_window_text\r\n\t\t(\r\n\t\tHWND hWnd\r\n\t\t)\r\n\t{\r\n\t\tTCHAR text[ 65 ] = { 0 };\r\n\r\n\t\tif( _i64tot_s( newRdTsc_ - oldRdTsc_, text, 65, 10 ) )\r\n\t\t{\r\n\t\t\treturn;\r\n\t\t}\r\n\t\t\r\n\t\tSetWindowText( hWnd, text );\r\n\t};<\/pre>\n<p>\u30eb\u30fc\u30d7\u306a\u3069\u3067rdtsc\u306e\u5e73\u5747\u5024\u3092\u6e2c\u5b9a\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u306f\u3001<a href=\"http:\/\/soundengine.jp\/wordpress\/tips\/2012\/10\/26\/rdtscread-time-stamp-counter%e3%81%ae%e5%b9%b3%e5%9d%87%e5%80%a4%e6%b8%ac%e5%ae%9a\/\">\u3053\u3061\u3089<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>rdtsc rdtsc\u3068\u306fRead Time Stamp Counter\u3067\u3042\u308b\u3002 &hellip; <a href=\"https:\/\/soundengine.jp\/wordpress\/tips\/try\/361\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-361","post","type-post","status-publish","format-standard","hentry","category-try"],"_links":{"self":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/comments?post=361"}],"version-history":[{"count":5,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/361\/revisions"}],"predecessor-version":[{"id":3306,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/361\/revisions\/3306"}],"wp:attachment":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/media?parent=361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/categories?post=361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/tags?post=361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}