]> gitweb.factorcode.org Git - factor.git/blob - basis/cpu/x86/features/features.factor
change add-init-hook to add-startup-hook, new add-shutdown-hook word
[factor.git] / basis / cpu / x86 / features / features.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: system kernel memoize math math.order math.parser
4 namespaces alien.c-types alien.syntax combinators locals init io
5 compiler compiler.units accessors ;
6 IN: cpu.x86.features
7
8 <PRIVATE
9
10 FUNCTION: int sse_version ( ) ;
11
12 FUNCTION: longlong read_timestamp_counter ( ) ;
13
14 PRIVATE>
15
16 MEMO: sse-version ( -- n )
17     sse_version
18     "sse-version" get string>number [ min ] when* ;
19
20 [ \ sse-version reset-memoized ] "cpu.x86.features" add-startup-hook
21
22 : sse? ( -- ? ) sse-version 10 >= ;
23 : sse2? ( -- ? ) sse-version 20 >= ;
24 : sse3? ( -- ? ) sse-version 30 >= ;
25 : ssse3? ( -- ? ) sse-version 33 >= ;
26 : sse4.1? ( -- ? ) sse-version 41 >= ;
27 : sse4.2? ( -- ? ) sse-version 42 >= ;
28
29 : sse-string ( version -- string )
30     {
31         { 00 [ "no SSE" ] }
32         { 10 [ "SSE1" ] }
33         { 20 [ "SSE2" ] }
34         { 30 [ "SSE3" ] }
35         { 33 [ "SSSE3" ] }
36         { 41 [ "SSE4.1" ] }
37         { 42 [ "SSE4.2" ] }
38     } case ;
39
40 HOOK: instruction-count cpu ( -- n )
41
42 M: x86 instruction-count read_timestamp_counter ;
43
44 : count-instructions ( quot -- n )
45     instruction-count [ call ] dip instruction-count swap - ; inline