aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/asmlib/rdtsc64.asm
diff options
context:
space:
mode:
authorpnv1 <pnv@ydb.tech>2023-04-27 19:15:07 +0300
committerpnv1 <pnv@ydb.tech>2023-04-27 19:15:07 +0300
commita66c59109292f9e0fb44ede41adfdebe569e4df3 (patch)
tree906b3d10274afd16e8e70c61ff416bff9075422e /contrib/libs/asmlib/rdtsc64.asm
parent9ca91b40d6f45546e20a646d15590c0cc6cc9778 (diff)
downloadydb-a66c59109292f9e0fb44ede41adfdebe569e4df3.tar.gz
Switch to old asmlib to be able to build ydb cli without sse4
Diffstat (limited to 'contrib/libs/asmlib/rdtsc64.asm')
-rw-r--r--contrib/libs/asmlib/rdtsc64.asm53
1 files changed, 53 insertions, 0 deletions
diff --git a/contrib/libs/asmlib/rdtsc64.asm b/contrib/libs/asmlib/rdtsc64.asm
new file mode 100644
index 0000000000..42a0e23203
--- /dev/null
+++ b/contrib/libs/asmlib/rdtsc64.asm
@@ -0,0 +1,53 @@
+%include "defs.asm"
+
+; RDTSC64.ASM
+;
+; Author: Agner Fog
+; Date created: 2003
+; Last modified: 2008-10-16
+; Description:
+;
+; Copyright (c) 2009 GNU General Public License www.gnu.org/licenses
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+default rel
+
+global ReadTSC: function
+
+SECTION .text align=16
+
+; ********** ReadTSC function **********
+; C++ prototype:
+; extern "C" __int64 ReadTSC (void);
+
+; This function returns the value of the time stamp counter, which counts
+; clock cycles. To count how many clock cycles a piece of code takes, call
+; Rdtsc before and after the code to measure and calculate the difference.
+
+; The number of clock cycles taken by the ReadTSC function itself is approximately:
+; Core 2: 730
+; Pentium 4: 700
+; Pentium II and Pentium III: 225
+; AMD Athlon 64, Opteron: 126
+; Does not work on 80386 and 80486.
+
+; Note that clock counts may not be fully reproducible on Intel Core and
+; Core 2 processors because the clock frequency can change. More reliable
+; instruction timings are obtained with the performance monitor counter
+; for "core clock cycles". This requires a kernel mode driver as the one
+; included with www.agner.org/optimize/testp.zip.
+
+ReadTSC:
+ push rbx ; ebx is modified by cpuid
+ sub eax, eax ; 0
+ cpuid ; serialize
+ rdtsc ; read time stamp counter into edx:eax
+ shl rdx, 32
+ or rax, rdx ; combine into 64 bit register
+ push rax
+ sub eax, eax
+ cpuid ; serialize
+ pop rax ; return value
+ pop rbx
+ ret
+;ReadTSC ENDP