]> gitweb.factorcode.org Git - factor.git/commitdiff
cpu.x86.features: add RDTSC support. This is a new vocabulary with words: sse2? instr...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 31 May 2009 20:02:14 +0000 (15:02 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 31 May 2009 20:02:14 +0000 (15:02 -0500)
basis/cpu/x86/32/32.factor
basis/cpu/x86/features/authors.txt [new file with mode: 0644]
basis/cpu/x86/features/features-tests.factor [new file with mode: 0644]
basis/cpu/x86/features/features.factor [new file with mode: 0644]
vm/cpu-x86.32.S
vm/cpu-x86.64.S

index 0a0ac4a53e727e570093db26083375cb7b217ca6..95b65912d14e672add1b7bfa72c63481670f2d7b 100755 (executable)
@@ -305,10 +305,7 @@ os windows? [
     4 "double" c-type (>>align)
 ] unless
 
-FUNCTION: bool check_sse2 ( ) ;
-
-: sse2? ( -- ? )
-    check_sse2 ;
+USING: cpu.x86.features cpu.x86.features.private ;
 
 "-no-sse2" (command-line) member? [
     [ { check_sse2 } compile ] with-optimizer
diff --git a/basis/cpu/x86/features/authors.txt b/basis/cpu/x86/features/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/cpu/x86/features/features-tests.factor b/basis/cpu/x86/features/features-tests.factor
new file mode 100644 (file)
index 0000000..69847ca
--- /dev/null
@@ -0,0 +1,7 @@
+IN: cpu.x86.features.tests
+USING: cpu.x86.features tools.test kernel sequences math system ;
+
+cpu x86? [
+    [ t ] [ sse2? { t f } member? ] unit-test
+    [ t ] [ [ 10000 [ ] times ] count-instructions integer? ] unit-test
+] when
\ No newline at end of file
diff --git a/basis/cpu/x86/features/features.factor b/basis/cpu/x86/features/features.factor
new file mode 100644 (file)
index 0000000..bc4818d
--- /dev/null
@@ -0,0 +1,25 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: system kernel math alien.syntax ;
+IN: cpu.x86.features
+
+<PRIVATE
+
+FUNCTION: bool check_sse2 ( ) ;
+
+FUNCTION: longlong read_timestamp_counter ( ) ;
+
+PRIVATE>
+
+HOOK: sse2? cpu ( -- ? )
+
+M: x86.32 sse2? check_sse2 ;
+
+M: x86.64 sse2? t ;
+
+HOOK: instruction-count cpu ( -- n )
+
+M: x86 instruction-count read_timestamp_counter ;
+
+: count-instructions ( quot -- n )
+    instruction-count [ call ] dip instruction-count swap - ; inline
index afda9d31cd959a0e0deffe7228483c12ba579631..1a9fd6165ed7fb668d3cb62d01f57e38a447506d 100755 (executable)
@@ -55,6 +55,10 @@ DEF(bool,check_sse2,(void)):
        mov %edx,%eax
        ret
 
+DEF(long long,read_timestamp_counter,(void)):
+       rdtsc
+       ret
+
 DEF(void,primitive_inline_cache_miss,(void)):
        mov (%esp),%ebx
 DEF(void,primitive_inline_cache_miss_tail,(void)):
index 8cf7423239db62add1d8b3268f9447d7d5f35953..5cc3c98f334dab0bf7990b212174cbc5c3695db3 100644 (file)
@@ -72,6 +72,13 @@ DEF(void,set_callstack,(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, voi
        call *ARG3                         /* call memcpy */
        ret                                /* return _with new stack_ */
 
+DEF(long long,read_timestamp_counter,(void)):
+       mov $0,%rax
+       rdtsc
+       shl $32,%rdx
+       or %rdx,%rax
+       ret
+
 DEF(void,primitive_inline_cache_miss,(void)):
        mov (%rsp),%rbx
 DEF(void,primitive_inline_cache_miss_tail,(void)):