diff --git a/basis/cpu/x86/32/32.factor b/basis/cpu/x86/32/32.factor index 0a0ac4a53e..95b65912d1 100755 --- a/basis/cpu/x86/32/32.factor +++ b/basis/cpu/x86/32/32.factor @@ -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 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/basis/cpu/x86/features/authors.txt @@ -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 index 0000000000..69847cacfa --- /dev/null +++ b/basis/cpu/x86/features/features-tests.factor @@ -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 index 0000000000..bc4818d6af --- /dev/null +++ b/basis/cpu/x86/features/features.factor @@ -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 + + + +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 diff --git a/vm/cpu-x86.32.S b/vm/cpu-x86.32.S index afda9d31cd..a879712190 100755 --- a/vm/cpu-x86.32.S +++ b/vm/cpu-x86.32.S @@ -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)): @@ -69,4 +73,5 @@ DEF(void,primitive_inline_cache_miss_tail,(void)): #ifdef WINDOWS .section .drectve .ascii " -export:check_sse2" + .ascii " -export:read_timestamp_counter" #endif diff --git a/vm/cpu-x86.64.S b/vm/cpu-x86.64.S index 8cf7423239..5cc3c98f33 100644 --- a/vm/cpu-x86.64.S +++ b/vm/cpu-x86.64.S @@ -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)):